Search

10/18/2009

Nicholas C. Zakas — Scalable JavaScript Application Architecture

Nicholas C. Zakas — Scalable JavaScript Application Architecture

Sandbox Jobs
• Consistency
– Interface must be dependable
• Security
– Determine which parts of the framework a module
can access
• Communication
– Translate module requests into core actions

The application core manages modules
The application core tells a module when
it should initialize and when it should shutdown

Application Core Jobs
Manage module lifecycle
– Tell modules when to start and stop doing their job
• Enable inter-module communication
– Allow loose coupling between modules that are
related to one another
• General error handling
– Detect, trap, and report errors in the system
• Be extensible
– The first three jobs are not enough!

Ideally, only the application core has any idea what base library is being used

tight coupling
TimelineFilter = {
changeFilter: function (filter) {
Timeline.applyFilter(filter);
}
};
StatusPoster = {
postStatus: function (status) {
Timeline.post(status);
}
};
Timeline = {
applyFilter: function (filter) {
//implementation
},
post: function (status) {
//implementation
}
};

loose coupling
Core.register("timeline-filter", function (sandbox) {
return {
changeFilter: function (filter) {
sandbox.notify({
type: "timeline-filter-change",
data: filter
});
}
};
});
Core.register("status-poster", function (sandbox) {
return {
postStatus: function (statusText) {
sandbox.notify({
type: "new-status",
data: statusText
});
}
};
});

When modules are loosely coupled,
removing a module doesn't break the others
No direct access to another module = no breaking should the module disappear

沒有留言: