Пример #1
0
  // kernel.applyMiddleware(function logger(next) {
  //   return (context) => {
  //     let result = next(context);
  //     // console.log("CONTEXT: ", context);
  //     // console.log("RESULT: ", result);
  //     return result;
  //   };
  // });
  //

  /**
   * [_addFeature description]
   * @param {String} name
   * @param {Array} feature
   */
  function _addFeature(name, featureDesc){
    const featureName = name.toLowerCase();

    if (_.has(symbols, featureName)) {
      throw new Error(`Something called "${featureName}" already exists!`);
    }
    symbols[featureName] = featureName;

    if(!_.isArray(featureDesc)){
      throw new Error(`f(name, featureDescription), featureDescription MUST be an array ending with a function`);
    }

    const feature = _.last(featureDesc);

    if(!_.isFunction(feature)){
      throw new Error(`f(name, featureDescription), featureDescription MUST ends with a function`);
    }

    // Setup injectable
    decorate(injectable(), feature);

    const deps = _.initial(featureDesc).map((feature) => feature.toLowerCase());

    if(deps.length !== feature.length){
      throw new Error(`Mismatch between feature dependency array declaration and feature function argument length. See http://bit.ly/2aRp7iS`);
    }

    deps.forEach((dep, i) => {
      if (!_.has(symbols, dep)) {
        throw new Error(`Undeclared feature "${dep}"!`);
      }
      decorate(inject(dep), feature, i);
    });

    kernel.bind(featureName).to(feature).inSingletonScope();
  }
Пример #2
0
 deps.forEach((dep, i) => {
   if (!_.has(symbols, dep)) {
     throw new Error(`Undeclared feature "${dep}"!`);
   }
   decorate(inject(dep), feature, i);
 });