Socket
Socket
Sign inDemoInstall

mobservable

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobservable - npm Package Compare versions

Comparing version 0.6.5 to 0.6.6

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# 0.6.6:
* Deprecated observable array `.values()` and `.clone()`
* Deprecated observeUntilInvalid; use sideEffect instead
* Renamed mobservable.toJson to mobservable.toJSON
# 0.6.5:

@@ -2,0 +9,0 @@

12

dist/mobservable.d.ts

@@ -8,5 +8,5 @@ /**

interface _IMobservableStatic {
makeReactive : IMakeReactive;
makeReactive: IMakeReactive;
extendReactive(target: Object, properties: Object);
extendReactive(target: Object, properties: Object):Object;

@@ -21,7 +21,5 @@ isReactive(value: any): boolean;

observeUntilInvalid<T>(func: ()=>T, onInvalidate: Mobservable.Lambda, context?: Mobservable.IContextInfo): [T,Mobservable.Lambda];
transaction<T>(action: ()=>T): T;
toJson<T>(value: T): T;
toJSON<T>(value: T): T;

@@ -33,3 +31,3 @@ // decorator

debugLevel: number;
logLevel: number; // 0 = production, 1 = development, 2 = debugging

@@ -92,4 +90,2 @@ extras: {

replace(newItems: T[]);
values(): T[];
clone(): IObservableArray<T>;
find(predicate: (item: T,index: number,array: IObservableArray<T>)=>boolean,thisArg?,fromIndex?: number): T;

@@ -96,0 +92,0 @@ remove(value: T): boolean;

@@ -15,4 +15,4 @@ /**

(function (mobservable) {
var global = (function () { return this; })();
global.__mobservableTrackingStack = [];
var globalScope = (function () { return this; })();
globalScope.__mobservableTrackingStack = [];
var _;

@@ -166,5 +166,4 @@ (function (_) {

this.observing = __mobservableTrackingStack.pop();
if (this.observing.length === 0 && mobservable.debugLevel > 1 && !this.isDisposed) {
console.trace();
_.warn("You have created a function that doesn't observe any values, did you forget to make its dependencies observable?");
if (this.observing.length === 0 && mobservable.logLevel > 1 && !this.isDisposed) {
console.error("[mobservable] You have created a view function that doesn't observe any values, did you forget to make its dependencies observable?");
}

@@ -271,5 +270,8 @@ var _a = _.quickDiff(this.observing, this.prevObserving), added = _a[0], removed = _a[1];

});
var disposer = observable.observe(_.noop);
if (observable.observing.length === 0)
_.warn("mobservable.sideEffect: not a single observable was used inside the side-effect function. Side-effect would be a no-op.");
observable.setRefCount(+1);
var disposer = _.once(function () {
observable.setRefCount(-1);
});
if (mobservable.logLevel >= 2 && observable.observing.length === 0)
console.warn("[mobservable.sideEffect] not a single observable was used inside the side-effect function. Side-effect would be a no-op.");
disposer.$mobservable = observable;

@@ -280,3 +282,3 @@ return disposer;

function extendReactive(target, properties, context) {
_.extendReactive(target, properties, true, context);
return _.extendReactive(target, properties, true, context);
}

@@ -302,12 +304,12 @@ mobservable.extendReactive = extendReactive;

mobservable.observable = observable;
function toJson(source) {
function toJSON(source) {
if (!source)
return source;
if (Array.isArray(source) || source instanceof _.ObservableArray)
return source.map(toJson);
if (typeof source === "object") {
return source.map(toJSON);
if (typeof source === "object" && _.isPlainObject(source)) {
var res = {};
for (var key in source)
if (source.hasOwnProperty(key))
res[key] = toJson(source[key]);
res[key] = toJSON(source[key]);
return res;

@@ -317,2 +319,7 @@ }

}
mobservable.toJSON = toJSON;
function toJson(source) {
console.warn("mobservable.toJson is deprecated, use mobservable.toJSON instead");
return toJSON(source);
}
mobservable.toJson = toJson;

@@ -324,7 +331,22 @@ function transaction(action) {

function observeUntilInvalid(func, onInvalidate, context) {
var watch = new _.WatchedExpression(func, onInvalidate, context || func.name);
return [watch.value, function () { return watch.dispose(); }, watch];
console.warn("mobservable.observeUntilInvalid is deprecated and will be removed in 0.7");
var hasRun = false;
var result;
var disposer = sideEffect(function () {
if (!hasRun) {
hasRun = true;
result = func();
}
else {
onInvalidate();
}
});
return [result, disposer, disposer['$mobservable']];
}
mobservable.observeUntilInvalid = observeUntilInvalid;
mobservable.debugLevel = 0;
mobservable.logLevel = 1;
setTimeout(function () {
if (mobservable.logLevel > 0)
console.info("Welcome to mobservable. Current logLevel = " + mobservable.logLevel + ". Change mobservable.logLevel according to your needs: 0 = production, 1 = development, 2 = debugging");
}, 1);
var _;

@@ -391,7 +413,2 @@ (function (_) {

(function (_) {
function warn(message) {
if (console)
console.warn("[mobservable:warning] " + message);
}
_.warn = warn;
function once(func) {

@@ -608,2 +625,3 @@ var invoked = false;

ObservableArray.prototype.values = function () {
console.warn("mobservable.array.values is deprecated and will be removed in 0.7, use slice() instead");
this.$mobservable.notifyObserved();

@@ -617,2 +635,3 @@ return this.$mobservable.values.slice();

ObservableArray.prototype.clone = function () {
console.warn("mobservable.array.clone is deprecated and will be removed in 0.7");
this.$mobservable.notifyObserved();

@@ -692,29 +711,23 @@ return new ObservableArray(this.$mobservable.values, this.$mobservable.recurse, {

};
ObservableArray.prototype.toString = function () { return this.wrapReadFunction("toString", arguments); };
ObservableArray.prototype.toLocaleString = function () { return this.wrapReadFunction("toLocaleString", arguments); };
ObservableArray.prototype.concat = function () { return this.wrapReadFunction("concat", arguments); };
ObservableArray.prototype.join = function (separator) { return this.wrapReadFunction("join", arguments); };
ObservableArray.prototype.slice = function (start, end) { return this.wrapReadFunction("slice", arguments); };
ObservableArray.prototype.indexOf = function (searchElement, fromIndex) { return this.wrapReadFunction("indexOf", arguments); };
ObservableArray.prototype.lastIndexOf = function (searchElement, fromIndex) { return this.wrapReadFunction("lastIndexOf", arguments); };
ObservableArray.prototype.every = function (callbackfn, thisArg) { return this.wrapReadFunction("every", arguments); };
ObservableArray.prototype.some = function (callbackfn, thisArg) { return this.wrapReadFunction("some", arguments); };
ObservableArray.prototype.forEach = function (callbackfn, thisArg) { return this.wrapReadFunction("forEach", arguments); };
ObservableArray.prototype.map = function (callbackfn, thisArg) { return this.wrapReadFunction("map", arguments); };
ObservableArray.prototype.filter = function (callbackfn, thisArg) { return this.wrapReadFunction("filter", arguments); };
ObservableArray.prototype.reduce = function (callbackfn, initialValue) { return this.wrapReadFunction("reduce", arguments); };
ObservableArray.prototype.reduceRight = function (callbackfn, initialValue) { return this.wrapReadFunction("reduceRight", arguments); };
ObservableArray.prototype.wrapReadFunction = function (funcName, initialArgs) {
var baseFunc = Array.prototype[funcName];
return (ObservableArray.prototype[funcName] = function () {
this.$mobservable.notifyObserved();
return baseFunc.apply(this.$mobservable.values, arguments);
}).apply(this, initialArgs);
ObservableArray.prototype.toString = function () {
return "[mobservable.array] " + Array.prototype.toString.apply(this.$mobservable.values, arguments);
};
ObservableArray.prototype.toLocaleString = function () {
return "[mobservable.array] " + Array.prototype.toLocaleString.apply(this.$mobservable.values, arguments);
};
ObservableArray.prototype.concat = function () { throw "Illegal state"; };
ObservableArray.prototype.join = function (separator) { throw "Illegal state"; };
ObservableArray.prototype.slice = function (start, end) { throw "Illegal state"; };
ObservableArray.prototype.indexOf = function (searchElement, fromIndex) { throw "Illegal state"; };
ObservableArray.prototype.lastIndexOf = function (searchElement, fromIndex) { throw "Illegal state"; };
ObservableArray.prototype.every = function (callbackfn, thisArg) { throw "Illegal state"; };
ObservableArray.prototype.some = function (callbackfn, thisArg) { throw "Illegal state"; };
ObservableArray.prototype.forEach = function (callbackfn, thisArg) { throw "Illegal state"; };
ObservableArray.prototype.map = function (callbackfn, thisArg) { throw "Illegal state"; };
ObservableArray.prototype.filter = function (callbackfn, thisArg) { throw "Illegal state"; };
ObservableArray.prototype.reduce = function (callbackfn, initialValue) { throw "Illegal state"; };
ObservableArray.prototype.reduceRight = function (callbackfn, initialValue) { throw "Illegal state"; };
ObservableArray.prototype.assertNotComputing = function (funcName) {
if (_.isComputingView()) {
var e = "[Mobservable.Array] The method array." + funcName + " is not allowed to be used inside reactive views since it alters the state.";
console.error(e);
console.trace();
throw new Error();
console.error("mobservable.array: The method array." + funcName + " is not allowed to be used inside reactive views since it alters the state.");
}

@@ -725,2 +738,22 @@ };

_.ObservableArray = ObservableArray;
[
"concat",
"join",
"slice",
"indexOf",
"lastIndexOf",
"every",
"some",
"forEach",
"map",
"filter",
"reduce",
"reduceRight",
].forEach(function (funcName) {
var baseFunc = Array.prototype[funcName];
ObservableArray.prototype[funcName] = function () {
this.$mobservable.notifyObserved();
return baseFunc.apply(this.$mobservable.values, arguments);
};
});
var OBSERVABLE_ARRAY_BUFFER_SIZE = 0;

@@ -780,7 +813,11 @@ var ENUMERABLE_PROPS = [];

__mobservableTrackingStack.push([]);
thing[property];
var dnode = __mobservableTrackingStack.pop()[0];
if (!dnode)
throw new Error("[mobservable.getDNode] property '" + property + "' of '" + thing + "' doesn't seem to be a reactive property");
return dnode;
try {
thing[property];
}
finally {
var dnode = __mobservableTrackingStack.pop()[0];
if (!dnode)
throw new Error("[mobservable.getDNode] property '" + property + "' of '" + thing + "' doesn't seem to be a reactive property");
return dnode;
}
}

@@ -883,3 +920,3 @@ if (thing.$mobservable) {

(function (_) {
_.NON_PURE_VIEW_ERROR = "[Mobservable] It is not allowed to change the state during the computation of a reactive view.";
_.NON_PURE_VIEW_ERROR = "[mobservable] It is not allowed to change the state during the computation of a reactive view.";
var ObservableValue = (function (_super) {

@@ -904,5 +941,3 @@ __extends(ObservableValue, _super);

if (_.isComputingView()) {
console.error(_.NON_PURE_VIEW_ERROR);
console.trace();
throw new Error(_.NON_PURE_VIEW_ERROR);
console.error(_.NON_PURE_VIEW_ERROR + (" (stack size is " + __mobservableTrackingStack.length + ")"));
}

@@ -978,6 +1013,4 @@ if (value !== this._value) {

if (this.hasError) {
if (mobservable.debugLevel) {
console.trace();
_.warn(this + ": rethrowing caught exception to observer: " + this._value + (this._value.cause || ''));
}
if (mobservable.logLevel > 0)
console.error(this + ": rethrowing caught exception to observer: " + this._value + (this._value.cause || ''));
throw this._value;

@@ -994,3 +1027,3 @@ }

if (this.isComputing)
throw new Error("Cycle detected");
throw new Error("[mobservable] Cycle detected");
this.isComputing = true;

@@ -1002,3 +1035,3 @@ newValue = this.func.call(this.scope);

this.hasError = true;
console.error(this + "Caught error during computation: ", e);
console.error("[mobservable] Caught error during computation: ", e);
if (e instanceof Error)

@@ -1273,32 +1306,2 @@ newValue = e;

})(mobservable || (mobservable = {}));
/// <reference path="./observablevalue" />
var mobservable;
(function (mobservable) {
var _;
(function (_) {
var WatchedExpression = (function (_super) {
__extends(WatchedExpression, _super);
function WatchedExpression(expr, onInvalidate, context) {
_super.call(this, context);
this.expr = expr;
this.onInvalidate = onInvalidate;
this.didEvaluate = false;
this.computeNextState();
}
WatchedExpression.prototype.compute = function () {
if (!this.didEvaluate) {
this.didEvaluate = true;
this.value = this.expr();
}
else {
this.dispose();
this.onInvalidate();
}
return false;
};
return WatchedExpression;
})(_.ObservingDNode);
_.WatchedExpression = WatchedExpression;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
/**

@@ -1312,3 +1315,2 @@ * This file basically works around all the typescript limitations that exist atm:

/// <reference path="./api.ts" />
/// <reference path="./watch.ts" />
var forCompilerVerificationOnly = mobservable;

@@ -1315,0 +1317,0 @@ (function (root, factory) {

@@ -1,1 +0,1 @@

var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},mobservable;!function(a){var b=function(){return this}();b.__mobservableTrackingStack=[];var c;!function(b){function c(){return __mobservableTrackingStack.length}function d(){return __mobservableTrackingStack.length>0}var e=0;!function(a){a[a.STALE=0]="STALE",a[a.PENDING=1]="PENDING",a[a.READY=2]="READY"}(b.DNodeState||(b.DNodeState={}));var f=b.DNodeState,g=function(){function a(a){this.context=a,this.id=++e,this.state=f.READY,this.observers=[],this.isDisposed=!1,this.externalRefenceCount=0,a.name||(a.name="[m#"+this.id+"]")}return a.prototype.setRefCount=function(a){this.externalRefenceCount+=a},a.prototype.addObserver=function(a){this.observers[this.observers.length]=a},a.prototype.removeObserver=function(a){var b=this.observers,c=b.indexOf(a);-1!==c&&b.splice(c,1)},a.prototype.markStale=function(){this.state===f.READY&&(this.state=f.STALE,b.transitionTracker&&b.reportTransition(this,"STALE"),this.notifyObservers())},a.prototype.markReady=function(a){this.state!==f.READY&&(this.state=f.READY,b.transitionTracker&&b.reportTransition(this,"READY",!0,this._value),this.notifyObservers(a))},a.prototype.notifyObservers=function(a){void 0===a&&(a=!1);for(var b=this.observers.slice(),c=b.length,d=0;c>d;d++)b[d].notifyStateChange(this,a)},a.prototype.notifyObserved=function(){var a=__mobservableTrackingStack,b=a.length;if(b>0){var c=a[b-1],d=c.length;c[d-1]!==this&&c[d-2]!==this&&(c[d]=this)}},a.prototype.dispose=function(){if(this.observers.length)throw new Error("Cannot dispose DNode; it is still being observed");this.isDisposed=!0},a.prototype.toString=function(){return"DNode["+this.context.name+", state: "+this.state+", observers: "+this.observers.length+"]"},a}();b.RootDNode=g;var h=function(c){function d(){c.apply(this,arguments),this.isSleeping=!0,this.hasCycle=!1,this.observing=[],this.prevObserving=null,this.dependencyChangeCount=0,this.dependencyStaleCount=0}return __extends(d,c),d.prototype.setRefCount=function(a){var b=this.externalRefenceCount+=a;0===b?this.tryToSleep():b===a&&this.wakeUp()},d.prototype.removeObserver=function(a){c.prototype.removeObserver.call(this,a),this.tryToSleep()},d.prototype.tryToSleep=function(){if(!this.isSleeping&&0===this.observers.length&&0===this.externalRefenceCount){for(var a=0,b=this.observing.length;b>a;a++)this.observing[a].removeObserver(this);this.observing=[],this.isSleeping=!0}},d.prototype.wakeUp=function(){this.isSleeping&&(this.isSleeping=!1,this.state=f.PENDING,this.computeNextState())},d.prototype.notifyStateChange=function(a,c){var d=this;a.state===f.STALE?1===++this.dependencyStaleCount&&this.markStale():(c&&(this.dependencyChangeCount+=1),0===--this.dependencyStaleCount&&(this.state=f.PENDING,b.Scheduler.schedule(function(){d.dependencyChangeCount>0?d.computeNextState():d.markReady(!1),d.dependencyChangeCount=0})))},d.prototype.computeNextState=function(){this.trackDependencies(),b.transitionTracker&&b.reportTransition(this,"PENDING");var a=this.compute();this.bindDependencies(),this.markReady(a)},d.prototype.compute=function(){throw"Abstract!"},d.prototype.trackDependencies=function(){this.prevObserving=this.observing,__mobservableTrackingStack[__mobservableTrackingStack.length]=[]},d.prototype.bindDependencies=function(){this.observing=__mobservableTrackingStack.pop(),0===this.observing.length&&a.debugLevel>1&&!this.isDisposed&&(console.trace(),b.warn("You have created a function that doesn't observe any values, did you forget to make its dependencies observable?"));var c=b.quickDiff(this.observing,this.prevObserving),e=c[0],f=c[1];this.prevObserving=null;for(var g=0,h=f.length;h>g;g++)f[g].removeObserver(this);this.hasCycle=!1;for(var g=0,h=e.length;h>g;g++){var i=e[g];i instanceof d&&i.findCycle(this)?(this.hasCycle=!0,this.observing.splice(this.observing.indexOf(e[g]),1),i.hasCycle=!0):e[g].addObserver(this)}},d.prototype.findCycle=function(a){var b=this.observing;if(-1!==b.indexOf(a))return!0;for(var c=b.length,e=0;c>e;e++)if(b[e]instanceof d&&b[e].findCycle(a))return!0;return!1},d.prototype.dispose=function(){if(this.observing)for(var a=this.observing.length,b=0;a>b;b++)this.observing[b].removeObserver(this);this.observing=null,c.prototype.dispose.call(this)},d}(g);b.ObservingDNode=h,b.stackDepth=c,b.isComputingView=d}(c=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){function b(a,b){if(d(a))return a;b=b||{},a instanceof k.AsReference&&(a=a.value,b.as="reference");var c=b.recurse!==!1,e="reference"===b.as?k.ValueType.Reference:k.getTypeOfValue(a),f={name:b.name,object:b.context||b.scope};switch(e){case k.ValueType.Reference:case k.ValueType.ComplexObject:return k.toGetterSetterFunction(new k.ObservableValue(a,!1,f));case k.ValueType.ComplexFunction:throw new Error("[mobservable:error] Creating reactive functions from functions with multiple arguments is currently not supported, see https://github.com/mweststrate/mobservable/issues/12");case k.ValueType.ViewFunction:return f.name||(f.name=a.name),k.toGetterSetterFunction(new k.ObservableView(a,b.scope||b.context,f));case k.ValueType.Array:return new k.ObservableArray(a,c,f);case k.ValueType.PlainObject:return k.extendReactive({},a,c,f)}throw"Illegal State"}function c(a){return new k.AsReference(a)}function d(a){return null===a||void 0===a?!1:!!a.$mobservable}function e(a,b){var c=new k.ObservableView(a,b,{object:b,name:a.name}),d=c.observe(k.noop);return 0===c.observing.length&&k.warn("mobservable.sideEffect: not a single observable was used inside the side-effect function. Side-effect would be a no-op."),d.$mobservable=c,d}function f(a,b,c){k.extendReactive(a,b,!0,c)}function g(a,b,c){var d=c?c.value:null;if("function"==typeof d)throw new Error("@observable functions are deprecated. Use @observable (getter) properties instead");if(c&&c.set)throw new Error("@observable properties cannot have a setter.");Object.defineProperty(a,b,{configurable:!0,enumberable:!0,get:function(){return k.ObservableObject.asReactive(this,null).set(b,void 0,!0),this[b]},set:function(a){k.ObservableObject.asReactive(this,null).set(b,a,!0)}})}function h(a){if(!a)return a;if(Array.isArray(a)||a instanceof k.ObservableArray)return a.map(h);if("object"==typeof a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=h(a[c]));return b}return a}function i(a){return k.Scheduler.batch(a)}function j(a,b,c){var d=new k.WatchedExpression(a,b,c||a.name);return[d.value,function(){return d.dispose()},d]}a.makeReactive=b,a.asReference=c,a.isReactive=d,a.sideEffect=e,a.extendReactive=f,a.observable=g,a.toJson=h,a.transaction=i,a.observeUntilInvalid=j,a.debugLevel=0;var k;!function(a){function b(b){return null===b||void 0===b?e.Reference:"function"==typeof b?b.length?e.ComplexFunction:e.ViewFunction:Array.isArray(b)||b instanceof a.ObservableArray?e.Array:"object"==typeof b?a.isPlainObject(b)?e.PlainObject:e.ComplexObject:e.Reference}function c(b,c,d,e){var f=a.ObservableObject.asReactive(b,e);for(var g in c)c.hasOwnProperty(g)&&f.set(g,c[g],d);return b}function d(a){var b=function(b){return arguments.length>0?void a.set(b):a.get()};return b.$mobservable=a,b.observe=function(b,c){return a.observe(b,c)},b.toString=function(){return a.toString()},b}!function(a){a[a.Reference=0]="Reference",a[a.PlainObject=1]="PlainObject",a[a.ComplexObject=2]="ComplexObject",a[a.Array=3]="Array",a[a.ViewFunction=4]="ViewFunction",a[a.ComplexFunction=5]="ComplexFunction"}(a.ValueType||(a.ValueType={}));var e=a.ValueType;a.getTypeOfValue=b,a.extendReactive=c,a.toGetterSetterFunction=d;var f=function(){function a(a){this.value=a}return a}();a.AsReference=f}(k=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){function b(a){console&&console.warn("[mobservable:warning] "+a)}function c(a){var b=!1;return function(){return b?void 0:(b=!0,a.apply(this,arguments))}}function d(){}function e(a){var b=[];return a.forEach(function(a){-1===b.indexOf(a)&&b.push(a)}),b}function f(a){return null!==a&&"object"==typeof a&&Object.getPrototypeOf(a)===Object.prototype}function g(a,b){if(!b||!b.length)return[a,[]];if(!a||!a.length)return[[],b];for(var c=[],d=[],e=0,f=0,g=a.length,h=!1,i=0,j=0,k=b.length,l=!1,m=!1;!m&&!h;){if(!l){if(g>e&&k>i&&a[e]===b[i]){if(e++,i++,e===g&&i===k)return[c,d];continue}f=e,j=i,l=!0}j+=1,f+=1,j>=k&&(m=!0),f>=g&&(h=!0),h||a[f]!==b[i]?m||b[j]!==a[e]||(d.push.apply(d,b.slice(i,j)),i=j+1,e++,l=!1):(c.push.apply(c,a.slice(e,f)),e=f+1,i++,l=!1)}return c.push.apply(c,a.slice(e)),d.push.apply(d,b.slice(i)),[c,d]}a.warn=b,a.once=c,a.noop=d,a.unique=e,a.isPlainObject=f,a.quickDiff=g}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){function c(a){var b={enumerable:!1,configurable:!1,set:function(b){if(a<this.$mobservable.values.length){var c=this.$mobservable.values[a];c!==b&&(this.$mobservable.values[a]=b,this.notifyChildUpdate(a,c))}else{if(a!==this.$mobservable.values.length)throw new Error("ObservableArray: Index out of bounds, "+a+" is larger than "+this.values.length);this.push(b)}},get:function(){return a<this.$mobservable.values.length?(this.$mobservable.notifyObserved(),this.$mobservable.values[a]):void 0}};Object.defineProperty(g.prototype,""+a,b),b.enumerable=!0,b.configurable=!0,i[a]=b}function d(a){for(var b=h;a>b;b++)c(b);h=a}var e=function(){function a(){}return a}();e.prototype=[];var f=function(a){function c(c,d,e){a.call(this,e),this.array=c,this.recurse=d,this.values=[],this.changeEvent=new b.SimpleEventEmitter,e.object||(e.object=c)}return __extends(c,a),c}(b.RootDNode);b.ObservableArrayAdministration=f;var g=function(c){function e(a,b,d){c.call(this),Object.defineProperty(this,"$mobservable",{enumerable:!1,configurable:!1,value:new f(this,b,d)}),a&&a.length&&this.replace(a)}return __extends(e,c),Object.defineProperty(e.prototype,"length",{get:function(){return this.$mobservable.notifyObserved(),this.$mobservable.values.length},set:function(a){if(this.assertNotComputing("spliceWithArray"),"number"!=typeof a||0>a)throw new Error("Out of range: "+a);var b=this.$mobservable.values.length;a!==b&&(a>b?this.spliceWithArray(b,0,new Array(a-b)):this.spliceWithArray(a,b-a))},enumerable:!0,configurable:!0}),e.prototype.updateLength=function(a,b){if(0>b)for(var c=a+b;a>c;c++)delete this[c];else if(b>0){a+b>h&&d(a+b);for(var c=a,e=a+b;e>c;c++)Object.defineProperty(this,""+c,i[c])}},e.prototype.spliceWithArray=function(a,b,c){var d=this;this.assertNotComputing("spliceWithArray");var e=this.$mobservable.values.length;if(!(void 0!==c&&0!==c.length||0!==b&&0!==e))return[];void 0===a?a=0:a>e?a=e:0>a&&(a=Math.max(0,e+a)),b=1===arguments.length?e-a:void 0===b||null===b?0:Math.max(0,Math.min(b,e-a)),void 0===c?c=[]:this.$mobservable.recurse&&(c=c.map(function(a){return d.makeReactiveArrayItem(a)}));var f=c.length-b,g=(h=this.$mobservable.values).splice.apply(h,[a,b].concat(c));return this.updateLength(e,f),this.notifySplice(a,g,c),g;var h},e.prototype.makeReactiveArrayItem=function(c){if(a.isReactive(c))return c;if(c instanceof b.AsReference)return c=c.value;var d={object:this.$mobservable.context.object,name:this.$mobservable.context.name+"[x]"};return Array.isArray(c)?new b.ObservableArray(c,!0,d):b.isPlainObject(c)?b.extendReactive({},c,!0,d):c},e.prototype.notifyChildUpdate=function(a,b){this.notifyChanged(),this.$mobservable.changeEvent.emit({object:this,type:"update",index:a,oldValue:b})},e.prototype.notifySplice=function(a,b,c){(0!==b.length||0!==c.length)&&(this.notifyChanged(),this.$mobservable.changeEvent.emit({object:this,type:"splice",index:a,addedCount:c.length,removed:b}))},e.prototype.notifyChanged=function(){this.$mobservable.markStale(),this.$mobservable.markReady(!0)},e.prototype.observe=function(a,b){return void 0===b&&(b=!1),b&&a({object:this,type:"splice",index:0,addedCount:this.$mobservable.values.length,removed:[]}),this.$mobservable.changeEvent.on(a)},e.prototype.clear=function(){return this.splice(0)},e.prototype.replace=function(a){return this.spliceWithArray(0,this.$mobservable.values.length,a)},e.prototype.values=function(){return this.$mobservable.notifyObserved(),this.$mobservable.values.slice()},e.prototype.toJSON=function(){return this.$mobservable.notifyObserved(),this.$mobservable.values.slice()},e.prototype.clone=function(){return this.$mobservable.notifyObserved(),new e(this.$mobservable.values,this.$mobservable.recurse,{object:null,name:this.$mobservable.context.name+"[clone]"})},e.prototype.find=function(a,b,c){void 0===c&&(c=0),this.$mobservable.notifyObserved();for(var d=this.$mobservable.values,e=d.length,f=c;e>f;f++)if(a.call(b,d[f],f,this))return d[f];return null},e.prototype.splice=function(a,b){for(var c=[],d=2;d<arguments.length;d++)c[d-2]=arguments[d];switch(this.assertNotComputing("splice"),arguments.length){case 0:return[];case 1:return this.spliceWithArray(a);case 2:return this.spliceWithArray(a,b)}return this.spliceWithArray(a,b,c)},e.prototype.push=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this.assertNotComputing("push"),this.spliceWithArray(this.$mobservable.values.length,0,a),this.$mobservable.values.length},e.prototype.pop=function(){return this.assertNotComputing("pop"),this.splice(Math.max(this.$mobservable.values.length-1,0),1)[0]},e.prototype.shift=function(){return this.assertNotComputing("shift"),this.splice(0,1)[0]},e.prototype.unshift=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this.assertNotComputing("unshift"),this.spliceWithArray(0,0,a),this.$mobservable.values.length},e.prototype.reverse=function(){return this.assertNotComputing("reverse"),this.replace(this.$mobservable.values.reverse())},e.prototype.sort=function(a){return this.assertNotComputing("sort"),this.replace(this.$mobservable.values.sort.apply(this.$mobservable.values,arguments))},e.prototype.remove=function(a){this.assertNotComputing("remove");var b=this.$mobservable.values.indexOf(a);return b>-1?(this.splice(b,1),!0):!1},e.prototype.toString=function(){return this.wrapReadFunction("toString",arguments)},e.prototype.toLocaleString=function(){return this.wrapReadFunction("toLocaleString",arguments)},e.prototype.concat=function(){return this.wrapReadFunction("concat",arguments)},e.prototype.join=function(a){return this.wrapReadFunction("join",arguments)},e.prototype.slice=function(a,b){return this.wrapReadFunction("slice",arguments)},e.prototype.indexOf=function(a,b){return this.wrapReadFunction("indexOf",arguments)},e.prototype.lastIndexOf=function(a,b){return this.wrapReadFunction("lastIndexOf",arguments)},e.prototype.every=function(a,b){return this.wrapReadFunction("every",arguments)},e.prototype.some=function(a,b){return this.wrapReadFunction("some",arguments)},e.prototype.forEach=function(a,b){return this.wrapReadFunction("forEach",arguments)},e.prototype.map=function(a,b){return this.wrapReadFunction("map",arguments)},e.prototype.filter=function(a,b){return this.wrapReadFunction("filter",arguments)},e.prototype.reduce=function(a,b){return this.wrapReadFunction("reduce",arguments)},e.prototype.reduceRight=function(a,b){return this.wrapReadFunction("reduceRight",arguments)},e.prototype.wrapReadFunction=function(a,b){var c=Array.prototype[a];return(e.prototype[a]=function(){return this.$mobservable.notifyObserved(),c.apply(this.$mobservable.values,arguments)}).apply(this,b)},e.prototype.assertNotComputing=function(a){if(b.isComputingView()){var c="[Mobservable.Array] The method array."+a+" is not allowed to be used inside reactive views since it alters the state.";throw console.error(c),console.trace(),new Error}},e}(e);b.ObservableArray=g;var h=0,i=[];d(1e3)}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){function c(c,d){if(!a.isReactive(c))throw new Error("[mobservable.getDNode] "+c+" doesn't seem to be reactive");if(void 0!==d){__mobservableTrackingStack.push([]),c[d];var e=__mobservableTrackingStack.pop()[0];if(!e)throw new Error("[mobservable.getDNode] property '"+d+"' of '"+c+"' doesn't seem to be a reactive property");return e}if(c.$mobservable){if(c.$mobservable instanceof b.ObservableObject)throw new Error("[mobservable.getDNode] missing properties parameter. Please specify a property of '"+c+"'.");return c.$mobservable}throw new Error("[mobservable.getDNode] "+c+" doesn't seem to be reactive")}function d(a,c,d,e){void 0===d&&(d=!1),void 0===e&&(e=null),b.transitionTracker.emit({id:a.id,name:a.context.name,context:a.context.object,state:c,changed:d,newValue:e})}b.getDNode=c,b.reportTransition=d,b.transitionTracker=null}(b=a._||(a._={}));var c;!function(a){function c(a,c){return d(b.getDNode(a,c))}function d(a){var c={id:a.id,name:a.context.name,context:a.context.object||null};return a instanceof b.ObservingDNode&&a.observing.length&&(c.dependencies=b.unique(a.observing).map(d)),c}function e(a,c){return f(b.getDNode(a,c))}function f(a){var c={id:a.id,name:a.context.name,context:a.context.object||null};return a.observers.length&&(c.observers=b.unique(a.observers).map(f)),a.externalRefenceCount>0&&(c.listeners=a.externalRefenceCount),c}function g(a){var b=[],c=!1;return function(d){(a||d.changed)&&b.push(d),c||(c=!0,setTimeout(function(){console[console.table?"table":"dir"](b),b=[],c=!1},1))}}function h(a,c){void 0===a&&(a=!1),b.transitionTracker||(b.transitionTracker=new b.SimpleEventEmitter);var d=c?function(b){(a||b.changed)&&c(b)}:g(a),e=b.transitionTracker.on(d);return b.once(function(){e(),0===b.transitionTracker.listeners.length&&(b.transitionTracker=null)})}a.getDependencyTree=c,a.getObserverTree=e,a.trackTransitions=h}(c=a.extras||(a.extras={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){b.NON_PURE_VIEW_ERROR="[Mobservable] It is not allowed to change the state during the computation of a reactive view.";var c=function(c){function d(a,d,e){c.call(this,e),this.value=a,this.recurse=d,this.changeEvent=new b.SimpleEventEmitter,this._value=this.makeReferenceValueReactive(a)}return __extends(d,c),d.prototype.makeReferenceValueReactive=function(c){return this.recurse&&(Array.isArray(c)||b.isPlainObject(c))?a.makeReactive(c,{context:this.context.object,name:this.context.name}):c},d.prototype.set=function(a){if(b.isComputingView())throw console.error(b.NON_PURE_VIEW_ERROR),console.trace(),new Error(b.NON_PURE_VIEW_ERROR);if(a!==this._value){var c=this._value;this.markStale(),this._value=this.makeReferenceValueReactive(a),this.markReady(!0),this.changeEvent.emit(this._value,c)}},d.prototype.get=function(){return this.notifyObserved(),this._value},d.prototype.observe=function(a,b){return void 0===b&&(b=!1),b&&a(this.get(),void 0),this.changeEvent.on(a)},d.prototype.asPropertyDescriptor=function(){var a=this;return{configurable:!1,enumerable:!0,get:function(){return a.get()},set:function(b){return a.set(b)}}},d.prototype.toString=function(){return"Observable["+this.context.name+":"+this._value+"]"},d}(b.RootDNode);b.ObservableValue=c}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){function c(){throw new Error("View functions do not accept new values")}var d=function(d){function e(a,c,e){d.call(this,e),this.func=a,this.scope=c,this.isComputing=!1,this.hasError=!1,this.changeEvent=new b.SimpleEventEmitter}return __extends(e,d),e.prototype.get=function(){if(this.isComputing)throw new Error("Cycle detected");if(this.isSleeping?b.isComputingView()?(this.wakeUp(),this.notifyObserved()):(this.wakeUp(),this.tryToSleep()):this.notifyObserved(),this.hasCycle)throw new Error("Cycle detected");if(this.hasError)throw a.debugLevel&&(console.trace(),b.warn(this+": rethrowing caught exception to observer: "+this._value+(this._value.cause||""))),this._value;return this._value},e.prototype.set=function(){c()},e.prototype.compute=function(){var a;try{if(this.isComputing)throw new Error("Cycle detected");this.isComputing=!0,a=this.func.call(this.scope),this.hasError=!1}catch(b){this.hasError=!0,console.error(this+"Caught error during computation: ",b),b instanceof Error?a=b:(a=new Error("MobservableComputationError"),a.cause=b)}if(this.isComputing=!1,a!==this._value){var c=this._value;return this._value=a,this.changeEvent.emit(a,c),!0}return!1},e.prototype.observe=function(a,c){var d=this;void 0===c&&(c=!1),this.setRefCount(1),c&&a(this.get(),void 0);var e=this.changeEvent.on(a);return b.once(function(){d.setRefCount(-1),e()})},e.prototype.asPropertyDescriptor=function(){var a=this;return{configurable:!1,enumerable:!1,get:function(){return a.get()},set:c}},e.prototype.toString=function(){return"ComputedObservable["+this.context.name+":"+this._value+"]"},e}(b.ObservingDNode);b.ObservableView=d}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(){function b(b,c){if(this.target=b,this.context=c,b.$mobservable)throw new Error("Illegal state: already an reactive object");c?c.object||(c.object=b):this.context={object:b,name:""},this.keys=new a.ObservableArray([],!1,{object:b,name:this.context.name+"[keys]"}),Object.defineProperty(b,"$mobservable",{enumerable:!1,configurable:!1,value:this})}return b.asReactive=function(a,c){return a.$mobservable?a.$mobservable:new b(a,c)},b.prototype.set=function(a,b,c){-1===this.keys.indexOf(a)?this.defineReactiveProperty(a,b,c):this.target[a]=b},b.prototype.defineReactiveProperty=function(b,c,d){c instanceof a.AsReference&&(c=c.value,d=!1);var e,f={object:this.context.object,name:(this.context.name||"")+"."+b};e="function"==typeof c&&0===c.length&&d?new a.ObservableView(c,this.target,f).asPropertyDescriptor():new a.ObservableValue(c,d,f).asPropertyDescriptor(),Object.defineProperty(this.target,b,e)},b}();a.ObservableObject=b}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){function b(b){console.warn("The use of mobservable.reactiveComponent and mobservable.reactiveMixin is deprecated, please use reactiveComponent from the mobservable-react package");var c=b.prototype||b,d=c.componentWillMount,e=c.componentWillUnmount;return c.componentWillMount=function(){a.reactiveMixin.componentWillMount.apply(this,arguments),d&&d.apply(this,arguments)},c.componentWillUnmount=function(){a.reactiveMixin.componentWillUnmount.apply(this,arguments),e&&e.apply(this,arguments)},c.shouldComponentUpdate||(c.shouldComponentUpdate=a.reactiveMixin.shouldComponentUpdate),b}var c=1;a.reactiveMixin={componentWillMount:function(){var b=(this.displayName||this.constructor.name||"ReactiveComponent")+c++,d=this.render;this.render=function(){var c=this;this._watchDisposer&&this._watchDisposer();var e=a.observeUntilInvalid(function(){return d.call(c)},function(){c.forceUpdate()},{object:this,name:b}),f=e[0],g=e[1],h=e[2];return this.$mobservable=h,this._watchDisposer=g,f}},componentWillUnmount:function(){this._watchDisposer&&this._watchDisposer(),delete this._mobservableDNode},shouldComponentUpdate:function(a,b){if(this.state!==b)return!0;var c,d=Object.keys(this.props);if(d.length!==Object.keys(a).length)return!0;for(var e=d.length-1;c=d[e];e--)if(a[c]!==this.props[c])return!0;return!1}},a.reactiveComponent=b}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(){function a(){}return a.schedule=function(b){a.inBatch<1?b():a.tasks[a.tasks.length]=b},a.runPostBatchActions=function(){for(var b=0;a.tasks.length;)try{for(;b<a.tasks.length;b++)a.tasks[b]();a.tasks=[]}catch(c){console.error("Failed to run scheduled action, the action has been dropped from the queue: "+c,c),a.tasks.splice(0,b+1)}},a.batch=function(b){a.inBatch+=1;try{return b()}finally{0===--a.inBatch&&(a.inBatch+=1,a.runPostBatchActions(),a.inBatch-=1)}},a.inBatch=0,a.tasks=[],a}();a.Scheduler=b}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(){function b(){this.listeners=[]}return b.prototype.emit=function(){var a=this.listeners.slice(),b=a.length;switch(arguments.length){case 0:for(var c=0;b>c;c++)a[c]();break;case 1:for(var d=arguments[0],c=0;b>c;c++)a[c](d);break;default:for(var c=0;b>c;c++)a[c].apply(null,arguments)}},b.prototype.on=function(b){var c=this;return this.listeners.push(b),a.once(function(){var a=c.listeners.indexOf(b);-1!==a&&c.listeners.splice(a,1)})},b.prototype.once=function(a){var b=this.on(function(){b(),a.apply(this,arguments)});return b},b}();a.SimpleEventEmitter=b}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(a){function b(b,c,d){a.call(this,d),this.expr=b,this.onInvalidate=c,this.didEvaluate=!1,this.computeNextState()}return __extends(b,a),b.prototype.compute=function(){return this.didEvaluate?(this.dispose(),this.onInvalidate()):(this.didEvaluate=!0,this.value=this.expr()),!1},b}(a.ObservingDNode);a.WatchedExpression=b}(b=a._||(a._={}))}(mobservable||(mobservable={}));var forCompilerVerificationOnly=mobservable;!function(a,b){"function"==typeof define&&define.amd?define("mobservable",[],function(){return b()}):"object"==typeof exports?module.exports=b():a.mobservable=b()}(this,function(){var a=mobservable.makeReactive;a["default"]=mobservable.makeReactive;for(var b in mobservable)mobservable.hasOwnProperty(b)&&(a[b]=mobservable[b]);return a});
var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},mobservable;!function(a){var b=function(){return this}();b.__mobservableTrackingStack=[];var c;!function(b){function c(){return __mobservableTrackingStack.length}function d(){return __mobservableTrackingStack.length>0}var e=0;!function(a){a[a.STALE=0]="STALE",a[a.PENDING=1]="PENDING",a[a.READY=2]="READY"}(b.DNodeState||(b.DNodeState={}));var f=b.DNodeState,g=function(){function a(a){this.context=a,this.id=++e,this.state=f.READY,this.observers=[],this.isDisposed=!1,this.externalRefenceCount=0,a.name||(a.name="[m#"+this.id+"]")}return a.prototype.setRefCount=function(a){this.externalRefenceCount+=a},a.prototype.addObserver=function(a){this.observers[this.observers.length]=a},a.prototype.removeObserver=function(a){var b=this.observers,c=b.indexOf(a);-1!==c&&b.splice(c,1)},a.prototype.markStale=function(){this.state===f.READY&&(this.state=f.STALE,b.transitionTracker&&b.reportTransition(this,"STALE"),this.notifyObservers())},a.prototype.markReady=function(a){this.state!==f.READY&&(this.state=f.READY,b.transitionTracker&&b.reportTransition(this,"READY",!0,this._value),this.notifyObservers(a))},a.prototype.notifyObservers=function(a){void 0===a&&(a=!1);for(var b=this.observers.slice(),c=b.length,d=0;c>d;d++)b[d].notifyStateChange(this,a)},a.prototype.notifyObserved=function(){var a=__mobservableTrackingStack,b=a.length;if(b>0){var c=a[b-1],d=c.length;c[d-1]!==this&&c[d-2]!==this&&(c[d]=this)}},a.prototype.dispose=function(){if(this.observers.length)throw new Error("Cannot dispose DNode; it is still being observed");this.isDisposed=!0},a.prototype.toString=function(){return"DNode["+this.context.name+", state: "+this.state+", observers: "+this.observers.length+"]"},a}();b.RootDNode=g;var h=function(c){function d(){c.apply(this,arguments),this.isSleeping=!0,this.hasCycle=!1,this.observing=[],this.prevObserving=null,this.dependencyChangeCount=0,this.dependencyStaleCount=0}return __extends(d,c),d.prototype.setRefCount=function(a){var b=this.externalRefenceCount+=a;0===b?this.tryToSleep():b===a&&this.wakeUp()},d.prototype.removeObserver=function(a){c.prototype.removeObserver.call(this,a),this.tryToSleep()},d.prototype.tryToSleep=function(){if(!this.isSleeping&&0===this.observers.length&&0===this.externalRefenceCount){for(var a=0,b=this.observing.length;b>a;a++)this.observing[a].removeObserver(this);this.observing=[],this.isSleeping=!0}},d.prototype.wakeUp=function(){this.isSleeping&&(this.isSleeping=!1,this.state=f.PENDING,this.computeNextState())},d.prototype.notifyStateChange=function(a,c){var d=this;a.state===f.STALE?1===++this.dependencyStaleCount&&this.markStale():(c&&(this.dependencyChangeCount+=1),0===--this.dependencyStaleCount&&(this.state=f.PENDING,b.Scheduler.schedule(function(){d.dependencyChangeCount>0?d.computeNextState():d.markReady(!1),d.dependencyChangeCount=0})))},d.prototype.computeNextState=function(){this.trackDependencies(),b.transitionTracker&&b.reportTransition(this,"PENDING");var a=this.compute();this.bindDependencies(),this.markReady(a)},d.prototype.compute=function(){throw"Abstract!"},d.prototype.trackDependencies=function(){this.prevObserving=this.observing,__mobservableTrackingStack[__mobservableTrackingStack.length]=[]},d.prototype.bindDependencies=function(){this.observing=__mobservableTrackingStack.pop(),0===this.observing.length&&a.logLevel>1&&!this.isDisposed&&console.error("[mobservable] You have created a view function that doesn't observe any values, did you forget to make its dependencies observable?");var c=b.quickDiff(this.observing,this.prevObserving),e=c[0],f=c[1];this.prevObserving=null;for(var g=0,h=f.length;h>g;g++)f[g].removeObserver(this);this.hasCycle=!1;for(var g=0,h=e.length;h>g;g++){var i=e[g];i instanceof d&&i.findCycle(this)?(this.hasCycle=!0,this.observing.splice(this.observing.indexOf(e[g]),1),i.hasCycle=!0):e[g].addObserver(this)}},d.prototype.findCycle=function(a){var b=this.observing;if(-1!==b.indexOf(a))return!0;for(var c=b.length,e=0;c>e;e++)if(b[e]instanceof d&&b[e].findCycle(a))return!0;return!1},d.prototype.dispose=function(){if(this.observing)for(var a=this.observing.length,b=0;a>b;b++)this.observing[b].removeObserver(this);this.observing=null,c.prototype.dispose.call(this)},d}(g);b.ObservingDNode=h,b.stackDepth=c,b.isComputingView=d}(c=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){function b(a,b){if(d(a))return a;b=b||{},a instanceof l.AsReference&&(a=a.value,b.as="reference");var c=b.recurse!==!1,e="reference"===b.as?l.ValueType.Reference:l.getTypeOfValue(a),f={name:b.name,object:b.context||b.scope};switch(e){case l.ValueType.Reference:case l.ValueType.ComplexObject:return l.toGetterSetterFunction(new l.ObservableValue(a,!1,f));case l.ValueType.ComplexFunction:throw new Error("[mobservable:error] Creating reactive functions from functions with multiple arguments is currently not supported, see https://github.com/mweststrate/mobservable/issues/12");case l.ValueType.ViewFunction:return f.name||(f.name=a.name),l.toGetterSetterFunction(new l.ObservableView(a,b.scope||b.context,f));case l.ValueType.Array:return new l.ObservableArray(a,c,f);case l.ValueType.PlainObject:return l.extendReactive({},a,c,f)}throw"Illegal State"}function c(a){return new l.AsReference(a)}function d(a){return null===a||void 0===a?!1:!!a.$mobservable}function e(b,c){var d=new l.ObservableView(b,c,{object:c,name:b.name});d.setRefCount(1);var e=l.once(function(){d.setRefCount(-1)});return a.logLevel>=2&&0===d.observing.length&&console.warn("[mobservable.sideEffect] not a single observable was used inside the side-effect function. Side-effect would be a no-op."),e.$mobservable=d,e}function f(a,b,c){return l.extendReactive(a,b,!0,c)}function g(a,b,c){var d=c?c.value:null;if("function"==typeof d)throw new Error("@observable functions are deprecated. Use @observable (getter) properties instead");if(c&&c.set)throw new Error("@observable properties cannot have a setter.");Object.defineProperty(a,b,{configurable:!0,enumberable:!0,get:function(){return l.ObservableObject.asReactive(this,null).set(b,void 0,!0),this[b]},set:function(a){l.ObservableObject.asReactive(this,null).set(b,a,!0)}})}function h(a){if(!a)return a;if(Array.isArray(a)||a instanceof l.ObservableArray)return a.map(h);if("object"==typeof a&&l.isPlainObject(a)){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=h(a[c]));return b}return a}function i(a){return console.warn("mobservable.toJson is deprecated, use mobservable.toJSON instead"),h(a)}function j(a){return l.Scheduler.batch(a)}function k(a,b,c){console.warn("mobservable.observeUntilInvalid is deprecated and will be removed in 0.7");var d,f=!1,g=e(function(){f?b():(f=!0,d=a())});return[d,g,g.$mobservable]}a.makeReactive=b,a.asReference=c,a.isReactive=d,a.sideEffect=e,a.extendReactive=f,a.observable=g,a.toJSON=h,a.toJson=i,a.transaction=j,a.observeUntilInvalid=k,a.logLevel=1,setTimeout(function(){a.logLevel>0&&console.info("Welcome to mobservable. Current logLevel = "+a.logLevel+". Change mobservable.logLevel according to your needs: 0 = production, 1 = development, 2 = debugging")},1);var l;!function(a){function b(b){return null===b||void 0===b?e.Reference:"function"==typeof b?b.length?e.ComplexFunction:e.ViewFunction:Array.isArray(b)||b instanceof a.ObservableArray?e.Array:"object"==typeof b?a.isPlainObject(b)?e.PlainObject:e.ComplexObject:e.Reference}function c(b,c,d,e){var f=a.ObservableObject.asReactive(b,e);for(var g in c)c.hasOwnProperty(g)&&f.set(g,c[g],d);return b}function d(a){var b=function(b){return arguments.length>0?void a.set(b):a.get()};return b.$mobservable=a,b.observe=function(b,c){return a.observe(b,c)},b.toString=function(){return a.toString()},b}!function(a){a[a.Reference=0]="Reference",a[a.PlainObject=1]="PlainObject",a[a.ComplexObject=2]="ComplexObject",a[a.Array=3]="Array",a[a.ViewFunction=4]="ViewFunction",a[a.ComplexFunction=5]="ComplexFunction"}(a.ValueType||(a.ValueType={}));var e=a.ValueType;a.getTypeOfValue=b,a.extendReactive=c,a.toGetterSetterFunction=d;var f=function(){function a(a){this.value=a}return a}();a.AsReference=f}(l=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){function b(a){var b=!1;return function(){return b?void 0:(b=!0,a.apply(this,arguments))}}function c(){}function d(a){var b=[];return a.forEach(function(a){-1===b.indexOf(a)&&b.push(a)}),b}function e(a){return null!==a&&"object"==typeof a&&Object.getPrototypeOf(a)===Object.prototype}function f(a,b){if(!b||!b.length)return[a,[]];if(!a||!a.length)return[[],b];for(var c=[],d=[],e=0,f=0,g=a.length,h=!1,i=0,j=0,k=b.length,l=!1,m=!1;!m&&!h;){if(!l){if(g>e&&k>i&&a[e]===b[i]){if(e++,i++,e===g&&i===k)return[c,d];continue}f=e,j=i,l=!0}j+=1,f+=1,j>=k&&(m=!0),f>=g&&(h=!0),h||a[f]!==b[i]?m||b[j]!==a[e]||(d.push.apply(d,b.slice(i,j)),i=j+1,e++,l=!1):(c.push.apply(c,a.slice(e,f)),e=f+1,i++,l=!1)}return c.push.apply(c,a.slice(e)),d.push.apply(d,b.slice(i)),[c,d]}a.once=b,a.noop=c,a.unique=d,a.isPlainObject=e,a.quickDiff=f}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){function c(a){var b={enumerable:!1,configurable:!1,set:function(b){if(a<this.$mobservable.values.length){var c=this.$mobservable.values[a];c!==b&&(this.$mobservable.values[a]=b,this.notifyChildUpdate(a,c))}else{if(a!==this.$mobservable.values.length)throw new Error("ObservableArray: Index out of bounds, "+a+" is larger than "+this.values.length);this.push(b)}},get:function(){return a<this.$mobservable.values.length?(this.$mobservable.notifyObserved(),this.$mobservable.values[a]):void 0}};Object.defineProperty(g.prototype,""+a,b),b.enumerable=!0,b.configurable=!0,i[a]=b}function d(a){for(var b=h;a>b;b++)c(b);h=a}var e=function(){function a(){}return a}();e.prototype=[];var f=function(a){function c(c,d,e){a.call(this,e),this.array=c,this.recurse=d,this.values=[],this.changeEvent=new b.SimpleEventEmitter,e.object||(e.object=c)}return __extends(c,a),c}(b.RootDNode);b.ObservableArrayAdministration=f;var g=function(c){function e(a,b,d){c.call(this),Object.defineProperty(this,"$mobservable",{enumerable:!1,configurable:!1,value:new f(this,b,d)}),a&&a.length&&this.replace(a)}return __extends(e,c),Object.defineProperty(e.prototype,"length",{get:function(){return this.$mobservable.notifyObserved(),this.$mobservable.values.length},set:function(a){if(this.assertNotComputing("spliceWithArray"),"number"!=typeof a||0>a)throw new Error("Out of range: "+a);var b=this.$mobservable.values.length;a!==b&&(a>b?this.spliceWithArray(b,0,new Array(a-b)):this.spliceWithArray(a,b-a))},enumerable:!0,configurable:!0}),e.prototype.updateLength=function(a,b){if(0>b)for(var c=a+b;a>c;c++)delete this[c];else if(b>0){a+b>h&&d(a+b);for(var c=a,e=a+b;e>c;c++)Object.defineProperty(this,""+c,i[c])}},e.prototype.spliceWithArray=function(a,b,c){var d=this;this.assertNotComputing("spliceWithArray");var e=this.$mobservable.values.length;if(!(void 0!==c&&0!==c.length||0!==b&&0!==e))return[];void 0===a?a=0:a>e?a=e:0>a&&(a=Math.max(0,e+a)),b=1===arguments.length?e-a:void 0===b||null===b?0:Math.max(0,Math.min(b,e-a)),void 0===c?c=[]:this.$mobservable.recurse&&(c=c.map(function(a){return d.makeReactiveArrayItem(a)}));var f=c.length-b,g=(h=this.$mobservable.values).splice.apply(h,[a,b].concat(c));return this.updateLength(e,f),this.notifySplice(a,g,c),g;var h},e.prototype.makeReactiveArrayItem=function(c){if(a.isReactive(c))return c;if(c instanceof b.AsReference)return c=c.value;var d={object:this.$mobservable.context.object,name:this.$mobservable.context.name+"[x]"};return Array.isArray(c)?new b.ObservableArray(c,!0,d):b.isPlainObject(c)?b.extendReactive({},c,!0,d):c},e.prototype.notifyChildUpdate=function(a,b){this.notifyChanged(),this.$mobservable.changeEvent.emit({object:this,type:"update",index:a,oldValue:b})},e.prototype.notifySplice=function(a,b,c){(0!==b.length||0!==c.length)&&(this.notifyChanged(),this.$mobservable.changeEvent.emit({object:this,type:"splice",index:a,addedCount:c.length,removed:b}))},e.prototype.notifyChanged=function(){this.$mobservable.markStale(),this.$mobservable.markReady(!0)},e.prototype.observe=function(a,b){return void 0===b&&(b=!1),b&&a({object:this,type:"splice",index:0,addedCount:this.$mobservable.values.length,removed:[]}),this.$mobservable.changeEvent.on(a)},e.prototype.clear=function(){return this.splice(0)},e.prototype.replace=function(a){return this.spliceWithArray(0,this.$mobservable.values.length,a)},e.prototype.values=function(){return console.warn("mobservable.array.values is deprecated and will be removed in 0.7, use slice() instead"),this.$mobservable.notifyObserved(),this.$mobservable.values.slice()},e.prototype.toJSON=function(){return this.$mobservable.notifyObserved(),this.$mobservable.values.slice()},e.prototype.clone=function(){return console.warn("mobservable.array.clone is deprecated and will be removed in 0.7"),this.$mobservable.notifyObserved(),new e(this.$mobservable.values,this.$mobservable.recurse,{object:null,name:this.$mobservable.context.name+"[clone]"})},e.prototype.find=function(a,b,c){void 0===c&&(c=0),this.$mobservable.notifyObserved();for(var d=this.$mobservable.values,e=d.length,f=c;e>f;f++)if(a.call(b,d[f],f,this))return d[f];return null},e.prototype.splice=function(a,b){for(var c=[],d=2;d<arguments.length;d++)c[d-2]=arguments[d];switch(this.assertNotComputing("splice"),arguments.length){case 0:return[];case 1:return this.spliceWithArray(a);case 2:return this.spliceWithArray(a,b)}return this.spliceWithArray(a,b,c)},e.prototype.push=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this.assertNotComputing("push"),this.spliceWithArray(this.$mobservable.values.length,0,a),this.$mobservable.values.length},e.prototype.pop=function(){return this.assertNotComputing("pop"),this.splice(Math.max(this.$mobservable.values.length-1,0),1)[0]},e.prototype.shift=function(){return this.assertNotComputing("shift"),this.splice(0,1)[0]},e.prototype.unshift=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this.assertNotComputing("unshift"),this.spliceWithArray(0,0,a),this.$mobservable.values.length},e.prototype.reverse=function(){return this.assertNotComputing("reverse"),this.replace(this.$mobservable.values.reverse())},e.prototype.sort=function(a){return this.assertNotComputing("sort"),this.replace(this.$mobservable.values.sort.apply(this.$mobservable.values,arguments))},e.prototype.remove=function(a){this.assertNotComputing("remove");var b=this.$mobservable.values.indexOf(a);return b>-1?(this.splice(b,1),!0):!1},e.prototype.toString=function(){return"[mobservable.array] "+Array.prototype.toString.apply(this.$mobservable.values,arguments)},e.prototype.toLocaleString=function(){return"[mobservable.array] "+Array.prototype.toLocaleString.apply(this.$mobservable.values,arguments)},e.prototype.concat=function(){throw"Illegal state"},e.prototype.join=function(a){throw"Illegal state"},e.prototype.slice=function(a,b){throw"Illegal state"},e.prototype.indexOf=function(a,b){throw"Illegal state"},e.prototype.lastIndexOf=function(a,b){throw"Illegal state"},e.prototype.every=function(a,b){throw"Illegal state"},e.prototype.some=function(a,b){throw"Illegal state"},e.prototype.forEach=function(a,b){throw"Illegal state"},e.prototype.map=function(a,b){throw"Illegal state"},e.prototype.filter=function(a,b){throw"Illegal state"},e.prototype.reduce=function(a,b){throw"Illegal state"},e.prototype.reduceRight=function(a,b){throw"Illegal state"},e.prototype.assertNotComputing=function(a){b.isComputingView()&&console.error("mobservable.array: The method array."+a+" is not allowed to be used inside reactive views since it alters the state.")},e}(e);b.ObservableArray=g,["concat","join","slice","indexOf","lastIndexOf","every","some","forEach","map","filter","reduce","reduceRight"].forEach(function(a){var b=Array.prototype[a];g.prototype[a]=function(){return this.$mobservable.notifyObserved(),b.apply(this.$mobservable.values,arguments)}});var h=0,i=[];d(1e3)}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){function c(c,d){if(!a.isReactive(c))throw new Error("[mobservable.getDNode] "+c+" doesn't seem to be reactive");if(void 0!==d){__mobservableTrackingStack.push([]);try{c[d]}finally{var e=__mobservableTrackingStack.pop()[0];if(!e)throw new Error("[mobservable.getDNode] property '"+d+"' of '"+c+"' doesn't seem to be a reactive property");return e}}if(c.$mobservable){if(c.$mobservable instanceof b.ObservableObject)throw new Error("[mobservable.getDNode] missing properties parameter. Please specify a property of '"+c+"'.");return c.$mobservable}throw new Error("[mobservable.getDNode] "+c+" doesn't seem to be reactive")}function d(a,c,d,e){void 0===d&&(d=!1),void 0===e&&(e=null),b.transitionTracker.emit({id:a.id,name:a.context.name,context:a.context.object,state:c,changed:d,newValue:e})}b.getDNode=c,b.reportTransition=d,b.transitionTracker=null}(b=a._||(a._={}));var c;!function(a){function c(a,c){return d(b.getDNode(a,c))}function d(a){var c={id:a.id,name:a.context.name,context:a.context.object||null};return a instanceof b.ObservingDNode&&a.observing.length&&(c.dependencies=b.unique(a.observing).map(d)),c}function e(a,c){return f(b.getDNode(a,c))}function f(a){var c={id:a.id,name:a.context.name,context:a.context.object||null};return a.observers.length&&(c.observers=b.unique(a.observers).map(f)),a.externalRefenceCount>0&&(c.listeners=a.externalRefenceCount),c}function g(a){var b=[],c=!1;return function(d){(a||d.changed)&&b.push(d),c||(c=!0,setTimeout(function(){console[console.table?"table":"dir"](b),b=[],c=!1},1))}}function h(a,c){void 0===a&&(a=!1),b.transitionTracker||(b.transitionTracker=new b.SimpleEventEmitter);var d=c?function(b){(a||b.changed)&&c(b)}:g(a),e=b.transitionTracker.on(d);return b.once(function(){e(),0===b.transitionTracker.listeners.length&&(b.transitionTracker=null)})}a.getDependencyTree=c,a.getObserverTree=e,a.trackTransitions=h}(c=a.extras||(a.extras={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){b.NON_PURE_VIEW_ERROR="[mobservable] It is not allowed to change the state during the computation of a reactive view.";var c=function(c){function d(a,d,e){c.call(this,e),this.value=a,this.recurse=d,this.changeEvent=new b.SimpleEventEmitter,this._value=this.makeReferenceValueReactive(a)}return __extends(d,c),d.prototype.makeReferenceValueReactive=function(c){return this.recurse&&(Array.isArray(c)||b.isPlainObject(c))?a.makeReactive(c,{context:this.context.object,name:this.context.name}):c},d.prototype.set=function(a){if(b.isComputingView()&&console.error(b.NON_PURE_VIEW_ERROR+(" (stack size is "+__mobservableTrackingStack.length+")")),a!==this._value){var c=this._value;this.markStale(),this._value=this.makeReferenceValueReactive(a),this.markReady(!0),this.changeEvent.emit(this._value,c)}},d.prototype.get=function(){return this.notifyObserved(),this._value},d.prototype.observe=function(a,b){return void 0===b&&(b=!1),b&&a(this.get(),void 0),this.changeEvent.on(a)},d.prototype.asPropertyDescriptor=function(){var a=this;return{configurable:!1,enumerable:!0,get:function(){return a.get()},set:function(b){return a.set(b)}}},d.prototype.toString=function(){return"Observable["+this.context.name+":"+this._value+"]"},d}(b.RootDNode);b.ObservableValue=c}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){function c(){throw new Error("View functions do not accept new values")}var d=function(d){function e(a,c,e){d.call(this,e),this.func=a,this.scope=c,this.isComputing=!1,this.hasError=!1,this.changeEvent=new b.SimpleEventEmitter}return __extends(e,d),e.prototype.get=function(){if(this.isComputing)throw new Error("Cycle detected");if(this.isSleeping?b.isComputingView()?(this.wakeUp(),this.notifyObserved()):(this.wakeUp(),this.tryToSleep()):this.notifyObserved(),this.hasCycle)throw new Error("Cycle detected");if(this.hasError)throw a.logLevel>0&&console.error(this+": rethrowing caught exception to observer: "+this._value+(this._value.cause||"")),this._value;return this._value},e.prototype.set=function(){c()},e.prototype.compute=function(){var a;try{if(this.isComputing)throw new Error("[mobservable] Cycle detected");this.isComputing=!0,a=this.func.call(this.scope),this.hasError=!1}catch(b){this.hasError=!0,console.error("[mobservable] Caught error during computation: ",b),b instanceof Error?a=b:(a=new Error("MobservableComputationError"),a.cause=b)}if(this.isComputing=!1,a!==this._value){var c=this._value;return this._value=a,this.changeEvent.emit(a,c),!0}return!1},e.prototype.observe=function(a,c){var d=this;void 0===c&&(c=!1),this.setRefCount(1),c&&a(this.get(),void 0);var e=this.changeEvent.on(a);return b.once(function(){d.setRefCount(-1),e()})},e.prototype.asPropertyDescriptor=function(){var a=this;return{configurable:!1,enumerable:!1,get:function(){return a.get()},set:c}},e.prototype.toString=function(){return"ComputedObservable["+this.context.name+":"+this._value+"]"},e}(b.ObservingDNode);b.ObservableView=d}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(){function b(b,c){if(this.target=b,this.context=c,b.$mobservable)throw new Error("Illegal state: already an reactive object");c?c.object||(c.object=b):this.context={object:b,name:""},this.keys=new a.ObservableArray([],!1,{object:b,name:this.context.name+"[keys]"}),Object.defineProperty(b,"$mobservable",{enumerable:!1,configurable:!1,value:this})}return b.asReactive=function(a,c){return a.$mobservable?a.$mobservable:new b(a,c)},b.prototype.set=function(a,b,c){-1===this.keys.indexOf(a)?this.defineReactiveProperty(a,b,c):this.target[a]=b},b.prototype.defineReactiveProperty=function(b,c,d){c instanceof a.AsReference&&(c=c.value,d=!1);var e,f={object:this.context.object,name:(this.context.name||"")+"."+b};e="function"==typeof c&&0===c.length&&d?new a.ObservableView(c,this.target,f).asPropertyDescriptor():new a.ObservableValue(c,d,f).asPropertyDescriptor(),Object.defineProperty(this.target,b,e)},b}();a.ObservableObject=b}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){function b(b){console.warn("The use of mobservable.reactiveComponent and mobservable.reactiveMixin is deprecated, please use reactiveComponent from the mobservable-react package");var c=b.prototype||b,d=c.componentWillMount,e=c.componentWillUnmount;return c.componentWillMount=function(){a.reactiveMixin.componentWillMount.apply(this,arguments),d&&d.apply(this,arguments)},c.componentWillUnmount=function(){a.reactiveMixin.componentWillUnmount.apply(this,arguments),e&&e.apply(this,arguments)},c.shouldComponentUpdate||(c.shouldComponentUpdate=a.reactiveMixin.shouldComponentUpdate),b}var c=1;a.reactiveMixin={componentWillMount:function(){var b=(this.displayName||this.constructor.name||"ReactiveComponent")+c++,d=this.render;this.render=function(){var c=this;this._watchDisposer&&this._watchDisposer();var e=a.observeUntilInvalid(function(){return d.call(c)},function(){c.forceUpdate()},{object:this,name:b}),f=e[0],g=e[1],h=e[2];return this.$mobservable=h,this._watchDisposer=g,f}},componentWillUnmount:function(){this._watchDisposer&&this._watchDisposer(),delete this._mobservableDNode},shouldComponentUpdate:function(a,b){if(this.state!==b)return!0;var c,d=Object.keys(this.props);if(d.length!==Object.keys(a).length)return!0;for(var e=d.length-1;c=d[e];e--)if(a[c]!==this.props[c])return!0;return!1}},a.reactiveComponent=b}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(){function a(){}return a.schedule=function(b){a.inBatch<1?b():a.tasks[a.tasks.length]=b},a.runPostBatchActions=function(){for(var b=0;a.tasks.length;)try{for(;b<a.tasks.length;b++)a.tasks[b]();a.tasks=[]}catch(c){console.error("Failed to run scheduled action, the action has been dropped from the queue: "+c,c),a.tasks.splice(0,b+1)}},a.batch=function(b){a.inBatch+=1;try{return b()}finally{0===--a.inBatch&&(a.inBatch+=1,a.runPostBatchActions(),a.inBatch-=1)}},a.inBatch=0,a.tasks=[],a}();a.Scheduler=b}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(){function b(){this.listeners=[]}return b.prototype.emit=function(){var a=this.listeners.slice(),b=a.length;switch(arguments.length){case 0:for(var c=0;b>c;c++)a[c]();break;case 1:for(var d=arguments[0],c=0;b>c;c++)a[c](d);break;default:for(var c=0;b>c;c++)a[c].apply(null,arguments)}},b.prototype.on=function(b){var c=this;return this.listeners.push(b),a.once(function(){var a=c.listeners.indexOf(b);-1!==a&&c.listeners.splice(a,1)})},b.prototype.once=function(a){var b=this.on(function(){b(),a.apply(this,arguments)});return b},b}();a.SimpleEventEmitter=b}(b=a._||(a._={}))}(mobservable||(mobservable={}));var forCompilerVerificationOnly=mobservable;!function(a,b){"function"==typeof define&&define.amd?define("mobservable",[],function(){return b()}):"object"==typeof exports?module.exports=b():a.mobservable=b()}(this,function(){var a=mobservable.makeReactive;a["default"]=mobservable.makeReactive;for(var b in mobservable)mobservable.hasOwnProperty(b)&&(a[b]=mobservable[b]);return a});
{
"name": "mobservable",
"version": "0.6.5",
"version": "0.6.6",
"description": "Keeps views automatically in sync with state. Unobtrusively.",

@@ -5,0 +5,0 @@ "main": "dist/mobservable.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc