UNPKG

@tacky/store

Version:

State management framework based on react

54 lines (43 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reactor = reactor; var _decorator = require("../utils/decorator"); /** * reactor decorator, making the reactor observable. */ function reactor() { var config = { deepProxy: true, isNeedRecord: true }; var decorator = function decorator(target, property, descriptor) { var newDescriptor = { enumerable: true, configurable: true, get: function get() { var current = this; return current.propertyGet(property, config); }, set: function set(newVal) { var current = this; current.propertySet(property, newVal, config); } }; // typescript only: (exp: @reactor() name: string = 'someone';) if (descriptor === void 0) { return Object.defineProperty(target, property, newDescriptor); } // babel only: (exp: @reactor() name = 'someone';) return newDescriptor; }; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if ((0, _decorator.quacksLikeADecorator)(args)) { // @decorator return decorator.apply(null, args); } // @decorator(args) config.deepProxy = args[0] !== void 0 ? args[0] : true; config.isNeedRecord = args[1] !== void 0 ? args[1] : true; return decorator; }