UNPKG

mmlpx

Version:

mobx model layer paradigm

39 lines (36 loc) 1.2 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = hydrate; var _mobx = require('mobx'); function hydrate(instance, Host) { var args = []; for (var _i = 2; _i < arguments.length; _i++) { args[_i - 2] = arguments[_i]; } if (!(instance instanceof Host)) { var real_1 = new (Host.bind.apply(Host, [void 0].concat(args)))(); // awake the reactive system of the model Object.keys(instance).forEach(function (key) { if (real_1[key] instanceof _mobx.ObservableMap) { var _a = real_1[key], name_1 = _a.name, enhancer_1 = _a.enhancer; (0, _mobx.runInAction)(function () { return real_1[key] = new _mobx.ObservableMap(instance[key], enhancer_1, name_1); }); } else { (0, _mobx.runInAction)(function () { return real_1[key] = instance[key]; }); } }); return real_1; } return instance; } /** * @author Kuitos * @homepage https://github.com/kuitos/ * @since 2018-06-26 15:43 */