Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Created May 30, 2011 03:00
Show Gist options
  • Save unscriptable/998397 to your computer and use it in GitHub Desktop.
Save unscriptable/998397 to your computer and use it in GitHub Desktop.
Possible syntaxes for wire.js deferrals
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'
}
}
});
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'
}
});
@unscriptable
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment