Skip to content
Barış Güler edited this page Aug 16, 2015 · 3 revisions

This wiki contains additional development information and links to know about everything for Booklet.

Booklet can be used to manage the views and its context by creating modules and attaching them to specific parts of the views like header, footer or content and etc. Creating configuration variables, using publish / subscribe for custom events and creating services are the basic usage patterns to manage your application.

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

You can do with Booklet:

  • Creating views attached with the application instance
  • Initializing modules for the parts whatever you expect
  • Setting configuration variables on Booklet and Page instance layer
  • Invoking services that you often use
  • Publishing custom events for which view subscribed

###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 View 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..."}
Clone this wiki locally