load-entry
Package to offload the execution of a function, object or module.
By default, if there's a document (i.e. on browsers), it will wait for the 'DOMContentLoaded' event and then execute the given object. If not it will execute the object immediately.
Why I use it on the browser
To create modules that are testable in any scenario.
Why I use it on a NodeJs app
To facilitate module running and unit testing.
Basic Usage (browser)
// index.js -> app entry file;; const myEntryPoint = { App; // -> executed only after the document triggers 'ready'}; ;
More examples
Also runs these examples seamlessly:
// Example 1: object with init functionconst myEntryPoint = { App; };; // Example 2: object with custom init functionconst myEntryPoint = { App; };;// OR; // Example 3: module with default as export// entry.js { App;};// index.js;; // Example 4: module with named exports// entry.jsconst myEntryPoint = { App;};const mySecondEntryPoint = { console;};// index.js;; // Example 5: run after a custom event is triggeredconst myEntryPoint = { App;};; // Example 6: run immediately (in a browser environment)const myEntryPoint = { App;};;