Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.5.9 to 0.5.10

dist/mobservable.d.ts

1791

dist/mobservable.js
/**
* mobservable
* (c) 2015 - Michel Weststrate
* https://github.com/mweststrate/mobservable
* https://mweststrate.github.io/mobservable
*/
var mobservable;
(function (mobservable) {
var _;
(function (_) {
var ObservableValue = (function () {
function ObservableValue(value, recurse) {
this.value = value;
this.recurse = recurse;
this.changeEvent = new _.SimpleEventEmitter();
this.dependencyState = new _.DNode(this);
this._value = this.makeReferenceValueReactive(value);
}
ObservableValue.prototype.makeReferenceValueReactive = function (value) {
if (this.recurse && (Array.isArray(value) || _.isPlainObject(value)))
return mobservable.makeReactive(value);
return value;
};
ObservableValue.prototype.set = function (value) {
if (value !== this._value) {
var oldValue = this._value;
this.dependencyState.markStale();
this._value = this.makeReferenceValueReactive(value);
this.dependencyState.markReady(true);
this.changeEvent.emit(this._value, oldValue);
}
};
ObservableValue.prototype.get = function () {
this.dependencyState.notifyObserved();
return this._value;
};
ObservableValue.prototype.observe = function (listener, fireImmediately) {
var _this = this;
if (fireImmediately === void 0) { fireImmediately = false; }
this.dependencyState.setRefCount(+1);
if (fireImmediately)
listener(this.get(), undefined);
var disposer = this.changeEvent.on(listener);
return _.once(function () {
_this.dependencyState.setRefCount(-1);
disposer();
});
};
ObservableValue.prototype.createGetterSetter = function () {
var self = this;
var f = function (value) {
if (arguments.length > 0)
self.set(value);
else
return self.get();
};
f.impl = this;
f.observe = function (listener, fire) {
return self.observe(listener, fire);
};
f.toString = function () {
return self.toString();
};
_.markReactive(f);
return f;
};
ObservableValue.prototype.toString = function () {
return "Observable[" + this._value + "]";
};
return ObservableValue;
})();
_.ObservableValue = ObservableValue;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
/// <reference path="./observablevalue" />
var __extends = (this && this.__extends) || function (d, b) {

@@ -14,93 +83,431 @@ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];

(function (mobservable) {
function createObservable(value, scope) {
if (Array.isArray(value))
return new ObservableArray(value);
var _;
(function (_1) {
var ComputedObservable = (function (_super) {
__extends(ComputedObservable, _super);
function ComputedObservable(func, scope) {
_super.call(this, undefined, false);
this.func = func;
this.scope = scope;
this.isComputing = false;
this.hasError = false;
if (typeof func !== "function")
throw new Error("ComputedObservable requires a function");
}
ComputedObservable.prototype.get = function () {
if (this.isComputing)
throw new Error("Cycle detected");
var state = this.dependencyState;
if (state.isSleeping) {
if (_1.DNode.trackingStack.length > 0) {
state.wakeUp();
state.notifyObserved();
}
else {
this.compute();
}
}
else {
state.notifyObserved();
}
if (state.hasCycle)
throw new Error("Cycle detected");
if (this.hasError) {
if (mobservable.debugLevel) {
console.trace();
_1.warn(this + ": rethrowing caught exception to observer: " + this._value + (this._value.cause || ''));
}
throw this._value;
}
return this._value;
};
ComputedObservable.prototype.set = function (_) {
throw new Error(this.toString() + ": A computed observable does not accept new values!");
};
ComputedObservable.prototype.compute = function () {
var newValue;
try {
if (this.isComputing)
throw new Error("Cycle detected");
this.isComputing = true;
newValue = this.func.call(this.scope);
this.hasError = false;
}
catch (e) {
this.hasError = true;
console.error(this + "Caught error during computation: ", e);
if (e instanceof Error)
newValue = e;
else {
newValue = new Error("MobservableComputationError");
newValue.cause = e;
}
}
this.isComputing = false;
if (newValue !== this._value) {
var oldValue = this._value;
this._value = newValue;
this.changeEvent.emit(newValue, oldValue);
return true;
}
return false;
};
ComputedObservable.prototype.toString = function () {
return "ComputedObservable[" + this.func.toString() + "]";
};
return ComputedObservable;
})(_1.ObservableValue);
_1.ComputedObservable = ComputedObservable;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
var mobservable;
(function (mobservable) {
var _;
(function (_) {
(function (DNodeState) {
DNodeState[DNodeState["STALE"] = 0] = "STALE";
DNodeState[DNodeState["PENDING"] = 1] = "PENDING";
DNodeState[DNodeState["READY"] = 2] = "READY";
})(_.DNodeState || (_.DNodeState = {}));
var DNodeState = _.DNodeState;
;
var DNode = (function () {
function DNode(owner) {
this.owner = owner;
this.state = DNodeState.READY;
this.isSleeping = true;
this.hasCycle = false;
this.observing = [];
this.prevObserving = null;
this.observers = [];
this.dependencyChangeCount = 0;
this.dependencyStaleCount = 0;
this.isDisposed = false;
this.externalRefenceCount = 0;
this.isComputed = owner.compute !== undefined;
}
;
DNode.prototype.setRefCount = function (delta) {
var rc = this.externalRefenceCount += delta;
if (rc === 0)
this.tryToSleep();
else if (rc === delta)
this.wakeUp();
};
DNode.prototype.addObserver = function (node) {
this.observers[this.observers.length] = node;
};
DNode.prototype.removeObserver = function (node) {
var obs = this.observers, idx = obs.indexOf(node);
if (idx !== -1) {
obs.splice(idx, 1);
if (obs.length === 0)
this.tryToSleep();
}
};
DNode.prototype.markStale = function () {
if (this.state !== DNodeState.READY)
return;
this.state = DNodeState.STALE;
this.notifyObservers();
};
DNode.prototype.markReady = function (stateDidActuallyChange) {
if (this.state === DNodeState.READY)
return;
this.state = DNodeState.READY;
this.notifyObservers(stateDidActuallyChange);
};
DNode.prototype.notifyObservers = function (stateDidActuallyChange) {
if (stateDidActuallyChange === void 0) { stateDidActuallyChange = false; }
var os = this.observers.slice();
for (var l = os.length, i = 0; i < l; i++)
os[i].notifyStateChange(this, stateDidActuallyChange);
};
DNode.prototype.tryToSleep = function () {
if (!this.isSleeping && this.isComputed && this.observers.length === 0 && this.externalRefenceCount === 0) {
for (var i = 0, l = this.observing.length; i < l; i++)
this.observing[i].removeObserver(this);
this.observing = [];
this.isSleeping = true;
}
};
DNode.prototype.wakeUp = function () {
if (this.isSleeping && this.isComputed) {
this.isSleeping = false;
this.state = DNodeState.PENDING;
this.computeNextState();
}
};
DNode.prototype.notifyStateChange = function (observable, stateDidActuallyChange) {
var _this = this;
if (observable.state === DNodeState.STALE) {
if (++this.dependencyStaleCount === 1)
this.markStale();
}
else {
if (stateDidActuallyChange)
this.dependencyChangeCount += 1;
if (--this.dependencyStaleCount === 0) {
this.state = DNodeState.PENDING;
_.Scheduler.schedule(function () {
if (_this.dependencyChangeCount > 0)
_this.computeNextState();
else
_this.markReady(false);
_this.dependencyChangeCount = 0;
});
}
}
};
DNode.prototype.computeNextState = function () {
this.trackDependencies();
var stateDidChange = this.owner.compute();
this.bindDependencies();
this.markReady(stateDidChange);
};
DNode.prototype.trackDependencies = function () {
this.prevObserving = this.observing;
DNode.trackingStack[DNode.trackingStack.length] = [];
};
DNode.prototype.bindDependencies = function () {
this.observing = DNode.trackingStack.pop();
if (this.isComputed && 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?");
}
var _a = _.quickDiff(this.observing, this.prevObserving), added = _a[0], removed = _a[1];
this.prevObserving = null;
for (var i = 0, l = removed.length; i < l; i++)
removed[i].removeObserver(this);
this.hasCycle = false;
for (var i = 0, l = added.length; i < l; i++) {
if (this.isComputed && added[i].findCycle(this)) {
this.hasCycle = true;
this.observing.splice(this.observing.indexOf(added[i]), 1);
added[i].hasCycle = true;
}
else {
added[i].addObserver(this);
}
}
};
DNode.prototype.notifyObserved = function () {
var ts = DNode.trackingStack, l = ts.length;
if (l > 0) {
var cs = ts[l - 1], csl = cs.length;
if (cs[csl - 1] !== this && cs[csl - 2] !== this)
cs[csl] = this;
}
};
DNode.prototype.findCycle = function (node) {
var obs = this.observing;
if (obs.indexOf(node) !== -1)
return true;
for (var l = obs.length, i = 0; i < l; i++)
if (obs[i].findCycle(node))
return true;
return false;
};
DNode.prototype.dispose = function () {
if (this.observers.length)
throw new Error("Cannot dispose DNode; it is still being observed");
if (this.observing)
for (var l = this.observing.length, i = 0; i < l; i++)
this.observing[i].removeObserver(this);
this.observing = null;
this.isDisposed = true;
};
DNode.trackingStack = [];
return DNode;
})();
_.DNode = DNode;
function stackDepth() {
return DNode.trackingStack.length;
}
_.stackDepth = stackDepth;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
/**
* mobservable
* (c) 2015 - Michel Weststrate
* https://github.com/mweststrate/mobservable
*/
var mobservable;
(function (mobservable) {
var ValueType;
(function (ValueType) {
ValueType[ValueType["Reference"] = 0] = "Reference";
ValueType[ValueType["PlainObject"] = 1] = "PlainObject";
ValueType[ValueType["ComplexObject"] = 2] = "ComplexObject";
ValueType[ValueType["Array"] = 3] = "Array";
ValueType[ValueType["ViewFunction"] = 4] = "ViewFunction";
ValueType[ValueType["ComplexFunction"] = 5] = "ComplexFunction";
})(ValueType || (ValueType = {}));
function makeReactive(value, opts) {
if (isReactive(value))
return value;
opts = opts || {};
if (value instanceof _.AsReference) {
value = value.value;
opts.as = "reference";
}
var recurse = opts.recurse !== false;
var sourceType = opts.as === "reference" ? ValueType.Reference : getTypeOfValue(value);
switch (sourceType) {
case ValueType.Reference:
case ValueType.ComplexObject:
return _.makeReactiveReference(value, false);
case 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 ValueType.ViewFunction:
return new _.ComputedObservable(value, opts.scope).createGetterSetter();
case ValueType.Array:
return new _.ObservableArray(value, recurse);
case ValueType.PlainObject:
return _.makeReactiveObject({}, value, recurse);
}
throw "Illegal State";
}
mobservable.makeReactive = makeReactive;
function getTypeOfValue(value) {
if (value === null || value === undefined)
return ValueType.Reference;
if (typeof value === "function")
return mobservable.m.computed(value, scope);
return mobservable.m.primitive(value);
return value.length ? ValueType.ComplexFunction : ValueType.ViewFunction;
if (Array.isArray(value) || value instanceof _.ObservableArray)
return ValueType.Array;
if (typeof value == 'object')
return _.isPlainObject(value) ? ValueType.PlainObject : ValueType.ComplexObject;
return ValueType.Reference;
}
mobservable.m = function (value, scope) {
return createObservable(value, scope);
};
mobservable.m.value = createObservable;
mobservable.m.primitive = mobservable.m.reference = function (value) {
return new ObservableValue(value).createGetterSetter();
};
mobservable.m.computed = function (func, scope) {
return new ComputedObservable(func, scope).createGetterSetter();
};
mobservable.m.expr = function (expr, scope) {
if (DNode.trackingStack.length === 0)
throw new Error("mobservable.expr can only be used inside a computed observable. Probably mobservable.computed should be used instead of .expr");
return new ComputedObservable(expr, scope).get();
};
mobservable.m.sideEffect = function (func, scope) {
return mobservable.m.computed(func, scope).observe(noop);
};
mobservable.m.array = function array(values) {
return new ObservableArray(values);
};
mobservable.m.props = function props(target, props, value) {
switch (arguments.length) {
case 0:
throw new Error("Not enough arguments");
case 1:
return mobservable.m.props(target, target);
case 2:
for (var key in props)
mobservable.m.props(target, key, props[key]);
break;
case 3:
var isArray = Array.isArray(value);
var observable = mobservable.m.value(value, target);
Object.defineProperty(target, props, {
get: isArray
? function () { return observable; }
: observable,
set: isArray
? function (newValue) { observable.replace(newValue); }
: observable,
enumerable: true,
configurable: false
});
break;
function asReference(value) {
return new _.AsReference(value);
}
mobservable.asReference = asReference;
var _;
(function (_) {
var deprecations = [];
function deprecated(name) {
if (deprecations.indexOf(name) === -1) {
deprecations.push(name);
console.warn("The method '" + name + "' has been deprecated, for any questions or suggestions, see: https://github.com/mweststrate/mobservable/issues/11");
console.trace();
}
}
return target;
};
mobservable.m.fromJson = function fromJson(source) {
function convertValue(value) {
if (!value)
_.deprecated = deprecated;
function wrapDeprecated(name, func) {
return function () {
deprecated(name);
return func.apply(null, arguments);
};
}
_.wrapDeprecated = wrapDeprecated;
function makeReactiveObject(target, properties, recurse) {
markReactive(target);
for (var key in properties)
makeReactiveObjectProperty(target, key, properties[key], recurse);
return target;
}
_.makeReactiveObject = makeReactiveObject;
function makeReactiveObjectProperty(target, name, value, recurse) {
var type;
if (value instanceof AsReference) {
value = value.value;
type = ValueType.Reference;
recurse = false;
}
else {
type = getTypeOfValue(value);
}
var observable;
switch (type) {
case ValueType.Reference:
case ValueType.ComplexObject:
observable = makeReactiveReference(value, false);
break;
case ValueType.ViewFunction:
observable = new _.ComputedObservable(value, target).createGetterSetter();
break;
case ValueType.ComplexFunction:
_.warn("Storing reactive functions in objects is not supported yet, please use flag 'recurse:false' or wrap the function in 'asReference'");
observable = makeReactiveReference(value, false);
case ValueType.Array:
case ValueType.PlainObject:
observable = makeReactiveReference(value, recurse);
default: "Illegal state";
}
Object.defineProperty(target, name, {
get: observable,
set: observable,
enumerable: true,
configurable: false
});
return target;
}
_.makeReactiveObjectProperty = makeReactiveObjectProperty;
function makeReactiveArrayItem(value) {
if (isReactive(value))
return value;
if (typeof value === "object")
return fromJson(value);
return value;
if (value instanceof AsReference)
return value = value.value;
switch (getTypeOfValue(value)) {
case ValueType.Reference:
case ValueType.ComplexObject:
return value;
case ValueType.ViewFunction:
case ValueType.ComplexFunction:
_.warn("Storing reactive functions in arrays is not supported, please use flag 'recurse:false' or wrap the function in 'asReference'");
return value;
case ValueType.Array:
return new _.ObservableArray(value, true);
case ValueType.PlainObject:
return _.makeReactiveObject({}, value, true);
}
throw "Illegal State";
}
if (source) {
if (Array.isArray(source))
return mobservable.m.array(source.map(convertValue));
if (typeof source === "object") {
var props = {};
for (var key in source)
if (source.hasOwnProperty(key))
props[key] = convertValue(source[key]);
return mobservable.m.props(props);
_.makeReactiveArrayItem = makeReactiveArrayItem;
function makeReactiveReference(value, recurse) {
return new _.ObservableValue(value, recurse).createGetterSetter();
}
_.makeReactiveReference = makeReactiveReference;
function markReactive(value) {
Object.defineProperty(value, "__isReactive", {
enumerable: false,
value: true
});
}
_.markReactive = markReactive;
var AsReference = (function () {
function AsReference(value) {
this.value = value;
}
return AsReference;
})();
_.AsReference = AsReference;
})(_ = mobservable._ || (mobservable._ = {}));
function isReactive(value) {
if (value === null || value === undefined)
return false;
switch (typeof value) {
case "array":
case "object":
case "function":
return value.__isReactive === true;
}
throw new Error("mobservable.fromJson expects object or array, got: '" + source + "'");
};
mobservable.m.toJson = function toJson(source) {
if (!source)
return source;
if (Array.isArray(source) || source instanceof ObservableArray)
return source.map(toJson);
if (typeof source === "object") {
var res = {};
for (var key in source)
if (source.hasOwnProperty(key))
res[key] = toJson(source[key]);
return res;
}
return source;
};
mobservable.m.observable = function observable(target, key, descriptor) {
return false;
}
mobservable.isReactive = isReactive;
function sideEffect(func, scope) {
var observable = new _.ComputedObservable(func, scope);
var disposer = observable.observe(_.noop);
if (observable.dependencyState.observing.length === 0)
_.warn("mobservable.sideEffect: not a single observable was used inside the side-effect function. Side-effect would be a no-op.");
return disposer;
}
mobservable.sideEffect = sideEffect;
function defineReactiveProperties(target, properties) {
_.makeReactiveObject(target, properties, true);
}
mobservable.defineReactiveProperties = defineReactiveProperties;
function observable(target, key, descriptor) {
var baseValue = descriptor ? descriptor.value : null;

@@ -112,3 +519,3 @@ if (typeof baseValue === "function") {

descriptor.get = function () {
var observable = this.key = mobservable.m.computed(baseValue, this);
var observable = this.key = new _.ComputedObservable(baseValue, this).createGetterSetter();
return observable;

@@ -125,21 +532,93 @@ };

get: function () {
mobservable.m.props(this, key, undefined);
_.makeReactiveObjectProperty(this, key, undefined, true);
return this[key];
},
set: function (value) {
mobservable.m.props(this, key, value);
_.makeReactiveObjectProperty(this, key, value, true);
}
});
}
};
mobservable.m.toPlainValue = function toPlainValue(value) {
}
mobservable.observable = observable;
function toJson(source) {
if (!source)
return source;
if (Array.isArray(source) || source instanceof _.ObservableArray)
return source.map(toJson);
if (typeof source === "object") {
var res = {};
for (var key in source)
if (source.hasOwnProperty(key))
res[key] = toJson(source[key]);
return res;
}
return source;
}
mobservable.toJson = toJson;
function transaction(action) {
return _.Scheduler.batch(action);
}
mobservable.transaction = transaction;
function observeUntilInvalid(func, onInvalidate) {
var watch = new _.WatchedExpression(func, onInvalidate);
return [watch.value, function () { return watch.dispose(); }];
}
mobservable.observeUntilInvalid = observeUntilInvalid;
mobservable.watch = _.wrapDeprecated("watch", observeUntilInvalid);
mobservable.batch = _.wrapDeprecated("batch", transaction);
function value(value, scope) {
_.deprecated("value");
return makeReactive(value, { scope: scope });
}
mobservable.value = value;
function reference(value) {
_.deprecated("reference");
return makeReactive(value, { as: "reference" });
}
mobservable.reference = reference;
mobservable.primitive = _.wrapDeprecated("primitive", reference);
function computed(func, scope) {
_.deprecated("computed");
return makeReactive(func, { scope: scope });
}
mobservable.computed = computed;
function expr(expr, scope) {
_.deprecated("expr");
if (_.DNode.trackingStack.length === 0)
throw new Error("mobservable.expr can only be used inside a computed observable. Probably mobservable.computed should be used instead of .expr");
return new _.ComputedObservable(expr, scope).get();
}
mobservable.expr = expr;
function array(values) {
_.deprecated("array");
return new _.ObservableArray(values, false);
}
mobservable.array = array;
function props(target, properties, initialValue) {
_.deprecated("props");
switch (arguments.length) {
case 1: return _.makeReactiveObject(target, target, false);
case 2: return _.makeReactiveObject(target, properties, false);
case 3: return _.makeReactiveObject(target, (_a = {}, _a[properties] = initialValue, _a), false);
}
throw "Illegal invocation";
var _a;
}
mobservable.props = props;
function fromJson(source) {
_.deprecated("fromJson");
return makeReactive(source);
}
mobservable.fromJson = fromJson;
function toPlainValue(value) {
_.deprecated("toPlainValue");
if (value) {
if (value instanceof Array)
return value.slice();
else if (value instanceof ObservableValue)
else if (value instanceof _.ObservableValue)
return value.get();
else if (typeof value === "function" && value.impl) {
if (value.impl instanceof ObservableValue)
if (value.impl instanceof _.ObservableValue)
return value();
else if (value.impl instanceof ObservableArray)
else if (value.impl instanceof _.ObservableArray)
return value().slice();

@@ -155,5 +634,7 @@ }

return value;
};
mobservable.m.observeProperty = function observeProperty(object, key, listener, invokeImmediately) {
}
mobservable.toPlainValue = toPlainValue;
function observeProperty(object, key, listener, invokeImmediately) {
if (invokeImmediately === void 0) { invokeImmediately = false; }
_.deprecated("observeProperty");
if (!object)

@@ -165,531 +646,241 @@ throw new Error("Cannot observe property of '" + object + "'");

throw new Error("Third argument to mobservable.observeProperty should be a function");
var observer = new ComputedObservable((function () { return object[key]; }), object);
return sideEffect(function () {
listener(object[key]);
});
var observer = new _.ComputedObservable((function () { return object[key]; }), object);
var disposer = observer.observe(listener, invokeImmediately);
if (observer.dependencyState.observing.length === 0)
throw new Error("mobservable.observeProperty: property '" + key + "' of '" + object + " doesn't seem to be observable. Did you define it as observable using @observable or mobservable.props? You might try to use the .observe() method instead.");
return once(function () {
return _.once(function () {
disposer();
observer.dependencyState.dispose();
});
};
mobservable.m.watch = function watch(func, onInvalidate) {
var watch = new WatchedExpression(func, onInvalidate);
return [watch.value, function () { return watch.dispose(); }];
};
mobservable.m.batch = function batch(action) {
return Scheduler.batch(action);
};
mobservable.m.debugLevel = 0;
var ObservableValue = (function () {
function ObservableValue(_value) {
this._value = _value;
this.changeEvent = new SimpleEventEmitter();
this.dependencyState = new DNode(this);
}
ObservableValue.prototype.set = function (value) {
if (value !== this._value) {
var oldValue = this._value;
this.dependencyState.markStale();
this._value = value;
this.dependencyState.markReady(true);
this.changeEvent.emit(value, oldValue);
}
mobservable.observeProperty = observeProperty;
mobservable.debugLevel = 0;
})(mobservable || (mobservable = {}));
var mobservable;
(function (mobservable) {
var _;
(function (_) {
var StubArray = (function () {
function StubArray() {
}
};
ObservableValue.prototype.get = function () {
this.dependencyState.notifyObserved();
return this._value;
};
ObservableValue.prototype.observe = function (listener, fireImmediately) {
var _this = this;
if (fireImmediately === void 0) { fireImmediately = false; }
this.dependencyState.setRefCount(+1);
if (fireImmediately)
listener(this.get(), undefined);
var disposer = this.changeEvent.on(listener);
return once(function () {
_this.dependencyState.setRefCount(-1);
disposer();
return StubArray;
})();
StubArray.prototype = [];
var ObservableArray = (function (_super) {
__extends(ObservableArray, _super);
function ObservableArray(initialValues, recurse) {
_super.call(this);
_.markReactive(this);
Object.defineProperties(this, {
"recurse": { enumerable: false, value: recurse },
"dependencyState": { enumerable: false, value: new _.DNode(this) },
"_values": {
enumerable: false,
value: initialValues
? (recurse
? initialValues.map(_.makeReactiveArrayItem)
: initialValues.slice())
: [] },
"changeEvent": { enumerable: false, value: new _.SimpleEventEmitter() }
});
if (initialValues && initialValues.length)
this.updateLength(0, initialValues.length);
}
Object.defineProperty(ObservableArray.prototype, "length", {
get: function () {
this.dependencyState.notifyObserved();
return this._values.length;
},
set: function (newLength) {
if (typeof newLength !== "number" || newLength < 0)
throw new Error("Out of range: " + newLength);
var currentLength = this._values.length;
if (newLength === currentLength)
return;
else if (newLength > currentLength)
this.spliceWithArray(currentLength, 0, new Array(newLength - currentLength));
else
this.spliceWithArray(newLength, currentLength - newLength);
},
enumerable: true,
configurable: true
});
};
ObservableValue.prototype.createGetterSetter = function () {
var self = this;
var f = function (value) {
if (arguments.length > 0)
self.set(value);
ObservableArray.prototype.updateLength = function (oldLength, delta) {
if (delta < 0)
for (var i = oldLength + delta; i < oldLength; i++)
delete this[i];
else if (delta > 0) {
if (oldLength + delta > OBSERVABLE_ARRAY_BUFFER_SIZE)
reserveArrayBuffer(oldLength + delta);
for (var i = oldLength, end = oldLength + delta; i < end; i++)
Object.defineProperty(this, "" + i, ENUMERABLE_PROPS[i]);
}
};
ObservableArray.prototype.spliceWithArray = function (index, deleteCount, newItems) {
var length = this._values.length;
if ((newItems === undefined || newItems.length === 0) && (deleteCount === 0 || length === 0))
return [];
if (index === undefined)
index = 0;
else if (index > length)
index = length;
else if (index < 0)
index = Math.max(0, length + index);
if (arguments.length === 1)
deleteCount = length - index;
else if (deleteCount === undefined || deleteCount === null)
deleteCount = 0;
else
return self.get();
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
if (newItems === undefined)
newItems = [];
else if (this.recurse)
newItems = newItems.map(_.makeReactiveArrayItem);
var lengthDelta = newItems.length - deleteCount;
var res = (_a = this._values).splice.apply(_a, [index, deleteCount].concat(newItems));
this.updateLength(length, lengthDelta);
this.notifySplice(index, res, newItems);
return res;
var _a;
};
f.impl = this;
f.observe = function (listener, fire) {
return self.observe(listener, fire);
ObservableArray.prototype.notifyChildUpdate = function (index, oldValue) {
this.notifyChanged();
this.changeEvent.emit({ object: this, type: 'update', index: index, oldValue: oldValue });
};
f.toString = function () {
return self.toString();
ObservableArray.prototype.notifySplice = function (index, deleted, added) {
if (deleted.length === 0 && added.length === 0)
return;
this.notifyChanged();
this.changeEvent.emit({ object: this, type: 'splice', index: index, addedCount: added.length, removed: deleted });
};
return f;
};
ObservableValue.prototype.toString = function () {
return "Observable[" + this._value + "]";
};
return ObservableValue;
})();
var ComputedObservable = (function (_super) {
__extends(ComputedObservable, _super);
function ComputedObservable(func, scope) {
_super.call(this, undefined);
this.func = func;
this.scope = scope;
this.isComputing = false;
this.hasError = false;
if (typeof func !== "function")
throw new Error("ComputedObservable requires a function");
}
ComputedObservable.prototype.get = function () {
if (this.isComputing)
throw new Error("Cycle detected");
var state = this.dependencyState;
if (state.isSleeping) {
if (DNode.trackingStack.length > 0) {
state.wakeUp();
state.notifyObserved();
ObservableArray.prototype.notifyChanged = function () {
this.dependencyState.markStale();
this.dependencyState.markReady(true);
};
ObservableArray.prototype.observe = function (listener, fireImmediately) {
if (fireImmediately === void 0) { fireImmediately = false; }
if (fireImmediately)
listener({ object: this, type: 'splice', index: 0, addedCount: this._values.length, removed: [] });
return this.changeEvent.on(listener);
};
ObservableArray.prototype.clear = function () {
return this.splice(0);
};
ObservableArray.prototype.replace = function (newItems) {
return this.spliceWithArray(0, this._values.length, newItems);
};
ObservableArray.prototype.values = function () {
this.dependencyState.notifyObserved();
return this._values.slice();
};
ObservableArray.prototype.toJSON = function () {
this.dependencyState.notifyObserved();
return this._values.slice();
};
ObservableArray.prototype.clone = function () {
this.dependencyState.notifyObserved();
return new ObservableArray(this._values, this.recurse);
};
ObservableArray.prototype.find = function (predicate, thisArg, fromIndex) {
if (fromIndex === void 0) { fromIndex = 0; }
this.dependencyState.notifyObserved();
var items = this._values, l = items.length;
for (var i = fromIndex; i < l; i++)
if (predicate.call(thisArg, items[i], i, this))
return items[i];
return null;
};
ObservableArray.prototype.splice = function (index, deleteCount) {
var newItems = [];
for (var _i = 2; _i < arguments.length; _i++) {
newItems[_i - 2] = arguments[_i];
}
else {
this.compute();
this.sideEffectWarning("splice");
switch (arguments.length) {
case 0:
return [];
case 1:
return this.spliceWithArray(index);
case 2:
return this.spliceWithArray(index, deleteCount);
}
}
else {
state.notifyObserved();
}
if (state.hasCycle)
throw new Error("Cycle detected");
if (this.hasError) {
if (mobservable.m.debugLevel) {
console.trace();
warn(this + ": rethrowing caught exception to observer: " + this._value + (this._value.cause || ''));
return this.spliceWithArray(index, deleteCount, newItems);
};
ObservableArray.prototype.push = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i - 0] = arguments[_i];
}
throw this._value;
}
return this._value;
};
ComputedObservable.prototype.set = function (_) {
throw new Error(this.toString() + ": A computed observable does not accept new values!");
};
ComputedObservable.prototype.compute = function () {
var newValue;
try {
if (this.isComputing)
throw new Error("Cycle detected");
this.isComputing = true;
newValue = this.func.call(this.scope);
this.hasError = false;
}
catch (e) {
this.hasError = true;
console.error(this + "Caught error during computation: ", e);
if (e instanceof Error)
newValue = e;
else {
newValue = new Error("MobservableComputationError");
newValue.cause = e;
this.sideEffectWarning("push");
this.spliceWithArray(this._values.length, 0, items);
return this._values.length;
};
ObservableArray.prototype.pop = function () {
this.sideEffectWarning("pop");
return this.splice(Math.max(this._values.length - 1, 0), 1)[0];
};
ObservableArray.prototype.shift = function () {
this.sideEffectWarning("shift");
return this.splice(0, 1)[0];
};
ObservableArray.prototype.unshift = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i - 0] = arguments[_i];
}
}
this.isComputing = false;
if (newValue !== this._value) {
var oldValue = this._value;
this._value = newValue;
this.changeEvent.emit(newValue, oldValue);
return true;
}
return false;
};
ComputedObservable.prototype.toString = function () {
return "ComputedObservable[" + this.func.toString() + "]";
};
return ComputedObservable;
})(ObservableValue);
var WatchedExpression = (function () {
function WatchedExpression(expr, onInvalidate) {
this.expr = expr;
this.onInvalidate = onInvalidate;
this.dependencyState = new DNode(this);
this.didEvaluate = false;
this.dependencyState.computeNextState();
}
WatchedExpression.prototype.compute = function () {
if (!this.didEvaluate) {
this.didEvaluate = true;
this.value = this.expr();
}
else {
this.dispose();
this.onInvalidate();
}
return false;
};
WatchedExpression.prototype.dispose = function () {
this.dependencyState.dispose();
};
return WatchedExpression;
})();
var DNodeState;
(function (DNodeState) {
DNodeState[DNodeState["STALE"] = 0] = "STALE";
DNodeState[DNodeState["PENDING"] = 1] = "PENDING";
DNodeState[DNodeState["READY"] = 2] = "READY";
})(DNodeState || (DNodeState = {}));
;
var DNode = (function () {
function DNode(owner) {
this.owner = owner;
this.state = DNodeState.READY;
this.isSleeping = true;
this.hasCycle = false;
this.observing = [];
this.prevObserving = null;
this.observers = [];
this.dependencyChangeCount = 0;
this.dependencyStaleCount = 0;
this.isDisposed = false;
this.externalRefenceCount = 0;
this.isComputed = owner.compute !== undefined;
}
;
DNode.prototype.setRefCount = function (delta) {
var rc = this.externalRefenceCount += delta;
if (rc === 0)
this.tryToSleep();
else if (rc === delta)
this.wakeUp();
};
DNode.prototype.addObserver = function (node) {
this.observers[this.observers.length] = node;
};
DNode.prototype.removeObserver = function (node) {
var obs = this.observers, idx = obs.indexOf(node);
if (idx !== -1) {
obs.splice(idx, 1);
if (obs.length === 0)
this.tryToSleep();
}
};
DNode.prototype.markStale = function () {
if (this.state !== DNodeState.READY)
return;
this.state = DNodeState.STALE;
this.notifyObservers();
};
DNode.prototype.markReady = function (stateDidActuallyChange) {
if (this.state === DNodeState.READY)
return;
this.state = DNodeState.READY;
this.notifyObservers(stateDidActuallyChange);
};
DNode.prototype.notifyObservers = function (stateDidActuallyChange) {
if (stateDidActuallyChange === void 0) { stateDidActuallyChange = false; }
var os = this.observers.slice();
for (var l = os.length, i = 0; i < l; i++)
os[i].notifyStateChange(this, stateDidActuallyChange);
};
DNode.prototype.tryToSleep = function () {
if (!this.isSleeping && this.isComputed && this.observers.length === 0 && this.externalRefenceCount === 0) {
for (var i = 0, l = this.observing.length; i < l; i++)
this.observing[i].removeObserver(this);
this.observing = [];
this.isSleeping = true;
}
};
DNode.prototype.wakeUp = function () {
if (this.isSleeping && this.isComputed) {
this.isSleeping = false;
this.state = DNodeState.PENDING;
this.computeNextState();
}
};
DNode.prototype.notifyStateChange = function (observable, stateDidActuallyChange) {
var _this = this;
if (observable.state === DNodeState.STALE) {
if (++this.dependencyStaleCount === 1)
this.markStale();
}
else {
if (stateDidActuallyChange)
this.dependencyChangeCount += 1;
if (--this.dependencyStaleCount === 0) {
this.state = DNodeState.PENDING;
Scheduler.schedule(function () {
if (_this.dependencyChangeCount > 0)
_this.computeNextState();
else
_this.markReady(false);
_this.dependencyChangeCount = 0;
});
this.sideEffectWarning("unshift");
this.spliceWithArray(0, 0, items);
return this._values.length;
};
ObservableArray.prototype.reverse = function () {
this.sideEffectWarning("reverse");
return this.replace(this._values.reverse());
};
ObservableArray.prototype.sort = function (compareFn) {
this.sideEffectWarning("sort");
return this.replace(this._values.sort.apply(this._values, arguments));
};
ObservableArray.prototype.remove = function (value) {
this.sideEffectWarning("remove");
var idx = this._values.indexOf(value);
if (idx > -1) {
this.splice(idx, 1);
return true;
}
}
};
DNode.prototype.computeNextState = function () {
this.trackDependencies();
var stateDidChange = this.owner.compute();
this.bindDependencies();
this.markReady(stateDidChange);
};
DNode.prototype.trackDependencies = function () {
this.prevObserving = this.observing;
DNode.trackingStack[DNode.trackingStack.length] = [];
};
DNode.prototype.bindDependencies = function () {
this.observing = DNode.trackingStack.pop();
if (this.isComputed && this.observing.length === 0 && mobservable.m.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?");
}
var _a = quickDiff(this.observing, this.prevObserving), added = _a[0], removed = _a[1];
this.prevObserving = null;
for (var i = 0, l = removed.length; i < l; i++)
removed[i].removeObserver(this);
this.hasCycle = false;
for (var i = 0, l = added.length; i < l; i++) {
if (this.isComputed && added[i].findCycle(this)) {
this.hasCycle = true;
this.observing.splice(this.observing.indexOf(added[i]), 1);
added[i].hasCycle = true;
}
else {
added[i].addObserver(this);
}
}
};
DNode.prototype.notifyObserved = function () {
var ts = DNode.trackingStack, l = ts.length;
if (l > 0) {
var cs = ts[l - 1], csl = cs.length;
if (cs[csl - 1] !== this && cs[csl - 2] !== this)
cs[csl] = this;
}
};
DNode.prototype.findCycle = function (node) {
var obs = this.observing;
if (obs.indexOf(node) !== -1)
return true;
for (var l = obs.length, i = 0; i < l; i++)
if (obs[i].findCycle(node))
return true;
return false;
};
DNode.prototype.dispose = function () {
if (this.observers.length)
throw new Error("Cannot dispose DNode; it is still being observed");
if (this.observing)
for (var l = this.observing.length, i = 0; i < l; i++)
this.observing[i].removeObserver(this);
this.observing = null;
this.isDisposed = true;
};
DNode.trackingStack = [];
return DNode;
})();
var StubArray = (function () {
function StubArray() {
}
return StubArray;
})();
StubArray.prototype = [];
var ObservableArray = (function (_super) {
__extends(ObservableArray, _super);
function ObservableArray(initialValues) {
_super.call(this);
Object.defineProperties(this, {
"dependencyState": { enumerable: false, value: new DNode(this) },
"_values": { enumerable: false, value: initialValues ? initialValues.slice() : [] },
"changeEvent": { enumerable: false, value: new SimpleEventEmitter() }
});
if (initialValues && initialValues.length)
this.updateLength(0, initialValues.length);
}
Object.defineProperty(ObservableArray.prototype, "length", {
get: function () {
this.dependencyState.notifyObserved();
return this._values.length;
},
set: function (newLength) {
if (typeof newLength !== "number" || newLength < 0)
throw new Error("Out of range: " + newLength);
var currentLength = this._values.length;
if (newLength === currentLength)
return;
else if (newLength > currentLength)
this.spliceWithArray(currentLength, 0, new Array(newLength - currentLength));
else
this.spliceWithArray(newLength, currentLength - newLength);
},
enumerable: true,
configurable: true
});
ObservableArray.prototype.updateLength = function (oldLength, delta) {
if (delta < 0)
for (var i = oldLength + delta; i < oldLength; i++)
delete this[i];
else if (delta > 0) {
if (oldLength + delta > ObservableArray.OBSERVABLE_ARRAY_BUFFER_SIZE)
ObservableArray.reserveArrayBuffer(oldLength + delta);
for (var i = oldLength, end = oldLength + delta; i < end; i++)
Object.defineProperty(this, "" + i, ObservableArray.ENUMERABLE_PROPS[i]);
}
};
ObservableArray.prototype.spliceWithArray = function (index, deleteCount, newItems) {
var length = this._values.length;
if ((newItems === undefined || newItems.length === 0) && (deleteCount === 0 || length === 0))
return [];
if (index === undefined)
index = 0;
else if (index > length)
index = length;
else if (index < 0)
index = Math.max(0, length + index);
if (arguments.length === 1)
deleteCount = length - index;
else if (deleteCount === undefined || deleteCount === null)
deleteCount = 0;
else
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
if (newItems === undefined)
newItems = [];
var lengthDelta = newItems.length - deleteCount;
var res = (_a = this._values).splice.apply(_a, [index, deleteCount].concat(newItems));
this.updateLength(length, lengthDelta);
this.notifySplice(index, res, newItems);
return res;
var _a;
};
ObservableArray.prototype.notifyChildUpdate = function (index, oldValue) {
this.notifyChanged();
this.changeEvent.emit({ object: this, type: 'update', index: index, oldValue: oldValue });
};
ObservableArray.prototype.notifySplice = function (index, deleted, added) {
if (deleted.length === 0 && added.length === 0)
return;
this.notifyChanged();
this.changeEvent.emit({ object: this, type: 'splice', index: index, addedCount: added.length, removed: deleted });
};
ObservableArray.prototype.notifyChanged = function () {
this.dependencyState.markStale();
this.dependencyState.markReady(true);
};
ObservableArray.prototype.observe = function (listener, fireImmediately) {
if (fireImmediately === void 0) { fireImmediately = false; }
if (fireImmediately)
listener({ object: this, type: 'splice', index: 0, addedCount: this._values.length, removed: [] });
return this.changeEvent.on(listener);
};
ObservableArray.prototype.clear = function () {
return this.splice(0);
};
ObservableArray.prototype.replace = function (newItems) {
return this.spliceWithArray(0, this._values.length, newItems);
};
ObservableArray.prototype.values = function () {
this.dependencyState.notifyObserved();
return this._values.slice();
};
ObservableArray.prototype.toJSON = function () {
this.dependencyState.notifyObserved();
return this._values.slice();
};
ObservableArray.prototype.clone = function () {
this.dependencyState.notifyObserved();
return new ObservableArray(this._values);
};
ObservableArray.prototype.find = function (predicate, thisArg, fromIndex) {
if (fromIndex === void 0) { fromIndex = 0; }
this.dependencyState.notifyObserved();
var items = this._values, l = items.length;
for (var i = fromIndex; i < l; i++)
if (predicate.call(thisArg, items[i], i, this))
return items[i];
return null;
};
ObservableArray.prototype.splice = function (index, deleteCount) {
var newItems = [];
for (var _i = 2; _i < arguments.length; _i++) {
newItems[_i - 2] = arguments[_i];
}
this.sideEffectWarning("splice");
switch (arguments.length) {
case 0:
return [];
case 1:
return this.spliceWithArray(index);
case 2:
return this.spliceWithArray(index, deleteCount);
}
return this.spliceWithArray(index, deleteCount, newItems);
};
ObservableArray.prototype.push = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i - 0] = arguments[_i];
}
this.sideEffectWarning("push");
this.spliceWithArray(this._values.length, 0, items);
return this._values.length;
};
ObservableArray.prototype.pop = function () {
this.sideEffectWarning("pop");
return this.splice(Math.max(this._values.length - 1, 0), 1)[0];
};
ObservableArray.prototype.shift = function () {
this.sideEffectWarning("shift");
return this.splice(0, 1)[0];
};
ObservableArray.prototype.unshift = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i - 0] = arguments[_i];
}
this.sideEffectWarning("unshift");
this.spliceWithArray(0, 0, items);
return this._values.length;
};
ObservableArray.prototype.reverse = function () {
this.sideEffectWarning("reverse");
return this.replace(this._values.reverse());
};
ObservableArray.prototype.sort = function (compareFn) {
this.sideEffectWarning("sort");
return this.replace(this._values.sort.apply(this._values, arguments));
};
ObservableArray.prototype.remove = function (value) {
this.sideEffectWarning("remove");
var idx = this._values.indexOf(value);
if (idx > -1) {
this.splice(idx, 1);
return true;
}
return false;
};
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.dependencyState.notifyObserved();
return baseFunc.apply(this._values, arguments);
}).apply(this, initialArgs);
};
ObservableArray.prototype.sideEffectWarning = function (funcName) {
if (mobservable.m.debugLevel > 0 && DNode.trackingStack.length > 0)
warn("[Mobservable.Array] The method array." + funcName + " should probably not be used inside observable functions since it has side-effects");
};
ObservableArray.createArrayBufferItem = function (index) {
return false;
};
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.dependencyState.notifyObserved();
return baseFunc.apply(this._values, arguments);
}).apply(this, initialArgs);
};
ObservableArray.prototype.sideEffectWarning = function (funcName) {
if (mobservable.debugLevel > 0 && _.DNode.trackingStack.length > 0)
_.warn("[Mobservable.Array] The method array." + funcName + " should probably not be used inside observable functions since it has side-effects");
};
return ObservableArray;
})(StubArray);
_.ObservableArray = ObservableArray;
var OBSERVABLE_ARRAY_BUFFER_SIZE = 0;
var ENUMERABLE_PROPS = [];
function createArrayBufferItem(index) {
var prop = {

@@ -722,96 +913,15 @@ enumerable: false,

prop.configurable = true;
ObservableArray.ENUMERABLE_PROPS[index] = prop;
};
ObservableArray.reserveArrayBuffer = function (max) {
for (var index = ObservableArray.OBSERVABLE_ARRAY_BUFFER_SIZE; index < max; index++)
ObservableArray.createArrayBufferItem(index);
ObservableArray.OBSERVABLE_ARRAY_BUFFER_SIZE = max;
};
ObservableArray.OBSERVABLE_ARRAY_BUFFER_SIZE = 0;
ObservableArray.ENUMERABLE_PROPS = [];
return ObservableArray;
})(StubArray);
ObservableArray.reserveArrayBuffer(1000);
var SimpleEventEmitter = (function () {
function SimpleEventEmitter() {
this.listeners = [];
ENUMERABLE_PROPS[index] = prop;
}
SimpleEventEmitter.prototype.emit = function () {
var listeners = this.listeners.slice();
var l = listeners.length;
switch (arguments.length) {
case 0:
for (var i = 0; i < l; i++)
listeners[i]();
break;
case 1:
var data = arguments[0];
for (var i = 0; i < l; i++)
listeners[i](data);
break;
default:
for (var i = 0; i < l; i++)
listeners[i].apply(null, arguments);
}
};
SimpleEventEmitter.prototype.on = function (listener) {
var _this = this;
this.listeners.push(listener);
return once(function () {
var idx = _this.listeners.indexOf(listener);
if (idx !== -1)
_this.listeners.splice(idx, 1);
});
};
SimpleEventEmitter.prototype.once = function (listener) {
var subscription = this.on(function () {
subscription();
listener.apply(this, arguments);
});
return subscription;
};
return SimpleEventEmitter;
})();
mobservable.m.SimpleEventEmitter = SimpleEventEmitter;
var Scheduler = (function () {
function Scheduler() {
function reserveArrayBuffer(max) {
for (var index = OBSERVABLE_ARRAY_BUFFER_SIZE; index < max; index++)
createArrayBufferItem(index);
OBSERVABLE_ARRAY_BUFFER_SIZE = max;
}
Scheduler.schedule = function (func) {
if (Scheduler.inBatch < 1)
func();
else
Scheduler.tasks[Scheduler.tasks.length] = func;
};
Scheduler.runPostBatchActions = function () {
var i = 0;
while (Scheduler.tasks.length) {
try {
for (; i < Scheduler.tasks.length; i++)
Scheduler.tasks[i]();
Scheduler.tasks = [];
}
catch (e) {
console.error("Failed to run scheduled action, the action has been dropped from the queue: " + e, e);
Scheduler.tasks.splice(0, i + 1);
}
}
};
Scheduler.batch = function (action) {
Scheduler.inBatch += 1;
try {
return action();
}
finally {
if (--Scheduler.inBatch === 0) {
Scheduler.inBatch += 1;
Scheduler.runPostBatchActions();
Scheduler.inBatch -= 1;
}
}
};
Scheduler.inBatch = 0;
Scheduler.tasks = [];
return Scheduler;
})();
mobservable.m.ObserverMixin = {
reserveArrayBuffer(1000);
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
var mobservable;
(function (mobservable) {
mobservable.reactiveMixin = {
componentWillMount: function () {

@@ -823,3 +933,3 @@ var baseRender = this.render;

this._watchDisposer();
var _a = mobservable.m.watch(function () { return baseRender.call(_this); }, function () {
var _a = mobservable.observeUntilInvalid(function () { return baseRender.call(_this); }, function () {
_this.forceUpdate();

@@ -848,79 +958,231 @@ }), rendering = _a[0], disposer = _a[1];

};
mobservable.m.ObservingComponent = function (componentClass) {
mobservable.ObserverMixin = mobservable.reactiveMixin;
function reactiveComponent(componentClass) {
var baseMount = componentClass.prototype.componentWillMount;
var baseUnmount = componentClass.prototype.componentWillUnmount;
componentClass.prototype.componentWillMount = function () {
mobservable.m.ObserverMixin.componentWillMount.apply(this, arguments);
mobservable.ObserverMixin.componentWillMount.apply(this, arguments);
baseMount && baseMount.apply(this, arguments);
};
componentClass.prototype.componentWillUnmount = function () {
mobservable.m.ObserverMixin.componentWillUnmount.apply(this, arguments);
mobservable.ObserverMixin.componentWillUnmount.apply(this, arguments);
baseUnmount && baseUnmount.apply(this, arguments);
};
if (!componentClass.prototype.shouldComponentUpdate)
componentClass.prototype.shouldComponentUpdate = mobservable.m.ObserverMixin.shouldComponentUpdate;
componentClass.prototype.shouldComponentUpdate = mobservable.ObserverMixin.shouldComponentUpdate;
return componentClass;
};
function quickDiff(current, base) {
if (!base || !base.length)
return [current, []];
if (!current || !current.length)
return [[], base];
var added = [];
var removed = [];
var currentIndex = 0, currentSearch = 0, currentLength = current.length, currentExhausted = false, baseIndex = 0, baseSearch = 0, baseLength = base.length, isSearching = false, baseExhausted = false;
while (!baseExhausted && !currentExhausted) {
if (!isSearching) {
if (currentIndex < currentLength && baseIndex < baseLength && current[currentIndex] === base[baseIndex]) {
currentIndex++;
}
mobservable.reactiveComponent = reactiveComponent;
;
mobservable.ObservingComponent = mobservable._.wrapDeprecated("ObservingComponent", reactiveComponent);
})(mobservable || (mobservable = {}));
var mobservable;
(function (mobservable) {
var _;
(function (_) {
var Scheduler = (function () {
function Scheduler() {
}
Scheduler.schedule = function (func) {
if (Scheduler.inBatch < 1)
func();
else
Scheduler.tasks[Scheduler.tasks.length] = func;
};
Scheduler.runPostBatchActions = function () {
var i = 0;
while (Scheduler.tasks.length) {
try {
for (; i < Scheduler.tasks.length; i++)
Scheduler.tasks[i]();
Scheduler.tasks = [];
}
catch (e) {
console.error("Failed to run scheduled action, the action has been dropped from the queue: " + e, e);
Scheduler.tasks.splice(0, i + 1);
}
}
};
Scheduler.batch = function (action) {
Scheduler.inBatch += 1;
try {
return action();
}
finally {
if (--Scheduler.inBatch === 0) {
Scheduler.inBatch += 1;
Scheduler.runPostBatchActions();
Scheduler.inBatch -= 1;
}
}
};
Scheduler.inBatch = 0;
Scheduler.tasks = [];
return Scheduler;
})();
_.Scheduler = Scheduler;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
var mobservable;
(function (mobservable) {
var _;
(function (_) {
var SimpleEventEmitter = (function () {
function SimpleEventEmitter() {
this.listeners = [];
}
SimpleEventEmitter.prototype.emit = function () {
var listeners = this.listeners.slice();
var l = listeners.length;
switch (arguments.length) {
case 0:
for (var i = 0; i < l; i++)
listeners[i]();
break;
case 1:
var data = arguments[0];
for (var i = 0; i < l; i++)
listeners[i](data);
break;
default:
for (var i = 0; i < l; i++)
listeners[i].apply(null, arguments);
}
};
SimpleEventEmitter.prototype.on = function (listener) {
var _this = this;
this.listeners.push(listener);
return _.once(function () {
var idx = _this.listeners.indexOf(listener);
if (idx !== -1)
_this.listeners.splice(idx, 1);
});
};
SimpleEventEmitter.prototype.once = function (listener) {
var subscription = this.on(function () {
subscription();
listener.apply(this, arguments);
});
return subscription;
};
return SimpleEventEmitter;
})();
_.SimpleEventEmitter = SimpleEventEmitter;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
var mobservable;
(function (mobservable) {
var _;
(function (_) {
function warn(message) {
if (console)
console.warn("[mobservable:warning] " + message);
}
_.warn = warn;
function once(func) {
var invoked = false;
return function () {
if (invoked)
return;
invoked = true;
return func.apply(this, arguments);
};
}
_.once = once;
function noop() {
}
_.noop = noop;
function isPlainObject(value) {
return value !== null && typeof value == 'object' && Object.getPrototypeOf(value) === Object.prototype;
}
_.isPlainObject = isPlainObject;
function quickDiff(current, base) {
if (!base || !base.length)
return [current, []];
if (!current || !current.length)
return [[], base];
var added = [];
var removed = [];
var currentIndex = 0, currentSearch = 0, currentLength = current.length, currentExhausted = false, baseIndex = 0, baseSearch = 0, baseLength = base.length, isSearching = false, baseExhausted = false;
while (!baseExhausted && !currentExhausted) {
if (!isSearching) {
if (currentIndex < currentLength && baseIndex < baseLength && current[currentIndex] === base[baseIndex]) {
currentIndex++;
baseIndex++;
if (currentIndex === currentLength && baseIndex === baseLength)
return [added, removed];
continue;
}
currentSearch = currentIndex;
baseSearch = baseIndex;
isSearching = true;
}
baseSearch += 1;
currentSearch += 1;
if (baseSearch >= baseLength)
baseExhausted = true;
if (currentSearch >= currentLength)
currentExhausted = true;
if (!currentExhausted && current[currentSearch] === base[baseIndex]) {
added.push.apply(added, current.slice(currentIndex, currentSearch));
currentIndex = currentSearch + 1;
baseIndex++;
if (currentIndex === currentLength && baseIndex === baseLength)
return [added, removed];
continue;
isSearching = false;
}
currentSearch = currentIndex;
baseSearch = baseIndex;
isSearching = true;
else if (!baseExhausted && base[baseSearch] === current[currentIndex]) {
removed.push.apply(removed, base.slice(baseIndex, baseSearch));
baseIndex = baseSearch + 1;
currentIndex++;
isSearching = false;
}
}
baseSearch += 1;
currentSearch += 1;
if (baseSearch >= baseLength)
baseExhausted = true;
if (currentSearch >= currentLength)
currentExhausted = true;
if (!currentExhausted && current[currentSearch] === base[baseIndex]) {
added.push.apply(added, current.slice(currentIndex, currentSearch));
currentIndex = currentSearch + 1;
baseIndex++;
isSearching = false;
}
else if (!baseExhausted && base[baseSearch] === current[currentIndex]) {
removed.push.apply(removed, base.slice(baseIndex, baseSearch));
baseIndex = baseSearch + 1;
currentIndex++;
isSearching = false;
}
added.push.apply(added, current.slice(currentIndex));
removed.push.apply(removed, base.slice(baseIndex));
return [added, removed];
}
added.push.apply(added, current.slice(currentIndex));
removed.push.apply(removed, base.slice(baseIndex));
return [added, removed];
}
mobservable.m.quickDiff = quickDiff;
mobservable.m.stackDepth = function () { return DNode.trackingStack.length; };
function warn(message) {
if (console)
console.warn("[WARNING:mobservable] " + message);
}
function once(func) {
var invoked = false;
return function () {
if (invoked)
return;
invoked = true;
return func.apply(this, arguments);
};
}
function noop() { }
;
_.quickDiff = quickDiff;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
/// <reference path="./observablevalue" />
var mobservable;
(function (mobservable) {
var _;
(function (_) {
var WatchedExpression = (function () {
function WatchedExpression(expr, onInvalidate) {
this.expr = expr;
this.onInvalidate = onInvalidate;
this.dependencyState = new _.DNode(this);
this.didEvaluate = false;
this.dependencyState.computeNextState();
}
WatchedExpression.prototype.compute = function () {
if (!this.didEvaluate) {
this.didEvaluate = true;
this.value = this.expr();
}
else {
this.dispose();
this.onInvalidate();
}
return false;
};
WatchedExpression.prototype.dispose = function () {
this.dependencyState.dispose();
};
return WatchedExpression;
})();
_.WatchedExpression = WatchedExpression;
})(_ = mobservable._ || (mobservable._ = {}));
})(mobservable || (mobservable = {}));
/**
* This file basically works around all the typescript limitations that exist atm:
* 1. not being able to generate an external (UMD) module from multiple files (thats why we have internal module)
* 2. not being able to merge a default export declaration with non-default export declarations
*/
/// <reference path="./utils.ts" />
/// <reference path="./index.ts" />
/// <reference path="./api.ts" />
/// <reference path="./watch.ts" />
var forCompilerVerificationOnly = mobservable;
(function (root, factory) {

@@ -939,3 +1201,6 @@ if (typeof define === 'function' && define.amd) {

}(this, function () {
return mobservable.m;
var m = mobservable.makeReactive;
for (var key in mobservable)
m[key] = mobservable[key];
return m;
}));

@@ -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){function b(b,c){return Array.isArray(b)?new m(b):"function"==typeof b?a.m.computed(b,c):a.m.primitive(b)}function c(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]}function d(a){console&&console.warn("[WARNING:mobservable] "+a)}function e(a){var b=!1;return function(){return b?void 0:(b=!0,a.apply(this,arguments))}}function f(){}a.m=function(a,c){return b(a,c)},a.m.value=b,a.m.primitive=a.m.reference=function(a){return new h(a).createGetterSetter()},a.m.computed=function(a,b){return new i(a,b).createGetterSetter()},a.m.expr=function(a,b){if(0===k.trackingStack.length)throw new Error("mobservable.expr can only be used inside a computed observable. Probably mobservable.computed should be used instead of .expr");return new i(a,b).get()},a.m.sideEffect=function(b,c){return a.m.computed(b,c).observe(f)},a.m.array=function(a){return new m(a)},a.m.props=function p(b,p,c){switch(arguments.length){case 0:throw new Error("Not enough arguments");case 1:return a.m.props(b,b);case 2:for(var d in p)a.m.props(b,d,p[d]);break;case 3:var e=Array.isArray(c),f=a.m.value(c,b);Object.defineProperty(b,p,{get:e?function(){return f}:f,set:e?function(a){f.replace(a)}:f,enumerable:!0,configurable:!1})}return b},a.m.fromJson=function q(b){function c(a){return a&&"object"==typeof a?q(a):a}if(b){if(Array.isArray(b))return a.m.array(b.map(c));if("object"==typeof b){var d={};for(var e in b)b.hasOwnProperty(e)&&(d[e]=c(b[e]));return a.m.props(d)}}throw new Error("mobservable.fromJson expects object or array, got: '"+b+"'")},a.m.toJson=function r(a){if(!a)return a;if(Array.isArray(a)||a instanceof m)return a.map(r);if("object"==typeof a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=r(a[c]));return b}return a},a.m.observable=function(b,c,d){var e=d?d.value:null;"function"==typeof e?(delete d.value,delete d.writable,d.configurable=!0,d.get=function(){var b=this.key=a.m.computed(e,this);return b},d.set=function(){throw console.trace(),new Error("It is not allowed to reassign observable functions")}):Object.defineProperty(b,c,{configurable:!0,enumberable:!0,get:function(){return a.m.props(this,c,void 0),this[c]},set:function(b){a.m.props(this,c,b)}})},a.m.toPlainValue=function s(a){if(a){if(a instanceof Array)return a.slice();if(a instanceof h)return a.get();if("function"==typeof a&&a.impl){if(a.impl instanceof h)return a();if(a.impl instanceof m)return a().slice()}else if("object"==typeof a){var b={};for(var c in a)b[c]=s(a[c]);return b}}return a},a.m.observeProperty=function(a,b,c,d){if(void 0===d&&(d=!1),!a)throw new Error("Cannot observe property of '"+a+"'");if(!(b in a))throw new Error("Object '"+a+"' has no property '"+b+"'.");if(!c||"function"!=typeof c)throw new Error("Third argument to mobservable.observeProperty should be a function");var f=new i(function(){return a[b]},a),g=f.observe(c,d);if(0===f.dependencyState.observing.length)throw new Error("mobservable.observeProperty: property '"+b+"' of '"+a+" doesn't seem to be observable. Did you define it as observable using @observable or mobservable.props? You might try to use the .observe() method instead.");return e(function(){g(),f.dependencyState.dispose()})},a.m.watch=function t(a,b){var t=new j(a,b);return[t.value,function(){return t.dispose()}]},a.m.batch=function(a){return o.batch(a)},a.m.debugLevel=0;var g,h=function(){function a(a){this._value=a,this.changeEvent=new n,this.dependencyState=new k(this)}return a.prototype.set=function(a){if(a!==this._value){var b=this._value;this.dependencyState.markStale(),this._value=a,this.dependencyState.markReady(!0),this.changeEvent.emit(a,b)}},a.prototype.get=function(){return this.dependencyState.notifyObserved(),this._value},a.prototype.observe=function(a,b){var c=this;void 0===b&&(b=!1),this.dependencyState.setRefCount(1),b&&a(this.get(),void 0);var d=this.changeEvent.on(a);return e(function(){c.dependencyState.setRefCount(-1),d()})},a.prototype.createGetterSetter=function(){var a=this,b=function(b){return arguments.length>0?void a.set(b):a.get()};return b.impl=this,b.observe=function(b,c){return a.observe(b,c)},b.toString=function(){return a.toString()},b},a.prototype.toString=function(){return"Observable["+this._value+"]"},a}(),i=function(b){function c(a,c){if(b.call(this,void 0),this.func=a,this.scope=c,this.isComputing=!1,this.hasError=!1,"function"!=typeof a)throw new Error("ComputedObservable requires a function")}return __extends(c,b),c.prototype.get=function(){if(this.isComputing)throw new Error("Cycle detected");var b=this.dependencyState;if(b.isSleeping?k.trackingStack.length>0?(b.wakeUp(),b.notifyObserved()):this.compute():b.notifyObserved(),b.hasCycle)throw new Error("Cycle detected");if(this.hasError)throw a.m.debugLevel&&(console.trace(),d(this+": rethrowing caught exception to observer: "+this._value+(this._value.cause||""))),this._value;return this._value},c.prototype.set=function(a){throw new Error(this.toString()+": A computed observable does not accept new values!")},c.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},c.prototype.toString=function(){return"ComputedObservable["+this.func.toString()+"]"},c}(h),j=function(){function a(a,b){this.expr=a,this.onInvalidate=b,this.dependencyState=new k(this),this.didEvaluate=!1,this.dependencyState.computeNextState()}return a.prototype.compute=function(){return this.didEvaluate?(this.dispose(),this.onInvalidate()):(this.didEvaluate=!0,this.value=this.expr()),!1},a.prototype.dispose=function(){this.dependencyState.dispose()},a}();!function(a){a[a.STALE=0]="STALE",a[a.PENDING=1]="PENDING",a[a.READY=2]="READY"}(g||(g={}));var k=function(){function b(a){this.owner=a,this.state=g.READY,this.isSleeping=!0,this.hasCycle=!1,this.observing=[],this.prevObserving=null,this.observers=[],this.dependencyChangeCount=0,this.dependencyStaleCount=0,this.isDisposed=!1,this.externalRefenceCount=0,this.isComputed=void 0!==a.compute}return b.prototype.setRefCount=function(a){var b=this.externalRefenceCount+=a;0===b?this.tryToSleep():b===a&&this.wakeUp()},b.prototype.addObserver=function(a){this.observers[this.observers.length]=a},b.prototype.removeObserver=function(a){var b=this.observers,c=b.indexOf(a);-1!==c&&(b.splice(c,1),0===b.length&&this.tryToSleep())},b.prototype.markStale=function(){this.state===g.READY&&(this.state=g.STALE,this.notifyObservers())},b.prototype.markReady=function(a){this.state!==g.READY&&(this.state=g.READY,this.notifyObservers(a))},b.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)},b.prototype.tryToSleep=function(){if(!this.isSleeping&&this.isComputed&&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}},b.prototype.wakeUp=function(){this.isSleeping&&this.isComputed&&(this.isSleeping=!1,this.state=g.PENDING,this.computeNextState())},b.prototype.notifyStateChange=function(a,b){var c=this;a.state===g.STALE?1===++this.dependencyStaleCount&&this.markStale():(b&&(this.dependencyChangeCount+=1),0===--this.dependencyStaleCount&&(this.state=g.PENDING,o.schedule(function(){c.dependencyChangeCount>0?c.computeNextState():c.markReady(!1),c.dependencyChangeCount=0})))},b.prototype.computeNextState=function(){this.trackDependencies();var a=this.owner.compute();this.bindDependencies(),this.markReady(a)},b.prototype.trackDependencies=function(){this.prevObserving=this.observing,b.trackingStack[b.trackingStack.length]=[]},b.prototype.bindDependencies=function(){this.observing=b.trackingStack.pop(),this.isComputed&&0===this.observing.length&&a.m.debugLevel>1&&!this.isDisposed&&(console.trace(),d("You have created a function that doesn't observe any values, did you forget to make its dependencies observable?"));var e=c(this.observing,this.prevObserving),f=e[0],g=e[1];this.prevObserving=null;for(var h=0,i=g.length;i>h;h++)g[h].removeObserver(this);this.hasCycle=!1;for(var h=0,i=f.length;i>h;h++)this.isComputed&&f[h].findCycle(this)?(this.hasCycle=!0,this.observing.splice(this.observing.indexOf(f[h]),1),f[h].hasCycle=!0):f[h].addObserver(this)},b.prototype.notifyObserved=function(){var a=b.trackingStack,c=a.length;if(c>0){var d=a[c-1],e=d.length;d[e-1]!==this&&d[e-2]!==this&&(d[e]=this)}},b.prototype.findCycle=function(a){var b=this.observing;if(-1!==b.indexOf(a))return!0;for(var c=b.length,d=0;c>d;d++)if(b[d].findCycle(a))return!0;return!1},b.prototype.dispose=function(){if(this.observers.length)throw new Error("Cannot dispose DNode; it is still being observed");if(this.observing)for(var a=this.observing.length,b=0;a>b;b++)this.observing[b].removeObserver(this);this.observing=null,this.isDisposed=!0},b.trackingStack=[],b}(),l=function(){function a(){}return a}();l.prototype=[];var m=function(b){function c(a){b.call(this),Object.defineProperties(this,{dependencyState:{enumerable:!1,value:new k(this)},_values:{enumerable:!1,value:a?a.slice():[]},changeEvent:{enumerable:!1,value:new n}}),a&&a.length&&this.updateLength(0,a.length)}return __extends(c,b),Object.defineProperty(c.prototype,"length",{get:function(){return this.dependencyState.notifyObserved(),this._values.length},set:function(a){if("number"!=typeof a||0>a)throw new Error("Out of range: "+a);var b=this._values.length;a!==b&&(a>b?this.spliceWithArray(b,0,new Array(a-b)):this.spliceWithArray(a,b-a))},enumerable:!0,configurable:!0}),c.prototype.updateLength=function(a,b){if(0>b)for(var d=a+b;a>d;d++)delete this[d];else if(b>0){a+b>c.OBSERVABLE_ARRAY_BUFFER_SIZE&&c.reserveArrayBuffer(a+b);for(var d=a,e=a+b;e>d;d++)Object.defineProperty(this,""+d,c.ENUMERABLE_PROPS[d])}},c.prototype.spliceWithArray=function(a,b,c){var d=this._values.length;if(!(void 0!==c&&0!==c.length||0!==b&&0!==d))return[];void 0===a?a=0:a>d?a=d:0>a&&(a=Math.max(0,d+a)),b=1===arguments.length?d-a:void 0===b||null===b?0:Math.max(0,Math.min(b,d-a)),void 0===c&&(c=[]);var e=c.length-b,f=(g=this._values).splice.apply(g,[a,b].concat(c));return this.updateLength(d,e),this.notifySplice(a,f,c),f;var g},c.prototype.notifyChildUpdate=function(a,b){this.notifyChanged(),this.changeEvent.emit({object:this,type:"update",index:a,oldValue:b})},c.prototype.notifySplice=function(a,b,c){(0!==b.length||0!==c.length)&&(this.notifyChanged(),this.changeEvent.emit({object:this,type:"splice",index:a,addedCount:c.length,removed:b}))},c.prototype.notifyChanged=function(){this.dependencyState.markStale(),this.dependencyState.markReady(!0)},c.prototype.observe=function(a,b){return void 0===b&&(b=!1),b&&a({object:this,type:"splice",index:0,addedCount:this._values.length,removed:[]}),this.changeEvent.on(a)},c.prototype.clear=function(){return this.splice(0)},c.prototype.replace=function(a){return this.spliceWithArray(0,this._values.length,a)},c.prototype.values=function(){return this.dependencyState.notifyObserved(),this._values.slice()},c.prototype.toJSON=function(){return this.dependencyState.notifyObserved(),this._values.slice()},c.prototype.clone=function(){return this.dependencyState.notifyObserved(),new c(this._values)},c.prototype.find=function(a,b,c){void 0===c&&(c=0),this.dependencyState.notifyObserved();for(var d=this._values,e=d.length,f=c;e>f;f++)if(a.call(b,d[f],f,this))return d[f];return null},c.prototype.splice=function(a,b){for(var c=[],d=2;d<arguments.length;d++)c[d-2]=arguments[d];switch(this.sideEffectWarning("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)},c.prototype.push=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this.sideEffectWarning("push"),this.spliceWithArray(this._values.length,0,a),this._values.length},c.prototype.pop=function(){return this.sideEffectWarning("pop"),this.splice(Math.max(this._values.length-1,0),1)[0]},c.prototype.shift=function(){return this.sideEffectWarning("shift"),this.splice(0,1)[0]},c.prototype.unshift=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this.sideEffectWarning("unshift"),this.spliceWithArray(0,0,a),this._values.length},c.prototype.reverse=function(){return this.sideEffectWarning("reverse"),this.replace(this._values.reverse())},c.prototype.sort=function(a){return this.sideEffectWarning("sort"),this.replace(this._values.sort.apply(this._values,arguments))},c.prototype.remove=function(a){this.sideEffectWarning("remove");var b=this._values.indexOf(a);return b>-1?(this.splice(b,1),!0):!1},c.prototype.toString=function(){return this.wrapReadFunction("toString",arguments)},c.prototype.toLocaleString=function(){return this.wrapReadFunction("toLocaleString",arguments)},c.prototype.concat=function(){return this.wrapReadFunction("concat",arguments)},c.prototype.join=function(a){return this.wrapReadFunction("join",arguments)},c.prototype.slice=function(a,b){return this.wrapReadFunction("slice",arguments)},c.prototype.indexOf=function(a,b){return this.wrapReadFunction("indexOf",arguments)},c.prototype.lastIndexOf=function(a,b){return this.wrapReadFunction("lastIndexOf",arguments)},c.prototype.every=function(a,b){return this.wrapReadFunction("every",arguments)},c.prototype.some=function(a,b){return this.wrapReadFunction("some",arguments)},c.prototype.forEach=function(a,b){return this.wrapReadFunction("forEach",arguments)},c.prototype.map=function(a,b){return this.wrapReadFunction("map",arguments)},c.prototype.filter=function(a,b){return this.wrapReadFunction("filter",arguments)},c.prototype.reduce=function(a,b){return this.wrapReadFunction("reduce",arguments)},c.prototype.reduceRight=function(a,b){return this.wrapReadFunction("reduceRight",arguments)},c.prototype.wrapReadFunction=function(a,b){var d=Array.prototype[a];return(c.prototype[a]=function(){return this.dependencyState.notifyObserved(),d.apply(this._values,arguments)}).apply(this,b)},c.prototype.sideEffectWarning=function(b){a.m.debugLevel>0&&k.trackingStack.length>0&&d("[Mobservable.Array] The method array."+b+" should probably not be used inside observable functions since it has side-effects")},c.createArrayBufferItem=function(a){var b={enumerable:!1,configurable:!1,set:function(b){if(a<this._values.length){var c=this._values[a];c!==b&&(this._values[a]=b,this.notifyChildUpdate(a,c))}else{if(a!==this._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._values.length?(this.dependencyState.notifyObserved(),this._values[a]):void 0}};Object.defineProperty(c.prototype,""+a,b),b.enumerable=!0,b.configurable=!0,c.ENUMERABLE_PROPS[a]=b},c.reserveArrayBuffer=function(a){for(var b=c.OBSERVABLE_ARRAY_BUFFER_SIZE;a>b;b++)c.createArrayBufferItem(b);c.OBSERVABLE_ARRAY_BUFFER_SIZE=a},c.OBSERVABLE_ARRAY_BUFFER_SIZE=0,c.ENUMERABLE_PROPS=[],c}(l);m.reserveArrayBuffer(1e3);var n=function(){function a(){this.listeners=[]}return a.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)}},a.prototype.on=function(a){var b=this;return this.listeners.push(a),e(function(){var c=b.listeners.indexOf(a);-1!==c&&b.listeners.splice(c,1)})},a.prototype.once=function(a){var b=this.on(function(){b(),a.apply(this,arguments)});return b},a}();a.m.SimpleEventEmitter=n;var o=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.m.ObserverMixin={componentWillMount:function(){var b=this.render;this.render=function(){var c=this;this._watchDisposer&&this._watchDisposer();var d=a.m.watch(function(){return b.call(c)},function(){c.forceUpdate()}),e=d[0],f=d[1];return this._watchDisposer=f,e}},componentWillUnmount:function(){this._watchDisposer&&this._watchDisposer()},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.m.ObservingComponent=function(b){var c=b.prototype.componentWillMount,d=b.prototype.componentWillUnmount;return b.prototype.componentWillMount=function(){a.m.ObserverMixin.componentWillMount.apply(this,arguments),c&&c.apply(this,arguments)},b.prototype.componentWillUnmount=function(){a.m.ObserverMixin.componentWillUnmount.apply(this,arguments),d&&d.apply(this,arguments)},b.prototype.shouldComponentUpdate||(b.prototype.shouldComponentUpdate=a.m.ObserverMixin.shouldComponentUpdate),b},a.m.quickDiff=c,a.m.stackDepth=function(){return k.trackingStack.length}}(mobservable||(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(){return mobservable.m});
var mobservable;!function(a){var b;!function(b){var c=function(){function c(a,c){this.value=a,this.recurse=c,this.changeEvent=new b.SimpleEventEmitter,this.dependencyState=new b.DNode(this),this._value=this.makeReferenceValueReactive(a)}return c.prototype.makeReferenceValueReactive=function(c){return this.recurse&&(Array.isArray(c)||b.isPlainObject(c))?a.makeReactive(c):c},c.prototype.set=function(a){if(a!==this._value){var b=this._value;this.dependencyState.markStale(),this._value=this.makeReferenceValueReactive(a),this.dependencyState.markReady(!0),this.changeEvent.emit(this._value,b)}},c.prototype.get=function(){return this.dependencyState.notifyObserved(),this._value},c.prototype.observe=function(a,c){var d=this;void 0===c&&(c=!1),this.dependencyState.setRefCount(1),c&&a(this.get(),void 0);var e=this.changeEvent.on(a);return b.once(function(){d.dependencyState.setRefCount(-1),e()})},c.prototype.createGetterSetter=function(){var a=this,c=function(b){return arguments.length>0?void a.set(b):a.get()};return c.impl=this,c.observe=function(b,c){return a.observe(b,c)},c.toString=function(){return a.toString()},b.markReactive(c),c},c.prototype.toString=function(){return"Observable["+this._value+"]"},c}();b.ObservableValue=c}(b=a._||(a._={}))}(mobservable||(mobservable={}));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(b){var c=function(c){function d(a,b){if(c.call(this,void 0,!1),this.func=a,this.scope=b,this.isComputing=!1,this.hasError=!1,"function"!=typeof a)throw new Error("ComputedObservable requires a function")}return __extends(d,c),d.prototype.get=function(){if(this.isComputing)throw new Error("Cycle detected");var c=this.dependencyState;if(c.isSleeping?b.DNode.trackingStack.length>0?(c.wakeUp(),c.notifyObserved()):this.compute():c.notifyObserved(),c.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},d.prototype.set=function(a){throw new Error(this.toString()+": A computed observable does not accept new values!")},d.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},d.prototype.toString=function(){return"ComputedObservable["+this.func.toString()+"]"},d}(b.ObservableValue);b.ComputedObservable=c}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(b){function c(){return e.trackingStack.length}!function(a){a[a.STALE=0]="STALE",a[a.PENDING=1]="PENDING",a[a.READY=2]="READY"}(b.DNodeState||(b.DNodeState={}));var d=b.DNodeState,e=function(){function c(a){this.owner=a,this.state=d.READY,this.isSleeping=!0,this.hasCycle=!1,this.observing=[],this.prevObserving=null,this.observers=[],this.dependencyChangeCount=0,this.dependencyStaleCount=0,this.isDisposed=!1,this.externalRefenceCount=0,this.isComputed=void 0!==a.compute}return c.prototype.setRefCount=function(a){var b=this.externalRefenceCount+=a;0===b?this.tryToSleep():b===a&&this.wakeUp()},c.prototype.addObserver=function(a){this.observers[this.observers.length]=a},c.prototype.removeObserver=function(a){var b=this.observers,c=b.indexOf(a);-1!==c&&(b.splice(c,1),0===b.length&&this.tryToSleep())},c.prototype.markStale=function(){this.state===d.READY&&(this.state=d.STALE,this.notifyObservers())},c.prototype.markReady=function(a){this.state!==d.READY&&(this.state=d.READY,this.notifyObservers(a))},c.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)},c.prototype.tryToSleep=function(){if(!this.isSleeping&&this.isComputed&&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}},c.prototype.wakeUp=function(){this.isSleeping&&this.isComputed&&(this.isSleeping=!1,this.state=d.PENDING,this.computeNextState())},c.prototype.notifyStateChange=function(a,c){var e=this;a.state===d.STALE?1===++this.dependencyStaleCount&&this.markStale():(c&&(this.dependencyChangeCount+=1),0===--this.dependencyStaleCount&&(this.state=d.PENDING,b.Scheduler.schedule(function(){e.dependencyChangeCount>0?e.computeNextState():e.markReady(!1),e.dependencyChangeCount=0})))},c.prototype.computeNextState=function(){this.trackDependencies();var a=this.owner.compute();this.bindDependencies(),this.markReady(a)},c.prototype.trackDependencies=function(){this.prevObserving=this.observing,c.trackingStack[c.trackingStack.length]=[]},c.prototype.bindDependencies=function(){this.observing=c.trackingStack.pop(),this.isComputed&&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 d=b.quickDiff(this.observing,this.prevObserving),e=d[0],f=d[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++)this.isComputed&&e[g].findCycle(this)?(this.hasCycle=!0,this.observing.splice(this.observing.indexOf(e[g]),1),e[g].hasCycle=!0):e[g].addObserver(this)},c.prototype.notifyObserved=function(){var a=c.trackingStack,b=a.length;if(b>0){var d=a[b-1],e=d.length;d[e-1]!==this&&d[e-2]!==this&&(d[e]=this)}},c.prototype.findCycle=function(a){var b=this.observing;if(-1!==b.indexOf(a))return!0;for(var c=b.length,d=0;c>d;d++)if(b[d].findCycle(a))return!0;return!1},c.prototype.dispose=function(){if(this.observers.length)throw new Error("Cannot dispose DNode; it is still being observed");if(this.observing)for(var a=this.observing.length,b=0;a>b;b++)this.observing[b].removeObserver(this);this.observing=null,this.isDisposed=!0},c.trackingStack=[],c}();b.DNode=e,b.stackDepth=c}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){function b(a,b){if(e(a))return a;b=b||{},a instanceof v.AsReference&&(a=a.value,b.as="reference");var d=b.recurse!==!1,f="reference"===b.as?u.Reference:c(a);switch(f){case u.Reference:case u.ComplexObject:return v.makeReactiveReference(a,!1);case u.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 u.ViewFunction:return new v.ComputedObservable(a,b.scope).createGetterSetter();case u.Array:return new v.ObservableArray(a,d);case u.PlainObject:return v.makeReactiveObject({},a,d)}throw"Illegal State"}function c(a){return null===a||void 0===a?u.Reference:"function"==typeof a?a.length?u.ComplexFunction:u.ViewFunction:Array.isArray(a)||a instanceof v.ObservableArray?u.Array:"object"==typeof a?v.isPlainObject(a)?u.PlainObject:u.ComplexObject:u.Reference}function d(a){return new v.AsReference(a)}function e(a){if(null===a||void 0===a)return!1;switch(typeof a){case"array":case"object":case"function":return a.__isReactive===!0}return!1}function f(a,b){var c=new v.ComputedObservable(a,b),d=c.observe(v.noop);return 0===c.dependencyState.observing.length&&v.warn("mobservable.sideEffect: not a single observable was used inside the side-effect function. Side-effect would be a no-op."),d}function g(a,b){v.makeReactiveObject(a,b,!0)}function h(a,b,c){var d=c?c.value:null;"function"==typeof d?(delete c.value,delete c.writable,c.configurable=!0,c.get=function(){var a=this.key=new v.ComputedObservable(d,this).createGetterSetter();return a},c.set=function(){throw console.trace(),new Error("It is not allowed to reassign observable functions")}):Object.defineProperty(a,b,{configurable:!0,enumberable:!0,get:function(){return v.makeReactiveObjectProperty(this,b,void 0,!0),this[b]},set:function(a){v.makeReactiveObjectProperty(this,b,a,!0)}})}function i(a){if(!a)return a;if(Array.isArray(a)||a instanceof v.ObservableArray)return a.map(i);if("object"==typeof a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=i(a[c]));return b}return a}function j(a){return v.Scheduler.batch(a)}function k(a,b){var c=new v.WatchedExpression(a,b);return[c.value,function(){return c.dispose()}]}function l(a,c){return v.deprecated("value"),b(a,{scope:c})}function m(a){return v.deprecated("reference"),b(a,{as:"reference"})}function n(a,c){return v.deprecated("computed"),b(a,{scope:c})}function o(a,b){if(v.deprecated("expr"),0===v.DNode.trackingStack.length)throw new Error("mobservable.expr can only be used inside a computed observable. Probably mobservable.computed should be used instead of .expr");return new v.ComputedObservable(a,b).get()}function p(a){return v.deprecated("array"),new v.ObservableArray(a,!1)}function q(a,b,c){switch(v.deprecated("props"),arguments.length){case 1:return v.makeReactiveObject(a,a,!1);case 2:return v.makeReactiveObject(a,b,!1);case 3:return v.makeReactiveObject(a,(d={},d[b]=c,d),!1)}throw"Illegal invocation";var d}function r(a){return v.deprecated("fromJson"),b(a)}function s(a){if(v.deprecated("toPlainValue"),a){if(a instanceof Array)return a.slice();if(a instanceof v.ObservableValue)return a.get();if("function"==typeof a&&a.impl){if(a.impl instanceof v.ObservableValue)return a();if(a.impl instanceof v.ObservableArray)return a().slice()}else if("object"==typeof a){var b={};for(var c in a)b[c]=s(a[c]);return b}}return a}function t(a,b,c,d){if(void 0===d&&(d=!1),v.deprecated("observeProperty"),!a)throw new Error("Cannot observe property of '"+a+"'");if(!(b in a))throw new Error("Object '"+a+"' has no property '"+b+"'.");if(!c||"function"!=typeof c)throw new Error("Third argument to mobservable.observeProperty should be a function");return f(function(){c(a[b])})}var u;!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"}(u||(u={})),a.makeReactive=b,a.asReference=d;var v;!function(a){function b(a){-1===k.indexOf(a)&&(k.push(a),console.warn("The method '"+a+"' has been deprecated, for any questions or suggestions, see: https://github.com/mweststrate/mobservable/issues/11"),console.trace())}function d(a,c){return function(){return b(a),c.apply(null,arguments)}}function f(a,b,c){j(a);for(var d in b)g(a,d,b[d],c);return a}function g(b,d,e,f){var g;e instanceof l?(e=e.value,g=u.Reference,f=!1):g=c(e);var h;switch(g){case u.Reference:case u.ComplexObject:h=i(e,!1);break;case u.ViewFunction:h=new a.ComputedObservable(e,b).createGetterSetter();break;case u.ComplexFunction:a.warn("Storing reactive functions in objects is not supported yet, please use flag 'recurse:false' or wrap the function in 'asReference'"),h=i(e,!1);case u.Array:case u.PlainObject:h=i(e,f)}return Object.defineProperty(b,d,{get:h,set:h,enumerable:!0,configurable:!1}),b}function h(b){if(e(b))return b;if(b instanceof l)return b=b.value;switch(c(b)){case u.Reference:case u.ComplexObject:return b;case u.ViewFunction:case u.ComplexFunction:return a.warn("Storing reactive functions in arrays is not supported, please use flag 'recurse:false' or wrap the function in 'asReference'"),b;case u.Array:return new a.ObservableArray(b,!0);case u.PlainObject:return a.makeReactiveObject({},b,!0)}throw"Illegal State"}function i(b,c){return new a.ObservableValue(b,c).createGetterSetter()}function j(a){Object.defineProperty(a,"__isReactive",{enumerable:!1,value:!0})}var k=[];a.deprecated=b,a.wrapDeprecated=d,a.makeReactiveObject=f,a.makeReactiveObjectProperty=g,a.makeReactiveArrayItem=h,a.makeReactiveReference=i,a.markReactive=j;var l=function(){function a(a){this.value=a}return a}();a.AsReference=l}(v=a._||(a._={})),a.isReactive=e,a.sideEffect=f,a.defineReactiveProperties=g,a.observable=h,a.toJson=i,a.transaction=j,a.observeUntilInvalid=k,a.watch=v.wrapDeprecated("watch",k),a.batch=v.wrapDeprecated("batch",j),a.value=l,a.reference=m,a.primitive=v.wrapDeprecated("primitive",m),a.computed=n,a.expr=o,a.array=p,a.props=q,a.fromJson=r,a.toPlainValue=s,a.observeProperty=t,a.debugLevel=0}(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._values.length){var c=this._values[a];c!==b&&(this._values[a]=b,this.notifyChildUpdate(a,c))}else{if(a!==this._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._values.length?(this.dependencyState.notifyObserved(),this._values[a]):void 0}};Object.defineProperty(f.prototype,""+a,b),b.enumerable=!0,b.configurable=!0,h[a]=b}function d(a){for(var b=g;a>b;b++)c(b);g=a}var e=function(){function a(){}return a}();e.prototype=[];var f=function(c){function e(a,d){c.call(this),b.markReactive(this),Object.defineProperties(this,{recurse:{enumerable:!1,value:d},dependencyState:{enumerable:!1,value:new b.DNode(this)},_values:{enumerable:!1,value:a?d?a.map(b.makeReactiveArrayItem):a.slice():[]},changeEvent:{enumerable:!1,value:new b.SimpleEventEmitter}}),a&&a.length&&this.updateLength(0,a.length)}return __extends(e,c),Object.defineProperty(e.prototype,"length",{get:function(){return this.dependencyState.notifyObserved(),this._values.length},set:function(a){if("number"!=typeof a||0>a)throw new Error("Out of range: "+a);var b=this._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>g&&d(a+b);for(var c=a,e=a+b;e>c;c++)Object.defineProperty(this,""+c,h[c])}},e.prototype.spliceWithArray=function(a,c,d){var e=this._values.length;if(!(void 0!==d&&0!==d.length||0!==c&&0!==e))return[];void 0===a?a=0:a>e?a=e:0>a&&(a=Math.max(0,e+a)),c=1===arguments.length?e-a:void 0===c||null===c?0:Math.max(0,Math.min(c,e-a)),void 0===d?d=[]:this.recurse&&(d=d.map(b.makeReactiveArrayItem));var f=d.length-c,g=(h=this._values).splice.apply(h,[a,c].concat(d));return this.updateLength(e,f),this.notifySplice(a,g,d),g;var h},e.prototype.notifyChildUpdate=function(a,b){this.notifyChanged(),this.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.changeEvent.emit({object:this,type:"splice",index:a,addedCount:c.length,removed:b}))},e.prototype.notifyChanged=function(){this.dependencyState.markStale(),this.dependencyState.markReady(!0)},e.prototype.observe=function(a,b){return void 0===b&&(b=!1),b&&a({object:this,type:"splice",index:0,addedCount:this._values.length,removed:[]}),this.changeEvent.on(a)},e.prototype.clear=function(){return this.splice(0)},e.prototype.replace=function(a){return this.spliceWithArray(0,this._values.length,a)},e.prototype.values=function(){return this.dependencyState.notifyObserved(),this._values.slice()},e.prototype.toJSON=function(){return this.dependencyState.notifyObserved(),this._values.slice()},e.prototype.clone=function(){return this.dependencyState.notifyObserved(),new e(this._values,this.recurse)},e.prototype.find=function(a,b,c){void 0===c&&(c=0),this.dependencyState.notifyObserved();for(var d=this._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.sideEffectWarning("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.sideEffectWarning("push"),this.spliceWithArray(this._values.length,0,a),this._values.length},e.prototype.pop=function(){return this.sideEffectWarning("pop"),this.splice(Math.max(this._values.length-1,0),1)[0]},e.prototype.shift=function(){return this.sideEffectWarning("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.sideEffectWarning("unshift"),this.spliceWithArray(0,0,a),this._values.length},e.prototype.reverse=function(){return this.sideEffectWarning("reverse"),this.replace(this._values.reverse())},e.prototype.sort=function(a){return this.sideEffectWarning("sort"),this.replace(this._values.sort.apply(this._values,arguments))},e.prototype.remove=function(a){this.sideEffectWarning("remove");var b=this._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.dependencyState.notifyObserved(),c.apply(this._values,arguments)}).apply(this,b)},e.prototype.sideEffectWarning=function(c){a.debugLevel>0&&b.DNode.trackingStack.length>0&&b.warn("[Mobservable.Array] The method array."+c+" should probably not be used inside observable functions since it has side-effects")},e}(e);b.ObservableArray=f;var g=0,h=[];d(1e3)}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){function b(b){var c=b.prototype.componentWillMount,d=b.prototype.componentWillUnmount;return b.prototype.componentWillMount=function(){a.ObserverMixin.componentWillMount.apply(this,arguments),c&&c.apply(this,arguments)},b.prototype.componentWillUnmount=function(){a.ObserverMixin.componentWillUnmount.apply(this,arguments),d&&d.apply(this,arguments)},b.prototype.shouldComponentUpdate||(b.prototype.shouldComponentUpdate=a.ObserverMixin.shouldComponentUpdate),b}a.reactiveMixin={componentWillMount:function(){var b=this.render;this.render=function(){var c=this;this._watchDisposer&&this._watchDisposer();var d=a.observeUntilInvalid(function(){return b.call(c)},function(){c.forceUpdate()}),e=d[0],f=d[1];return this._watchDisposer=f,e}},componentWillUnmount:function(){this._watchDisposer&&this._watchDisposer()},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.ObserverMixin=a.reactiveMixin,a.reactiveComponent=b,a.ObservingComponent=a._.wrapDeprecated("ObservingComponent",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){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){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.warn=b,a.once=c,a.noop=d,a.isPlainObject=e,a.quickDiff=f}(b=a._||(a._={}))}(mobservable||(mobservable={}));var mobservable;!function(a){var b;!function(a){var b=function(){function b(b,c){this.expr=b,this.onInvalidate=c,this.dependencyState=new a.DNode(this),this.didEvaluate=!1,this.dependencyState.computeNextState()}return b.prototype.compute=function(){return this.didEvaluate?(this.dispose(),this.onInvalidate()):(this.didEvaluate=!0,this.value=this.expr()),!1},b.prototype.dispose=function(){this.dependencyState.dispose()},b}();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;for(var b in mobservable)a[b]=mobservable[b];return a});
{
"name": "mobservable",
"version": "0.5.9",
"description": "Library to create reactive data structures and functions. Tracks and updates inter-data dependencies automatically.",
"version": "0.5.10",
"description": "unobtrusive library to make data structures reactive and create seamlessly self-updating view functions",
"main": "dist/mobservable.js",

@@ -30,15 +30,2 @@ "scripts": {

},
"testling": {
"files": "test/browser/test.js",
"browsers": [
"ie/6..latest",
"chrome/22..latest",
"firefox/16..latest",
"safari/latest",
"opera/11.0..latest",
"iphone/6",
"ipad/6",
"android-browser/latest"
]
},
"keywords": [

@@ -45,0 +32,0 @@ "mobservable",

@@ -123,3 +123,3 @@ # mobservable

```typescript
/// <reference path="./node_modules/mobservable/mobservable.d.ts"/>
/// <reference path="./node_modules/mobservable/dist/mobservable.d.ts"/>
import {observable, sideEffect} from "mobservable";

@@ -240,3 +240,3 @@

The [Typescript typings](https://github.com/mweststrate/mobservable/blob/master/mobservable.d.ts) serve as offline API documentation.
The [Typescript typings](https://github.com/mweststrate/mobservable/blob/master/dist/mobservable.d.ts) serve as offline API documentation.

@@ -456,3 +456,3 @@ ## Creating observables

```typescript
/// <reference path='./node_modules/mobservable/mobservable.d.ts'/>
/// <reference path='./node_modules/mobservable/dist/mobservable.d.ts'/>
import {observable} from 'mobservable';

@@ -459,0 +459,0 @@

Sorry, the diff of this file is not supported yet

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