mmlpx
Version:
mobx model layer paradigm
18 lines • 656 B
JavaScript
/**
* @author Kuitos
* @homepage https://github.com/kuitos/
* @since 2018-08-14 15:39
*/
import { getInjector } from '../core/dependency-inject/instantiate';
import { modelNameSymbol } from '../core/dependency-inject/meta';
export default function mock(Clazz, mockInstance, name) {
var container = getInjector()._getContainer();
var modelName = Clazz[modelNameSymbol] || (Clazz[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);
};
}