mmlpx
Version:
mobx model layer paradigm
54 lines (46 loc) • 1.8 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
require('reflect-metadata');
var _hydrate = require('../hydrate');
var _hydrate2 = _interopRequireDefault(_hydrate);
var _instantiate = require('../instantiate');
var _instantiate2 = _interopRequireDefault(_instantiate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (InjectedClass) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
return function (target, property) {
var symbol = Symbol(property);
if (!InjectedClass) {
InjectedClass = Reflect.getMetadata('design:type', target, property);
/* istanbul ignore next */
if (!InjectedClass) {
throw new SyntaxError('You must pass a Class for injection while you are not using typescript!' + 'Or you may need to add "emitDecoratorMetadata: true" configuration to your tsconfig.json');
}
}
return {
enumerable: true,
configurable: true,
get: function () {
if (!this[symbol]) {
var initializedValue = _instantiate2.default.apply(this, [InjectedClass].concat(args));
this[symbol] = initializedValue;
return initializedValue;
} else {
return _hydrate2.default.apply(void 0, [this[symbol], InjectedClass].concat(args));
}
},
// @formatter:off
// tslint:disable-next-line
set: function () {}
};
};
}; /**
* @author Kuitos
* @homepage https://github.com/kuitos/
* @since 2017-07-11
*/
;