UNPKG

1.13 kBJavaScriptView Raw
1export var NOOP = function () { };
2export var IDENTITY = function (_) { return _; };
3export function fail(message) {
4 throw new Error("[mobx-utils] " + message);
5}
6export function invariant(cond, message) {
7 if (message === void 0) { message = "Illegal state"; }
8 if (!cond)
9 fail(message);
10}
11export function addHiddenProp(object, propName, value) {
12 Object.defineProperty(object, propName, {
13 enumerable: false,
14 writable: true,
15 configurable: true,
16 value: value,
17 });
18}
19var deepFields = function (x) {
20 return (x &&
21 x !== Object.prototype &&
22 Object.getOwnPropertyNames(x).concat(deepFields(Object.getPrototypeOf(x)) || []));
23};
24var distinctDeepFields = function (x) {
25 var deepFieldsIndistinct = deepFields(x);
26 var deepFieldsDistinct = deepFieldsIndistinct.filter(function (item, index) { return deepFieldsIndistinct.indexOf(item) === index; });
27 return deepFieldsDistinct;
28};
29export var getAllMethodsAndProperties = function (x) {
30 return distinctDeepFields(x).filter(function (name) { return name !== "constructor" && !~name.indexOf("__"); });
31};