packages/api-gateway/src/index.js
function loadModel(modelSpecPath, name) {
  return plugin.myrmex.fire('beforeModelLoad', modelSpecPath, name)
  .spread(() => {
    // Because we use require() to get the spec, it could either be a JSON file
    // or the content exported by a node module
    // But because require() caches the content it loads, we clone the result to avoid bugs
    // if the function is called twice
    const modelSpec = _.cloneDeep(require(modelSpecPath));

    // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./model
    const Model = require('./model');
    return Promise.resolve(new Model(name, modelSpec));
  })
  .then(model => {
    // This event allows to inject code to alter the model specification
    return plugin.myrmex.fire('afterModelLoad', model);
  })
  .spread((model) => {
    return Promise.resolve(model);
  });
}
function loadModel(modelSpecPath, name) {
  return plugin.myrmex.fire('beforeModelLoad', modelSpecPath, name)
  .spread(() => {
    // Because we use require() to get the spec, it could either be a JSON file
    // or the content exported by a node module
    // But because require() caches the content it loads, we clone the result to avoid bugs
    // if the function is called twice
    const modelSpec = _.cloneDeep(require(modelSpecPath));

    // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./model
    const Model = require('./model');
    return Promise.resolve(new Model(name, modelSpec));
  })
  .then(model => {
    // This event allows to inject code to alter the model specification
    return plugin.myrmex.fire('afterModelLoad', model);
  })
  .spread((model) => {
    return Promise.resolve(model);
  });
}
function loadModel ( modelSpecPath , name ) { return plugin . myrmex . fire ( 'beforeModelLoad' , modelSpecPath , name ) . spread ( ( ) => { // Because we use require() to get the spec, it could either be a JSON file // or the content exported by a node module // But because require() caches the content it loads, we clone the result to avoid bugs // if the function is called twice const modelSpec = _ . cloneDeep ( require ( modelSpecPath ) ) ; // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./model const Model = require ( './model' ) ; return Promise . resolve ( new Model ( name , modelSpec ) ) ; } ) . then ( model => { // This event allows to inject code to alter the model specification return plugin . myrmex . fire ( 'afterModelLoad' , model ) ; } ) . spread ( ( model ) => { return Promise . resolve ( model ) ; } ) ; }
Load an Model specification
@param {string} modelSpecPath - the path to the the model specification
@returns {Promise<Model>} - the promise of an model instance
Load an Model specification