Tendril
Fancy Dependecy Injection
Methods:
/* * @param {Function|Array<paramNames..,fn>} - param names are service names */tendril
/* * @typedef {Object} IncludeConfig * * @property {Boolean} [inject=true] - should attempt to inject function * @property {Boolean} [lazy=true] - only load if required by a sub-service */ /* * @param {String|Object} name - if object, keys are names and values services * @param {Anything|Function} constructor - the service, or resolved * @param {IncludeConfig} config */tendril
/* * @typedef {Object} Crawl * * @property {String} path - absolute path of directory to crawl * @property {String} [postfix=''] - String to append to filenames as services * @property {Boolean} [lazy=true] - only load if required by another service */ /* * crawl a directory * * @param {Array<Crawl>|Crawl} crawls */tendril
/* * @param name - event name (e.g. serviceLoad) * @param fn - callback fn -> { name: 'serviceName', instance: {Service} } */tendril
/* * Inspect the dependencies * @param fn - callback fn -> {x: ['y', 'z'], y: ['z'], z: []} * where x depends on y and z, y depends on z, and z depends * on nothing. */tendril
Examples:
Setup
var Tendril = ; ;
// services/abc.jsmodule { return hello: 'world' }
Include/Override
;
Named parameter injection
;
Nested Injection
// The current tendril instance can be injected, just like any other service ;
Inject object
;
Include function without injecting it
// third optional param to include()
Include function non-lazily
Error handling for missing dependencies
;
Events
Submodules - TODO
All subfolders in a module (with an index.js) are considered submodules and will attempt to be loaded
Overriding submodules - TODO