viewloader
A teensy package that simplifies the process of binding DOM nodes to JavaScript functions. It does this by creating a convention for mapping between the DOM and your JavaScript and ensures that only the functions for the components in the DOM are executed.
Installation
% npm install --save viewloader
Development
To build a standalone version:
% npm run build
Example
// bar-chart.js { console; //=> div {data: [1,2,3]} return { ... } { ... } };
// index.js ;;; const views = myBarChart myLineChart; // Create the instanceconst manager = ;// Call the view functionsmanager;// Call the `reset` methods of each view functionmanager;// Call the `destroy` methods of each view functionmanager;
API
viewloader(views, scope, includeScope);
- views — An
object
of view functions mapped todata-view-[name]
attributes. (Required) - scope — An
element
ornodelist
to scope the view loader to. (Optional. Defaults todocument
) - includeScope — A
boolean
to indicate if the scoped element should be included in the scoped views. (Optional: Defaults tofalse
)
Promises
Viewloader supports view functions that return a Promise
, automatically setting the resolved return value from any promises once that value is resolved. This means you can call viewloader synchronously with underlying code in your views that is asynchronous:
; const views = { return import"./async-import" ; }