Moostrap offers the initialization function of large-scale application from middle-scale.
Every one initialization processing is performed and it secures that initialization of application is ensured.
In order to use Moostrap, an initialization module is created first.
Using Moostrap.Module, initialization processing is registered and it goes.
Two or more registration is possible for initialization processing.
The option at the time of execution and the processing to perform are specified.
When it succeeds in processing, success is performed, and failure is performed when it fails.
(function(){ var Bootstrapper = this.Bootstrapper = new Moostrap.Module(); //Initialization processing is registered by the name of **bootstrapA**. //A basic setup of application is performed. Bootstrapper.register('bootstrapA', { title: 'bootstrapA', configuration: { name: 'bootstrap', description: 'bootstrap description' }, handler: function(app, opts){ try { app.setName(opts.name) .setDescription(opts.description); } catch(exception) { this.failure(); } this.success(); } }); //Initialization processing is registered by the name of **bootstrapB**. //The URL list of pictures is acquired using Ajax. Bootstrapper.register('bootstrapB', { title: 'bootstrapB', configuration: { url: 'http://example.com/images/' }, handler: function(app, opts){ var loader = new Request.JSON({ url: opts.url, onSuccess: function(response){ app.setImages(response.images); this.success(); }, onFailture: function(xhr){ this.failure(); } }); loader.send(); } }); }());
Application is initialized using the created module.
An onSuccess event will be generated if all initialization is performed.
If processing goes wrong in the middle of initialization processing, processing is interrupted and execution of application is stopped.
(function(module){ var application = { start: function(){ //do something }, abort: function(){ //do something }, run: function(){ var app = this; var bootstrapper = new Moostrap('sync', module, { //A setup of an initialization module is specified. //A setup here carries out the override of the default setup. configurations: { //The override of the setup of bootstrapA is carried out. bootstrapA: { name: 'Hello world', description: 'My first application' }, //The override of the setup of bootstrapB is carried out. bootstrapB: { url: 'http://helloworld.com/images/' } }, onSuccess: app.start, onFailture: app.abort }); //Application is started. bootstrapper.execute(app); } }; application.run(); }(Bootstrapper));
The initialization processing using Moostrap.Executer.Sync performs processings in order one by one.
Initialization processing is performed whenever one processing is completed.
packager build Moostrap/Moostrap.Executer.Sync +use-only Moostrap > moostrap-sync.js
The initialization processing using Moostrap.Executer.Async performs processings in order one by one.
A synchronization is not taken at this time.
packager build Moostrap/Moostrap.Executer.Async +use-only Moostrap > moostrap-async.js
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus