Giter Club home page Giter Club logo

booklet's Introduction

booklet

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..."}

booklet's People

Contributors

hwclass avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.