Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Meteor modules

587 views

Published on

Suggestions for module structure in Meteor.js applications.

Published in: Internet
  • Be the first to comment

Meteor modules

  1. 1. Structure and modules on Meteor.js Vyacheslav Voronchuk CEO of Starbuildr LLC
  2. 2. • /server - scripts are executed only on server • /client - scripts are executed only on client • /public - images and other static assets • all other scripts are executed both on server and client Execution scope
  3. 3. • HTML template are loaded first • After HTML templates scripts from /lib folder are loaded • main.* is loaded the last • Files which are nested deeper in file structure have priority in execution order • All other files are executed in alphabetic order Loading order
  4. 4. • lib/module1/* • lib/module2/* • client/module1/* • client/module2/* • server/module1/* • server/module2/* Modules by execution type
  5. 5. • module1/lib/* • module1/client/* • module1/server/* • module2/lib/* • module2/client/* • module2/server/* Modules by folders
  6. 6. • packages/module1/package.js • packages/module1/* • packages/module2/package.js • packages/module2/* Packages
  7. 7. var ACCESS_CLIENT = 'client'; var ACCESS_SERVER = 'server'; var ACCESS_BOTH = [ACCESS_CLIENT, ACCESS_SERVER]; var DEP_CONFIG = [ { name: 'coffeescript', access: ACCESS_BOTH }, { name: 'jquery', access: ACCESS_CLIENT }, { name: 'underscore', access: ACCESS_BOTH }, { name: 'meteor-platform', access: ACCESS_BOTH }, { name: 'accounts-ui', access: ACCESS_BOTH }, ]; var NPM_DEP_CONFIG = { 'redis': '0.12.1' }; Module dependencies
  8. 8. Package.on_use(function(api) { var depConfig, accessType, accessPaths, _i, _len; for (_i = 0, _len = DEP_CONFIG.length; _i < _len; _i++) { depConfig = DEP_CONFIG[_i]; api.use(depConfig.name, depConfig.access); } Npm.depends(NPM_DEP_CONFIG); }); Package bootstrap
  9. 9. var FILE_CONFIG = {}; FILE_CONFIG['ACCESS_BOTH'] = { 'coffee/': [ 'bootstrap.coffee' ], 'coffee/route/': [ 'config.coffee', 'IndexController.coffee' ] }; FILE_CONFIG['ACCESS_CLIENT'] = { 'client/view/': [ 'index.html', 'indexLayout.html' ], 'client/style/': [ 'fix-icon.css', 'main.css' ], }; File loading order
  10. 10. Package.on_use(function(api) { var file, filesToLoad, path, accessType, accessPaths, _i, _len; for (accessType in FILE_CONFIG) { accessPaths = FILE_CONFIG[accessType]; for (path in accessPaths) { filesToLoad = accessPaths[path]; for (_i = 0, _len = filesToLoad.length; _i < _len; _i++) { file = filesToLoad[_i]; api.add_files(path + file, eval(accessType)); } } } }); More package bootstrapping
  11. 11. var EXPORT = [‘Module1’, ‘Model1’]; Package.on_use(function(api) { return api.export(EXPORT); }); Public module namespace
  12. 12. Module1 = {} Module1.ROUTE_NAME = 'index' Module1.TEMPLATE_NAME = 'index' Meteor.startup(function() { if (Meteor.isServer) { bootstrapServer(); } if (Meteor.isClient) { bootstrapClient(); } }); var bootstrapClient = function() {}; var bootstrapServer = function() { Model1.setInstance(Model1.factory()); }; Module loader
  13. 13. class Model1 @COLLECTION_NAME = ‘model1' @collection = null @getCollection: -> @collection @setCollection: (collection) -> @collection = collection constructor: (data) -> _.extend @, data getCollection: -> Model1.getCollection() customMethod: -> Model1.setCollection new Mongo.Collection Model1.COLLECTION_NAME, transform: (data) -> new Model1 data Model
  14. 14. • Production-ready hosting for meteor deploy • Kubernetes.io (Docker container management system) • Official support for React.js and Angular • Official support for ECMAScript 2015 (ES6) • Better build tools Next release (Galaxy, Meteor 1.2)
  15. 15. • Support of SQL • REST and micro-services • Testing with Velocity • Better tools for mobile development and testing • Integration of routing in a core After Meteor 1.2
  16. 16. Thank you! voronchuk@starbuildr.com Skype: voronhukvk https://www.linkedin.com/in/voronchuk

×