Blame view
node_modules/loopback-datasource-juggler/test/helpers/hook-monitor.js
1012 Bytes
f7563de62
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
// Copyright IBM Corp. 2016. All Rights Reserved. // Node module: loopback-datasource-juggler // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT 'use strict'; module.exports = HookMonitor; function HookMonitor(opts) { if (!(this instanceof HookMonitor)) { return new HookMonitor(); } this.options = opts || {}; this.names = []; }; HookMonitor.prototype.install = function(ObservedModel, hookNames) { var monitor = this; this.names = []; ObservedModel._notify = ObservedModel.notifyObserversOf; ObservedModel.notifyObserversOf = function(operation, context, callback) { if (!Array.isArray(hookNames) || hookNames.indexOf(operation) !== -1) { var item = monitor.options.includeModelName ? ObservedModel.modelName + ':' + operation : operation; monitor.names.push(item); } this._notify.apply(this, arguments); }; }; HookMonitor.prototype.resetNames = function() { this.names = []; }; |