linc
js execution controller for the browser or node.js
Installation
npm install linc
or include linc.js
on your page
API
Linc.add( name, [ options ], fn )
Adds a widget with string name
, optional options object
, and run function fn
. Widgets can be scoped by adding period separated namespaces in the name. Returns the module.
validation.signup
Add the validation widget to the signup namespacevalidation.signup.signin
Add the validation widget to both signup and signin namespaces
Linc.run( [ name, ] [ options ])
Executes all functions that are unscoped, and takes an optional options object to call specific namespaces, pass in a context, or execute all stored functions (options detailed below).
Linc.get( name )
Retrieves a module with name
-- can be a name along with a namespace, like widgetName.scope
, which will return the widgetName
module in the scope
namespace.
Linc.setDefaults([ options ])
set defaults such as default context
or namespace
that should be used when running or adding modules.
Widget Options
once
This widget is only called once during its life.
Run Options
context
Each widget's associated function is called withthis
ascontext
. Defaults toLinc
in node andwindow
on the browser.all
Calls all widgets, namespaced and unscoped.namespaceOnly
Calls only the namespace defineddata
Data to be sent as arguments in function calls
Examples
// Set the default context to be a header div in the browser Linc; // Adds a validation widget Linc; // Adds a selection toggle widget that can only be called once. Linc; // Adds the register widget to the account namespace Linc; // Runs all unscoped widgets -- just 'validation' and 'selectParent' in // this case, with default scope of the #content element Linc; // Runs all unscoped and widgets in the namespace 'account' -- // both 'register' and 'validation' functions are executed, since // 'selectParent' is only called once, with 'document' as context Linc; // You can also pass data to all modules called Linc; $;
Development
Uses jasmine-node for running specs, and coffeescript for source -- run make
in project root to compile and run specs.