UNPKG

@tacky/store

Version:

State management framework based on react

47 lines (38 loc) 1.26 kB
import { quacksLikeADecorator } from '../utils/decorator'; /** * reactor decorator, making the reactor observable. */ export 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 (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; }