Fixed hookImmutable()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 78ee497 · Browse files · 2 files·+21 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+21 added−10 removed
- tests:+13 added−5 removed
- other:+8 added−5 removed
Provenance
- Commit
2035c31- Tree
0d35918- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
78ee497
2 files changed+21 added−10 removed
modified:lib/express.core.js+8 added-5 removed
63 unmodified lines64 65 hook : function(name, args) {66 var results = []67 for (i = 0, len = this.modules.length; i < len; ++i)68+ for (var key in this.modules[i][name])68- if (typeof this.modules[i][name] == 'function')69- results.push(this.modules[i][name].apply(this.modules[i], this.argsArray(arguments, 1)))69+ if (this.modules[i][name].hasOwnProperty(key))70+ results.push(this.modules[i][name][key].apply(this.modules[i], this.argsArray(arguments, 1)))71 return results72 },73 74 /**75 * Invoke hook _name_ with _immutable_ and _args_, returning76 * the _immutable_ variable once modified by each hook implementation.77 * When implementing these hooks, the function must return a value.78 *79+ * @param {string} name80 * @param {mixed} immutable81 * @param {...} args82 * @return {mixed}83 * @api public84 */85 84- hookImmutable : function(immutable, args) {86+ hookImmutable : function(name, immutable, args) {87 for (i = 0, len = this.modules.length; i < len; ++i)86- if (typeof this.modules[i][name] == 'function')87- immutable = this.modules[i][name].apply(this.modules[i], this.argsArray(arguments, 1))88+ for (var key in this.modules[i][name])89+ if (this.modules[i][name].hasOwnProperty(key))90+ immutable = this.modules[i][name][key].call(this.modules[i], immutable)91 return immutable92 },93 94 /**506 unmodified linesmodified:spec/spec.modules.js+13 added-5 removed
14 unmodified lines151617181919202021222324232425262728293031323334353631 unmodified lines6869707164727374757614 unmodified lines return 'bar' } }, onFoo : { onFoo : function(one, two) { return 'bar ' + one + ' ' + two 'return bar' : function(one, two) { return 'bar ' + one + ' ' + two } }, onFooImmutable : function(immutable, arg) { return 'just ' + immutable + ' ' + arg onFooImmutable : { 'test one' : function(immutable, arg) { return 'one ' + immutable }, 'test two' : function(immutable, arg) { return immutable + ' two' } }})
describe 'Express'31 unmodified lines end describe 'hookImmutable' it 'should call hook implementations sequencially passing the first argument passed' Express.hook('onFooImmutable', 'a', 'test').should.eql ['just a test'] Express.hookImmutable('onFooImmutable', 'test').should.eql 'one test two' end end endend