A simple module initializer by creating view models. The main attitude of this module binding system is inspired by Nicholas Zakas's presentation here : http://www.slideshare.net/nzakas/scalable-javascript-application-architecture
###Usage
####Create a Booklet instance
var app = new Booklet('app', {someOption : 'some options'});
####Generate a Page instance by invoking createView method with a page name
var page = app.createView('page');
####Bind a module into the instance with an init method calling the inner functions
page.register('testModule', {
init : function () {
this.someMethod();
},
someMethod : function () {
console.log('someMethod initialized');
}
});
####Make the new module begin to work specifically mentioning its name
page.start('testModule');
####Or make the all modules begin to work
page.startAll();
###Creating Services for Booklet Instance
####Create a Booklet Service
app.createService('testService', function () {
return 'testService invoked'
});
####Invoke the Current Booklet Service
page.register('menu', {
init : function () {
console.log(this.getServiceWorked()); //logs "testService invoked"
},
getServiceWorked : function () {
var testService = app.getService('testService');
return testService();
}
});
###Creating Services for Page Instance
####Create a Page Service
page.createService('testService', function () {
return 'testService invoked'
});
####Invoke the Current Page Service
page.register('menu', {
init : function () {
console.log(this.getServiceWorked()); //logs "testService invoked"
},
getServiceWorked : function () {
var testService = page.getService('testService');
return testService();
}
});
###Creating Configuration Options for Booklet instance
####Create a Booklet instance configuration option
var app = new Booklet('app', {
appOption : 1
});
####Create a Page instance configuration option
var page = app.createView('page', {
pageOption : 2
})
####Create a Module Using Configuration Options
page.register('testModule', {
init : function () {
this.logOptions();
},
logOptions : function () {
console.dir(app.defaults);
console.dir(page.defaults);
}
});
###Creating Custom Events
####Subscribe for an Event with Page Instance
page.subscribe('testEvent', function (data) {
console.log(data);
});
####Publish an Event with Booklet Instance
app.publish('testEvent', {
testData : 'test data...'
}); // logs Object {testData: "test data..."}