geb (global-event-bus)
geb is an abnormal and great EventBus for Javascript Web/Node.
Features
- Instantiate Object on call for better start-up-time
- Better overview
Short simple introduction
- Definition
var {console;};eb;
- Run from everywhere
ebtestCasefirstCase;// will print: 'hello there'
Install
npm install geb --save
Include
Node
var geb = ; ; //add eb to Global and return it //var eb = new geb(false); //won't add eb to global, maybe for security reasons.
Web
Use the Browserify boundle.js
in folder node_modules/geb/lib/boundle.js
Now eb
is globally (on window) available.
Examples
eb()
Info
After implement, you could call it with eb
.
You could store your events on separate domains. Every domain contains the eb()
function.
The function only knows his own domain and his followed domains.
The eb()
function creates-/removes- Domains, add-/remove (multiple) event definitions and add thisArg
to the domains and/or event(s).
eb()
will operate on and return his own current domain.
Function definition
- parameter {Object}: adds Option to Domain and functions
- parameter {String}: define the Domain
- parameter {Function}: adds function to Domain.methode
- return {Object}: current Domain
Without domain (String): add to current domain
Without function: add domain and/or option
Only Object: adds option to current domain
You could add more then one function to damain.
- The
thisArg
option on create a function will be used on call, not the domainthisArg
. - The domain
thisArg
will only be used, if there is nothisArg
on function create.
Function examples
// eb.debug=true; // define an Object var o = { console; } //set testCaseEB to subdomain and add function test with thisArg to subdomain var testCaseEB = eb; //reg. domain testCaseEB; testCaseEBthisArg = o; //OR same in one Statement: var testCaseEB = eb; //call it with: testCaseEB //OR globally ebtestCasefirstCase //Add option permanent to domain testCase und above ebtestCasefirstCase //Removes all sub function from domain eb; //Remove testCase Domain eb;
IF
var obj1 = id: 1 { console; } var obj2 = id: 2 { console; } eb; eb; // will only log 'Hello from obj1', the if object checks the thisArg object eb
Instantiate Object on call
Instantiate Objects only when you need them. For better startup-time.
test-object.coffee
module.exports = : : consolelog " " :
example1.js
normal (lazy startup-time)
var TestObject = var instance = 'hello'eb;ebtest; //print: hello world
example1.js
instance on call (better startup-time)
eb;ebtest; //print: hello world// will instantiate Test (with readFile...) after call// and execute call