UNPKG

mmlpx

Version:

mobx model layer paradigm

27 lines (23 loc) 769 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = mock; var _instantiate = require('../core/dependency-inject/instantiate'); var _meta = require('../core/dependency-inject/meta'); /** * @author Kuitos * @homepage https://github.com/kuitos/ * @since 2018-08-14 15:39 */ function mock(Clazz, mockInstance, name) { var container = (0, _instantiate.getInjector)()._getContainer(); var modelName = Clazz[_meta.modelNameSymbol] || (Clazz[_meta.modelNameSymbol] = name); if (!modelName) { throw new SyntaxError('you need to make sure that the model had a model name'); } container.set(modelName, mockInstance); return function recover() { container.set(modelName, null); }; }