File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ export class Context
2
+ {
3
+ //For plain JS version
4
+ //Returns a constructor function to instantiate a new context.
5
+ //In the future it may also inherit some utility methods that are common to all contexts.
6
+ //
7
+ //It will check whether the passed callback function has a bindRoles() method, and if so,
8
+ //any constructor arguments will be passed to bindRoles(). If the passed callback does not
9
+ //have a bindRoles() method, then the roles should be bound at the top of the callback function.
10
+ //
11
+ //bindRoles() is useful for the case where you want to be able to re-bind the roles on an existing
12
+ //context object.
13
+ //
14
+ static extend ( callback ) : any {
15
+ return function ( ...args : any [ ] ) {
16
+ //We always pass the parameters to the passed function (callback) because
17
+ //we can't check whether or not a bindRoles() method exists until after we've
18
+ //instantiated the context object.
19
+ //The ContextConstructor function is needed so that we can pass constructor arguments dynamically
20
+ //(see http://stackoverflow.com/a/13931627/560114)
21
+ var ContextConstructor : any = function ( ) {
22
+ return callback . apply ( this , args ) ;
23
+ }
24
+ ContextConstructor . prototype = callback . prototype ;
25
+
26
+ var context = new ContextConstructor ( ) ;
27
+ context . constructor = callback ;
28
+
29
+ if ( context . bindRoles ) context . bindRoles . apply ( context , arguments ) ;
30
+ return context ;
31
+ }
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments