UNPKG

mmlpx

Version:

mobx model layer paradigm

21 lines (20 loc) 956 B
import _isFunction from 'lodash/isFunction'; import _flatten from 'lodash/flatten'; /** * @author Kuitos * @homepage https://github.com/kuitos/ * @since 2017-09-13 */ import { modelNameSymbol } from '../meta'; export default function initialize(injector, ViewModel) { var args = []; for (var _i = 2; _i < arguments.length; _i++) { args[_i - 2] = arguments[_i]; } var constructorParams = args; // if the first argument is a function, we can initialize it with the invoker instance `this` if (_isFunction(args[0])) { constructorParams = _flatten([args[0].call(this, this)]); } var name = ViewModel[modelNameSymbol]; return injector.get.apply(injector, [ViewModel, { scope: "prototype" /* Prototype */, name: name }].concat(constructorParams)); }