{"_id":"562d5f31d38b650d00444724","__v":51,"githubsync":"","category":{"_id":"562d68d5d38b650d0044472a","project":"56000f0d8c0c9d0d00dcad21","__v":5,"version":"56000f0e8c0c9d0d00dcad24","pages":["562d904026a0a10d00ad6c30","56398e44a19edf0d009721a7","5639e5bad25e8919005f3e6a","563a30e3a19edf0d009722e6","563bf349d8f2d20d00448b39"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-25T23:42:13.718Z","from_sync":false,"order":1,"slug":"getting-started","title":"Getting Started"},"project":"56000f0d8c0c9d0d00dcad21","version":{"_id":"56000f0e8c0c9d0d00dcad24","project":"56000f0d8c0c9d0d00dcad21","__v":13,"createdAt":"2015-09-21T14:07:10.176Z","releaseDate":"2015-09-21T14:07:10.176Z","categories":["56000f0e8c0c9d0d00dcad25","56008f2497f69f1700f21a36","560091601503430d007cc936","560e0d8054af2b0d005bbe92","560e3ce7ad6b200d00ff471c","560e3cf2c4e4ae0d00b42ed1","561c81d0e822e12b00e1fe00","561c81e9e822e12b00e1fe01","561c823d20b4a92b007d5147","56257f8951bf1c0d001f660a","562d5f165bd25e0d0054dbd4","562d68d5d38b650d0044472a","56421aebb0dc090d00f88438"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"user":"5600910981a9670d006d144f","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-25T23:01:05.796Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Work in progress, not all APIs are in released versions\"\n}\n[/block]\nSpace.Application is the central control object for your application. You need one on both the client and server to:\n\n- Orchestrate required [Modules](doc:modules)\n- [Inject](doc:injector) objects\n\nOn the server it also: \n- Exposes APIs (Wrapped Meteor Methods) and Publications\n- Enables Projections when using space:event-sourcing\n\nOn the client it also:\n- Registers Trackers, Controllers, and Components\n- Registers Stores when using space:flux\n \nWIP Notes:\nhook into lifecycle events such as starting, stopping, and resetting your application instance. The ability to override the configuration of it's dependent modules. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Contents\"\n}\n[/block]\n- Definition and configuration\n- Lifecycle\n- Behaviour\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Define your Space.Application\"\n}\n[/block]\nCreate 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.\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Suggested approach\",\n  \"body\": \"my-application-package/src/client/application.js\\nmy-application-package/src/server/application.js\"\n}\n[/block]\n**Server-side** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var MyApp = Space.Application.define('MyApp', {\\n   \\n  Dependencies: [],\\n  \\n  RequiredModules: [],\\n  \\n  Configuration: {},\\n\\n  // Publications: [],\\n  \\n  // Projections: [], // only when space:event-sourcing is installed\\n  \\n  // Apis: [],\\n\\n  // StaticMappings: []\\n\\n  Singletons: []// Low level\\n\\n});  \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**Client-side** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var MyApp = Space.Application.define('MyApp', {\\n   \\n  Dependencies: [],\\n  \\n  RequiredModules: [],\\n  \\n  Configuration: {},\\n\\n  // Trackers: [],\\n  \\n  Stores: [], // only when space:flux is installed\\n  \\n  Controllers: [], // only when space:flux is installed\\n  \\n  Components: [], // only when space:flux is installed\\n  \\n  // StaticMappings: []\\n  \\n  Singletons: [] // Low level\\n\\n});  \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Lifecycle\"\n}\n[/block]\nThe Application has a lifecycle that results in the following states:\n\n`Constructed` - `Initialized` - `Running` - `Stopped`\n\n**Initialize**\nIn 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.\n\n**Start**\nUsually this is where a method is called to start up part of the module.\n\n**Stop**\nThis should shut down any processes that are part of the running state of your application.\n\n**Reset**\nResetting 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.\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Resetting causes data loss\",\n  \"body\": \"…but it's rejected when process.env.NODE_ENV  is _production_ so there's not a nuke switch in a production app :-)\"\n}\n[/block]\nHooks are available to apply configuration from defined ENVs or the global `Configuration`, and/or perform any bootstrapping to create an encapsulated module.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var MyApp = Space.Application.define('MyApp', {\\n \\n  // required properties ommited for brevity\\n  \\n  beforeInitialize: function(){},\\n  onInitialize: function(){},\\n  afterInitialize: function(){},\\n  \\n  beforeStart: function(){},\\n  onStart: function(){},\\n  afterStart: function(){},\\n\\n  beforeReset: function(){},\\n  onReset: function(){},\\n  afterReset: function(){}\\n  \\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nYou can confirm the current state of by using the `.is(expectedState)` accessor, and control it using the following methods:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Meteor.startup(function(){\\n  app = new App()\\n  app.start();\\n  app.stop();\\n  app.reset();\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Behaviour\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Proposed additions to Space.Application\"\n}\n[/block]\napp.sendCommand()\napp.publishEvent()","excerpt":"Space.Application extends Space.Module","slug":"application","type":"basic","title":"Application"}

Application

Space.Application extends Space.Module

[block:callout] { "type": "warning", "title": "Work in progress, not all APIs are in released versions" } [/block] Space.Application is the central control object for your application. You need one on both the client and server to: - Orchestrate required [Modules](doc:modules) - [Inject](doc:injector) objects 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. [block:api-header] { "type": "basic", "title": "Contents" } [/block] - Definition and configuration - Lifecycle - Behaviour [block:api-header] { "type": "basic", "title": "Define your Space.Application" } [/block] 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. [block:callout] { "type": "success", "title": "Suggested approach", "body": "my-application-package/src/client/application.js\nmy-application-package/src/server/application.js" } [/block] **Server-side** [block:code] { "codes": [ { "code": "var MyApp = Space.Application.define('MyApp', {\n \n Dependencies: [],\n \n RequiredModules: [],\n \n Configuration: {},\n\n // Publications: [],\n \n // Projections: [], // only when space:event-sourcing is installed\n \n // Apis: [],\n\n // StaticMappings: []\n\n Singletons: []// Low level\n\n}); ", "language": "javascript" } ] } [/block] **Client-side** [block:code] { "codes": [ { "code": "var MyApp = Space.Application.define('MyApp', {\n \n Dependencies: [],\n \n RequiredModules: [],\n \n Configuration: {},\n\n // Trackers: [],\n \n Stores: [], // only when space:flux is installed\n \n Controllers: [], // only when space:flux is installed\n \n Components: [], // only when space:flux is installed\n \n // StaticMappings: []\n \n Singletons: [] // Low level\n\n}); ", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Lifecycle" } [/block] 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. [block:callout] { "type": "danger", "title": "Resetting causes data loss", "body": "…but it's rejected when process.env.NODE_ENV is _production_ so there's not a nuke switch in a production app :-)" } [/block] Hooks are available to apply configuration from defined ENVs or the global `Configuration`, and/or perform any bootstrapping to create an encapsulated module. [block:code] { "codes": [ { "code": "var MyApp = Space.Application.define('MyApp', {\n \n // required properties ommited for brevity\n \n beforeInitialize: function(){},\n onInitialize: function(){},\n afterInitialize: function(){},\n \n beforeStart: function(){},\n onStart: function(){},\n afterStart: function(){},\n\n beforeReset: function(){},\n onReset: function(){},\n afterReset: function(){}\n \n});", "language": "javascript" } ] } [/block] You can confirm the current state of by using the `.is(expectedState)` accessor, and control it using the following methods: [block:code] { "codes": [ { "code": "Meteor.startup(function(){\n app = new App()\n app.start();\n app.stop();\n app.reset();\n});", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Behaviour" } [/block] [block:callout] { "type": "warning", "title": "Proposed additions to Space.Application" } [/block] app.sendCommand() app.publishEvent()