Now passing getInst() directly into MethodwrapperFactory factory function, like good 'ol times
- I seem to have forgotten that this is necessary due to the static implementationclosure/master
parent
ba251d5a21
commit
ce1370e025
|
@ -33,15 +33,14 @@
|
||||||
* perform the actual
|
* perform the actual
|
||||||
* wrapping
|
* wrapping
|
||||||
*/
|
*/
|
||||||
module.exports = exports = function MethodWrapperFactory( getInst, factory )
|
module.exports = exports = function MethodWrapperFactory( factory )
|
||||||
{
|
{
|
||||||
// permit omission of the 'new' keyword for instantiation
|
// permit omission of the 'new' keyword for instantiation
|
||||||
if ( !( this instanceof exports ) )
|
if ( !( this instanceof exports ) )
|
||||||
{
|
{
|
||||||
return new exports( getInst, factory );
|
return new exports( factory );
|
||||||
}
|
}
|
||||||
|
|
||||||
this._getInst = getInst;
|
|
||||||
this._factory = factory;
|
this._factory = factory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,8 +55,8 @@ module.exports = exports = function MethodWrapperFactory( getInst, factory )
|
||||||
* @param {function()} super_method super method, if overriding
|
* @param {function()} super_method super method, if overriding
|
||||||
* @param {number} cid class id that method is associated with
|
* @param {number} cid class id that method is associated with
|
||||||
*/
|
*/
|
||||||
exports.prototype.wrapMethod = function( method, super_method, cid )
|
exports.prototype.wrapMethod = function( method, super_method, cid, getInst )
|
||||||
{
|
{
|
||||||
return this._factory( method, super_method, cid, this._getInst );
|
return this._factory( method, super_method, cid, getInst );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -64,11 +64,11 @@ var common = require( './common' ),
|
||||||
method = function() {},
|
method = function() {},
|
||||||
super_method = function() {},
|
super_method = function() {},
|
||||||
cid = 55,
|
cid = 55,
|
||||||
|
getInst = function() {},
|
||||||
retval = 'foobar';
|
retval = 'foobar';
|
||||||
|
|
||||||
var result = Sut(
|
var result = Sut(
|
||||||
function() {},
|
function( given_method, given_super, given_cid, givenGetInst )
|
||||||
function( given_method, given_super, given_cid )
|
|
||||||
{
|
{
|
||||||
called = true;
|
called = true;
|
||||||
|
|
||||||
|
@ -84,9 +84,13 @@ var common = require( './common' ),
|
||||||
"Factory method should be provided with cid"
|
"Factory method should be provided with cid"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.equal( givenGetInst, getInst,
|
||||||
|
"Factory method should be provided with proper inst function"
|
||||||
|
);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
).wrapMethod( method, super_method, cid );
|
).wrapMethod( method, super_method, cid, getInst );
|
||||||
|
|
||||||
// we'll include this in addition to the following assertion (which is
|
// we'll include this in addition to the following assertion (which is
|
||||||
// redundant) to make debugging more clear
|
// redundant) to make debugging more clear
|
||||||
|
@ -99,29 +103,3 @@ var common = require( './common' ),
|
||||||
);
|
);
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The instance function, which should be made available to the factory
|
|
||||||
* function, is used to retrieve the visibility object associated with the
|
|
||||||
* instance that the context is associated with.
|
|
||||||
*/
|
|
||||||
( function testProvidedFactoryFunctionIsCalledWithInstanceFunction()
|
|
||||||
{
|
|
||||||
var called = false;
|
|
||||||
|
|
||||||
Sut(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
called = true;
|
|
||||||
},
|
|
||||||
function( _, __, ___, inst )
|
|
||||||
{
|
|
||||||
inst();
|
|
||||||
}
|
|
||||||
).wrapMethod( null, null, 0 );
|
|
||||||
|
|
||||||
assert.equal( called, true,
|
|
||||||
"Instance callback should be provided to factory function"
|
|
||||||
);
|
|
||||||
} )();
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue