Created
May 30, 2011 03:00
-
-
Save unscriptable/998397 to your computer and use it in GitHub Desktop.
Possible syntaxes for wire.js deferrals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wire({ | |
// this is a normal module | |
// it is loaded, created, and initialized asap | |
staticModule: { | |
create: { | |
module: 'my/static/module', | |
args: {} | |
}, | |
init: 'startMe' | |
}, | |
// load the entire module when it's needed | |
dynamicModule: { | |
defer: { | |
create: { | |
module: 'my/dynamic/module', | |
args: {} | |
}, | |
init: 'startMe' | |
} | |
}, | |
// init the module when it's needed | |
dynamicModule2: { | |
create: { | |
module: 'my/dynamic/module2', | |
args: {} | |
}, | |
defer: { | |
init: 'startMe' | |
} | |
}, | |
// only load the module, but don't create or init until needed | |
dynamicModule3: { | |
module: 'my/dynamic/module3', | |
defer: { | |
create: { | |
args: {} | |
}, | |
init: 'startMe' | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wire({ | |
// load the entire module when it's needed | |
dynamicModule: { | |
defer: 'load', | |
create: { | |
module: 'my/dynamic/module', | |
args: {} | |
}, | |
init: 'startMe' | |
}, | |
// init the module when it's needed | |
dynamicModule2: { | |
defer: 'init', | |
create: { | |
args: {} | |
init: 'startMe' | |
} | |
}, | |
// only load the module, but don't create or init until needed | |
dynamicModule3: { | |
defer: 'create' | |
create: { | |
module: 'my/dynamic/module2', | |
args: {} | |
}, | |
init: 'startMe' | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am not sure the first syntax is bullet-proof. For instance, what if somebody were to defer the create, but not the init? However, I like that it feels like async programming.
The second syntax seems like it may be easier to implement.
I just realized that cram will have to understand the defer syntax, too.