Sibling traits will each have __mixin called distinctly
parent
2204ff6d28
commit
f3cb815baa
17
lib/Trait.js
17
lib/Trait.js
|
@ -617,6 +617,14 @@ function mixMethods( src, dest, vis, iname )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: generalize
|
||||||
|
// __mixin is exclusive to the trait (private-ish, but can be
|
||||||
|
// invoked publically internally)
|
||||||
|
if ( f === '__mixin' )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this is a kluge; we'll use proper reflection eventually,
|
// TODO: this is a kluge; we'll use proper reflection eventually,
|
||||||
// but for now, this is how we determine if this is an actual method
|
// but for now, this is how we determine if this is an actual method
|
||||||
// vs. something that just happens to be on the visibility object
|
// vs. something that just happens to be on the visibility object
|
||||||
|
@ -778,10 +786,13 @@ function tctor( tc, base, privsym )
|
||||||
// visibility object to gain access to its protected members...quite
|
// visibility object to gain access to its protected members...quite
|
||||||
// the intimate relationship
|
// the intimate relationship
|
||||||
this[ f ] = C( base, this[ privsym ].vis )[ privsym ].vis;
|
this[ f ] = C( base, this[ privsym ].vis )[ privsym ].vis;
|
||||||
}
|
|
||||||
|
|
||||||
// this has been previously validated to ensure that it is a function
|
// this has been previously validated to ensure that it is a
|
||||||
this.__mixin && this.__mixin.apply( this, T.___$$mixinargs );
|
// function
|
||||||
|
this[ f ].__mixin && this[ f ].__mixin.apply(
|
||||||
|
this[ f ], T.___$$mixinargs
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// if we are a subtype, be sure to initialize our parent's traits
|
// if we are a subtype, be sure to initialize our parent's traits
|
||||||
this.__super && this.__super( privsym );
|
this.__super && this.__super( privsym );
|
||||||
|
|
|
@ -259,5 +259,31 @@ require( 'common' ).testCase(
|
||||||
|
|
||||||
this.assertEqual( n, 3 );
|
this.assertEqual( n, 3 );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sibling traits are an interesting case---rather than stacking, they
|
||||||
|
* are mixed in alongside each other, meaning that there may be
|
||||||
|
* multiple traits that define __mixin. Ordinarily, this is a problem;
|
||||||
|
* however, __mixin shall be treated as if it were private and shall be
|
||||||
|
* invoked once per trait, giving each a chance to initialize.
|
||||||
|
*
|
||||||
|
* Furthermore, each should retain access to their own configuration.
|
||||||
|
*/
|
||||||
|
'Invokes __mixin of each sibling mixin': function()
|
||||||
|
{
|
||||||
|
var args = [],
|
||||||
|
vals = [ {}, [] ],
|
||||||
|
c = function() { args.push( arguments ) };
|
||||||
|
|
||||||
|
var Ta = this.createParamTrait( c ),
|
||||||
|
Tb = this.createParamTrait( c );
|
||||||
|
|
||||||
|
this.Class( {} ).use( Ta( vals[0] ), Tb( vals[1] ) )();
|
||||||
|
|
||||||
|
this.assertEqual( args.length, 2 );
|
||||||
|
this.assertStrictEqual( args[0][0], vals[0] );
|
||||||
|
this.assertStrictEqual( args[1][0], vals[1] );
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue