41
Introducing Applitude Simple Module Management

Introducing Applitude: Simple Module Management

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Introducing Applitude: Simple Module Management

Introducing ApplitudeSimple Module Management

Page 2: Introducing Applitude: Simple Module Management

Eric ElliottAuthor

"Programming JavaScript Applications"

Page 3: Introducing Applitude: Simple Module Management

Modularity = Simplicity

Page 4: Introducing Applitude: Simple Module Management

Avoid Complexity(don't build a large app!)

Page 5: Introducing Applitude: Simple Module Management

Build Lots of Small Apps!(modules)

Page 6: Introducing Applitude: Simple Module Management

Principles of

Modularity

Page 7: Introducing Applitude: Simple Module Management

Principles of

Modularity(modules are...)

Page 8: Introducing Applitude: Simple Module Management

Specialized

(do one thing)

Page 9: Introducing Applitude: Simple Module Management

Independent

(don't dependon each other)

Page 10: Introducing Applitude: Simple Module Management

Decomposable

(work inisolation)

Page 11: Introducing Applitude: Simple Module Management

Recomposable

(work indifferent apps)

Page 12: Introducing Applitude: Simple Module Management

Substitutable

(can swap modules)

Page 13: Introducing Applitude: Simple Module Management

Module Interfaces

Page 14: Introducing Applitude: Simple Module Management

"Program to an interface, not an implementation."

- Gang of Four

Page 15: Introducing Applitude: Simple Module Management

Open / Closed Principle

Page 16: Introducing Applitude: Simple Module Management

Open for

Extension

Page 17: Introducing Applitude: Simple Module Management

Closed for

Modification(breaking changes)

Page 18: Introducing Applitude: Simple Module Management

Communicate through

Mediator(event bus)

Page 19: Introducing Applitude: Simple Module Management

Module FrameworkResponsibilities

Page 20: Introducing Applitude: Simple Module Management

Namespacing

Page 21: Introducing Applitude: Simple Module Management

Sandbox API

Page 22: Introducing Applitude: Simple Module Management

Expose Environment

Page 23: Introducing Applitude: Simple Module Management

Lifecycle

Page 24: Introducing Applitude: Simple Module Management

Load Timing

Page 25: Introducing Applitude: Simple Module Management

Define Module API

Page 26: Introducing Applitude: Simple Module Management

Introducing Applitude(a module framework)

Page 27: Introducing Applitude: Simple Module Management

An Applitude Module

// IIFE for encapsulation

(function (app) {// your code here

}(applitude));

Page 28: Introducing Applitude: Simple Module Management

Namespace it...

(function (app) { // namespace should be a var var namespace = 'hello';}(applitude));

Page 29: Introducing Applitude: Simple Module Management

Provide an API(function (app) { 'use strict'; var namespace = 'hello', api;

function hello() { return 'hello, world'; }

api = { hello: hello };

app.register(namespace, api);}(applitude));

Page 30: Introducing Applitude: Simple Module Management

Register(function (app) { 'use strict'; var namespace = 'hello', api;

function hello() { return 'hello, world'; }

api = { hello: hello };

app.register(namespace, api);}(applitude));

Page 31: Introducing Applitude: Simple Module Management

Sandbox API

app.register();app.environment // objectapp.deferred(); // also .when(), .queue(), ...app.o(); // prototypal ooapp.events();app.log();

Page 32: Introducing Applitude: Simple Module Management

api = { load: load, render: render,

beforeRender: [promise, iou, eventually] };

runs early!(please don't block)

.load()

Page 33: Introducing Applitude: Simple Module Management

api = { load: load, render: render,

beforeRender: [promise, iou, eventually] };

waits around...

.render()

Page 34: Introducing Applitude: Simple Module Management

api = { load: load, render: render,

beforeRender: [promise, iou, eventually] };

for load...

.render()

Page 35: Introducing Applitude: Simple Module Management

api = { load: load, render: render,

beforeRender: [promise, iou, eventually] };

and this stuff...

.beforeRender

Page 36: Introducing Applitude: Simple Module Management

$(document).ready(function () { // Make this faster! // developer.yahoo.com/yslow});

and this guy

.beforeRender

Page 37: Introducing Applitude: Simple Module Management

(function (app) { var namespace = 'sendMessage', api;

api = function sendMessage(message) { app.events.trigger('send_message.' +

namespace, message); };

app.register(namespace, api);}(applitude));

Modules should NOT call each other directly.

Use Events

Page 38: Introducing Applitude: Simple Module Management

(function (app) { var namespace = 'messageLogger', api;

function subscribe() { app.events.on('send_message.*',

function (payload) { app.log(payload); }); }

// public interface api = { load: subscribe };

// this never has to change app.register(namespace, api);}(applitude));

Listen

Page 39: Introducing Applitude: Simple Module Management

app.register();app.environment // object

app.deferred();app.when();app.o(); // prototypal oo...

Better Than Ice Cream

Page 40: Introducing Applitude: Simple Module Management

Get the Sourcehttp://dilvie.github.com/applitude/

Page 41: Introducing Applitude: Simple Module Management

Get the Bookhttp://ericleads.com/javascript-applications/