All files / ima/page PageFactory.js

68.42% Statements 13/19
25% Branches 1/4
80% Functions 4/5
68.42% Lines 13/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101      4x                                 2x                   2x   2x                         2x 2x                                       2x 2x 2x 2x   2x               2x                                       4x  
import ns from '../namespace';
import GenericError from '../error/GenericError';
 
ns.namespace('ima.page');
 
/**
 * Factory for page.
 */
export default class PageFactory {
  /**
	 * Factory used by page management classes.
	 *
	 * @param {ObjectContainer} oc
	 */
  constructor(oc) {
    /**
		 * The current application object container.
		 *
		 * @type {ObjectContainer}
		 */
    this._oc = oc;
  }
 
  /**
	 * Create new instance of {@linkcode Controller}.
	 *
	 * @param {(string|function(new:Controller))} controller
	 * @return {Controller}
	 */
  createController(controller) {
    let controllerInstance = this._oc.create(controller);
 
    return controllerInstance;
  }
 
  /**
	 * Retrieves the specified react component class.
	 *
	 * @param {(string|function(new: React.Component))} view The namespace
	 *        referring to a react component class, or a react component class
	 *        constructor.
	 * @return {function(new: React.Component)} The react component class
	 *         constructor.
	 */
  createView(view) {
    Eif (typeof view === 'function') {
      return view;
    }
    let classConstructor = this._oc.getConstructorOf(view);
 
    if (classConstructor) {
      return classConstructor;
    } else {
      throw new GenericError(
        `ima.page.Factory:createView hasn't name of view "${view}".`
      );
    }
  }
 
  /**
	 * Returns decorated controller for ease setting seo params in controller.
	 *
	 * @param {Controller} controller
	 * @return {Controller}
	 */
  decorateController(controller) {
    let metaManager = this._oc.get('$MetaManager');
    let router = this._oc.get('$Router');
    let dictionary = this._oc.get('$Dictionary');
    let settings = this._oc.get('$Settings');
 
    let decoratedController = this._oc.create('$ControllerDecorator', [
      controller,
      metaManager,
      router,
      dictionary,
      settings
    ]);
 
    return decoratedController;
  }
 
  /**
	 * Returns decorated page state manager for extension.
	 *
	 * @param {PageStateManager} pageStateManager
	 * @param {string[]} allowedStateKeys
	 * @return {PageStateManager}
	 */
  decoratePageStateManager(pageStateManager, allowedStateKeys) {
    let decoratedPageStateManager = this._oc.create(
      '$PageStateManagerDecorator',
      [pageStateManager, allowedStateKeys]
    );
 
    return decoratedPageStateManager;
  }
}
 
ns.ima.page.PageFactory = PageFactory;