Application
Space.Application extends Space.Module
Work in progress, not all APIs are in released versions
Space.Application is the central control object for your application. You need one on both the client and server to:
On the server it also:
- Exposes APIs (Wrapped Meteor Methods) and Publications
- Enables Projections when using space:event-sourcing
On the client it also:
- Registers Trackers, Controllers, and Components
- Registers Stores when using space:flux
WIP Notes:
hook into lifecycle events such as starting, stopping, and resetting your application instance. The ability to override the configuration of it's dependent modules.
Contents
- Definition and configuration
- Lifecycle
- Behaviour
Define your Space.Application
Create an Application on both the client and server, ensuring you're not sending the server code to the client even if it's not being executed.
Suggested approach
my-application-package/src/client/application.js
my-application-package/src/server/application.js
Server-side
var MyApp = Space.Application.define('MyApp', {
Dependencies: [],
RequiredModules: [],
Configuration: {},
// Publications: [],
// Projections: [], // only when space:event-sourcing is installed
// Apis: [],
// StaticMappings: []
Singletons: []// Low level
});
Client-side
var MyApp = Space.Application.define('MyApp', {
Dependencies: [],
RequiredModules: [],
Configuration: {},
// Trackers: [],
Stores: [], // only when space:flux is installed
Controllers: [], // only when space:flux is installed
Components: [], // only when space:flux is installed
// StaticMappings: []
Singletons: [] // Low level
});
Lifecycle
The Application has a lifecycle that results in the following states:
Constructed
- Initialized
- Running
- Stopped
Initialize
In addition to bootstrapping the application using the Configuration API and module static mappings, this is where any required modules are also initialized. The order of initialization is from the deepest module right back to the Application.
Start
Usually this is where a method is called to start up part of the module.
Stop
This should shut down any processes that are part of the running state of your application.
Reset
Resetting is a non-production method that will scrub all data generated by the app. It's primary use is for testing, although is useful during development when wanting to bring your development state back to the first start.
Resetting causes data loss
…but it's rejected when process.env.NODEENV is _production so there's not a nuke switch in a production app :-)
Hooks are available to apply configuration from defined ENVs or the global Configuration
, and/or perform any bootstrapping to create an encapsulated module.
var MyApp = Space.Application.define('MyApp', {
// required properties ommited for brevity
beforeInitialize: function(){},
onInitialize: function(){},
afterInitialize: function(){},
beforeStart: function(){},
onStart: function(){},
afterStart: function(){},
beforeReset: function(){},
onReset: function(){},
afterReset: function(){}
});
You can confirm the current state of by using the .is(expectedState)
accessor, and control it using the following methods:
Meteor.startup(function(){
app = new App()
app.start();
app.stop();
app.reset();
});
Behaviour
Proposed additions to Space.Application
app.sendCommand()
app.publishEvent()
Updated less than a minute ago