Socket
Socket
Sign inDemoInstall

@nx-js/observer-util

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nx-js/observer-util - npm Package Compare versions

Comparing version 3.1.4 to 4.0.0

379

dist/cjs.es5.js

@@ -170,202 +170,132 @@ 'use strict';

function has(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.has.apply(this, arguments);
var instrumentations = {
has: function has(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
},
get: function get(key) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
},
add: function add(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = !proto.has.call(rawContext, value);
var result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
set: function set(key, value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = proto.get.call(rawContext, key) !== value;
var result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
delete: function delete$1(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = proto.has.call(rawContext, value);
var result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
clear: function clear() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = rawContext.size !== 0;
var result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
forEach: function forEach() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
},
keys: function keys() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
},
values: function values() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
},
entries: function entries() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
},
get size() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
}
};
instrumentations[Symbol.iterator] = function () {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
};
function get(key) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.get.apply(this, arguments);
var collectionHandlers = {
get: function get(target, key, receiver) {
// instrument methods and property accessors to be reactive
target = key in getPrototypeOf(target) ? instrumentations : target;
return Reflect.get(target, key, receiver);
}
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
}
};
function add(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.add.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = !proto.has.call(rawContext, value);
var result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// simple objects are not wrapped by Proxies, neither instrumented
var dontInstrument = new Set([Date, RegExp]);
function set(key, value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.set.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = proto.get.call(rawContext, key) !== value;
var result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' instead of the Proxy wrapper
// complex objects are wrapped with a Proxy of instrumented methods
// which switch the proxy to the raw object and to add reactive wiring
var handlers = new Map([[Map, collectionHandlers], [Set, collectionHandlers], [WeakMap, collectionHandlers], [WeakSet, collectionHandlers]]);
function deleteFn(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.delete.apply(this, arguments);
function shouldInstrument(obj) {
if (typeof Node === 'function' && obj instanceof Node) {
return false;
}
// forward the operation before queueing reactions
var valueChanged = proto.has.call(rawContext, value);
var result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
return !dontInstrument.has(obj.constructor);
}
function clear() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.clear.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = rawContext.size !== 0;
var result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
function getHandlers(obj) {
return handlers.get(obj.constructor);
}
function forEach() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.forEach.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
}
function keys() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.keys.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
}
function values() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.values.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
}
function entries() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.entries.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
}
function iterator() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto[Symbol.iterator].apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
}
function getSize() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return Reflect.get(proto, 'size', this);
}
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
function instrumentMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
map.clear = clear;
map.forEach = forEach;
map.keys = keys;
map.values = values;
map.entries = entries;
map[Symbol.iterator] = iterator;
Object.defineProperty(map, 'size', { get: getSize });
}
function instrumentSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
set$$1.clear = clear;
set$$1.forEach = forEach;
set$$1.keys = keys;
set$$1.values = values;
set$$1.entries = entries;
set$$1[Symbol.iterator] = iterator;
Object.defineProperty(set$$1, 'size', { get: getSize });
}
function instrumentWeakMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
}
function instrumentWeakSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' and when a Proxy instance is passed instead they break
// simple objects are not wrapped by Proxies or instrumented
// complex objects are wrapped and their methods are monkey patched
// to switch the proxy to the raw object and to add reactive wiring
var instrumentations = new Map([[Map.prototype, instrumentMap], [Set.prototype, instrumentSet], [WeakMap.prototype, instrumentWeakMap], [WeakSet.prototype, instrumentWeakSet], [Date.prototype, false], [RegExp.prototype, false]]);
var ENUMERATE = Symbol('enumerate');
// intercept get operations on observables to know which reaction uses their properties
function get$1(obj, key, receiver) {
// make sure to use the raw object here
var rawObj = proxyToRaw.get(obj) || obj;
// expose the raw object on observable.$raw
if (key === '$raw') {
return rawObj;
}
function get(obj, key, receiver) {
var result = Reflect.get(obj, key, receiver);

@@ -376,4 +306,6 @@ // do not register (observable.prop -> reaction) pairs for these cases

}
// make sure to use the raw object here, obj might be a Proxy because of inheritance
obj = proxyToRaw.get(obj) || obj;
// register and save (observable.prop -> runningReaction)
registerRunningReactionForKey(rawObj, key);
registerRunningReactionForKey(obj, key);
// if we are inside a reaction and observable.prop is an object wrap it in an observable too

@@ -394,3 +326,3 @@ // this is needed to intercept property access on that object too (dynamic observable tree)

// intercept set operations on observables to know when to trigger reactions
function set$1(obj, key, value, receiver) {
function set(obj, key, value, receiver) {
// make sure to do not pollute the raw object with observables

@@ -401,6 +333,9 @@ if (typeof value === 'object' && value !== null) {

// save if the value changed because of this set operation
// array 'length' is an exception here, because of it's exotic nature
var valueChanged = key === 'length' || value !== obj[key];
var valueChanged = value !== obj[key];
// length is lazy, it can change without an explicit length set operation
var prevLength = Array.isArray(obj) && obj.length;
// execute the set operation before running any reaction
var result = Reflect.set(obj, key, value, receiver);
// check if the length changed implicitly, because of out of bound set operations
var lengthChanged = prevLength !== false && prevLength !== obj.length;
// emit a warning and do not queue anything when another reaction is queued

@@ -412,9 +347,17 @@ // from an already running reaction

}
// if the target of the operation is not the raw receiver return
// (possible because of prototypal inheritance)
if (obj !== proxyToRaw.get(receiver)) {
return result;
}
// do not queue reactions if it is a symbol keyed property
// or the set operation resulted in no value change
// or if the target of the operation is not the raw object (possible because of prototypal inheritance)
if (typeof key !== 'symbol' && valueChanged && obj === proxyToRaw.get(receiver)) {
if (typeof key !== 'symbol' && valueChanged) {
queueReactionsForKey(obj, key);
queueReactionsForKey(obj, ENUMERATE);
}
// queue length reactions in case the length changed
if (lengthChanged) {
queueReactionsForKey(obj, 'length');
}
return result;

@@ -436,11 +379,4 @@ }

var handlers = { get: get$1, ownKeys: ownKeys, set: set$1, deleteProperty: deleteProperty };
var baseHandlers = { get: get, ownKeys: ownKeys, set: set, deleteProperty: deleteProperty };
function isObservable(obj) {
if (typeof obj !== 'object') {
throw new TypeError('First argument must be an object');
}
return proxyToRaw.has(obj);
}
function observable(obj) {

@@ -452,37 +388,31 @@ if ( obj === void 0 ) obj = {};

}
// if it is already an observable, return it
if (proxyToRaw.has(obj)) {
// if it is already an observable or it should not be wrapped, return it
if (proxyToRaw.has(obj) || !shouldInstrument(obj)) {
return obj;
}
return (
// if it already has a cached observable wrapper, return it
// if it is a special built-in object, instrument it then wrap it with an observable
// otherwise simply wrap the object with an observable
rawToProxy.get(obj) || instrumentObservable(obj) || createObservable(obj)
);
// if it already has a cached observable wrapper, return it
// otherwise create a new observable
return rawToProxy.get(obj) || createObservable(obj);
}
function instrumentObservable(obj) {
var instrument = instrumentations.get(Object.getPrototypeOf(obj));
// these objects break, when they are wrapped with proxies
if (instrument === false) {
return obj;
}
// these objects can be wrapped by Proxies, but require special instrumentation beforehand
if (typeof instrument === 'function') {
instrument(obj);
}
}
// wrap the object in a Proxy and save the obj-proxy, proxy-obj pairs
function createObservable(obj) {
// if it is a complex built-in object or a normal object, wrap it
var handlers = getHandlers(obj) || baseHandlers;
var observable = new Proxy(obj, handlers);
// save these to switch between the raw object and the wrapped object with ease later
rawToProxy.set(obj, observable);
proxyToRaw.set(observable, obj);
// init basic data structures to save and cleanup later (observable.prop -> reaction) connections
storeObservable(obj);
// save these to switch between the raw object and the wrapped object with ease later
proxyToRaw.set(observable, obj);
rawToProxy.set(obj, observable);
return observable;
}
function isObservable(obj) {
return proxyToRaw.has(obj);
}
function raw(obj) {
return proxyToRaw.get(obj) || obj;
}
exports.observe = observe;

@@ -492,1 +422,2 @@ exports.unobserve = unobserve;

exports.isObservable = isObservable;
exports.raw = raw;

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

'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){var d=connectionStore.get(a),e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){var d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}var runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error('Unobserved reactions can not be executed. You tried to run a reaction for '+b);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}var IS_REACTION=Symbol('is reaction');function observe(a,b){function c(){return runAsReaction(c,a,this,arguments)}if(void 0===b&&(b={}),'function'!=typeof a)throw new TypeError('The first argument must be a function instead of '+a);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError('The second argument must be an options object instead of '+b);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions(a){var b=a.lazy;void 0===b&&(b=!1);var c=a.scheduler;if('boolean'!=typeof b)throw new TypeError('options.lazy must be a boolean or undefined instead of '+b);if('object'==typeof c&&null!==c){if('function'!=typeof c.add||'function'!=typeof c.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==c&&'function'!=typeof c)throw new TypeError('options.scheduler must be a function, an object or undefined instead of '+c)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError('The first argument must be a reaction instead of '+a);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}var proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf;function has(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.has.apply(b,arguments)):c.has.apply(this,arguments)}function get(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.get.apply(b,arguments)):c.get.apply(this,arguments)}function add(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.add.apply(this,arguments);var d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function set(a,b){var c=proxyToRaw.get(this),d=getPrototypeOf(this);if(!c)return d.set.apply(this,arguments);var e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(queueReactionsForKey(c,a),queueReactionsForKey(c,ITERATE)),f}function deleteFn(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.delete.apply(this,arguments);var d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function clear(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);if(!a)return b.clear.apply(this,arguments);var c=0!==a.size,d=b.clear.apply(a,arguments);return c&&queueReactionsForKey(a,ITERATE),d}function forEach(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.forEach.apply(a,arguments)):b.forEach.apply(this,arguments)}function keys(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.keys.apply(a,arguments)):b.keys.apply(this,arguments)}function values(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.values.apply(a,arguments)):b.values.apply(this,arguments)}function entries(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.entries.apply(a,arguments)):b.entries.apply(this,arguments)}function iterator(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)):b[Symbol.iterator].apply(this,arguments)}function getSize(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)):Reflect.get(b,'size',this)}function instrumentMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentSet(a){a.has=has,a.add=add,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentWeakMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn}function instrumentWeakSet(a){a.has=has,a.add=add,a.delete=deleteFn}var instrumentations=new Map([[Map.prototype,instrumentMap],[Set.prototype,instrumentSet],[WeakMap.prototype,instrumentWeakMap],[WeakSet.prototype,instrumentWeakSet],[Date.prototype,!1],[RegExp.prototype,!1]]),ENUMERATE=Symbol('enumerate');function get$1(a,b,c){var d=proxyToRaw.get(a)||a;if('$raw'===b)return d;var e=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof e?e:(registerRunningReactionForKey(d,b),hasRunningReaction()&&'object'==typeof e&&null!==e?observable(e):rawToProxy.get(e)||e)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set$1(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);var e='length'===b||c!==a[b],f=Reflect.set(a,b,c,d);return hasRunningReaction()?(console.error('Mutating observables in reactions is forbidden. You set '+b+' to '+c+'.'),f):('symbol'!=typeof b&&e&&a===proxyToRaw.get(d)&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),f)}function deleteProperty(a,b){var c=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&b in a&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),c}var handlers={get:get$1,ownKeys:ownKeys,set:set$1,deleteProperty:deleteProperty};function isObservable(a){if('object'!=typeof a)throw new TypeError('First argument must be an object');return proxyToRaw.has(a)}function observable(a){if(void 0===a&&(a={}),'object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)?a:rawToProxy.get(a)||instrumentObservable(a)||createObservable(a)}function instrumentObservable(a){var b=instrumentations.get(Object.getPrototypeOf(a));return!1===b?a:void('function'==typeof b&&b(a))}function createObservable(a){var b=new Proxy(a,handlers);return storeObservable(a),proxyToRaw.set(b,a),rawToProxy.set(a,b),b}exports.observe=observe,exports.unobserve=unobserve,exports.observable=observable,exports.isObservable=isObservable;
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){var d=connectionStore.get(a),e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){var d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}var runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error('Unobserved reactions can not be executed. You tried to run a reaction for '+b);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}var IS_REACTION=Symbol('is reaction');function observe(a,b){function c(){return runAsReaction(c,a,this,arguments)}if(void 0===b&&(b={}),'function'!=typeof a)throw new TypeError('The first argument must be a function instead of '+a);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError('The second argument must be an options object instead of '+b);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions(a){var b=a.lazy;void 0===b&&(b=!1);var c=a.scheduler;if('boolean'!=typeof b)throw new TypeError('options.lazy must be a boolean or undefined instead of '+b);if('object'==typeof c&&null!==c){if('function'!=typeof c.add||'function'!=typeof c.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==c&&'function'!=typeof c)throw new TypeError('options.scheduler must be a function, an object or undefined instead of '+c)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError('The first argument must be a reaction instead of '+a);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}var proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf,instrumentations={has:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this);return registerRunningReactionForKey(c,b),d.has.apply(c,arguments)},get:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this);return registerRunningReactionForKey(c,b),d.get.apply(c,arguments)},add:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this),e=!d.has.call(c,b),f=d.add.apply(c,arguments);return e&&(queueReactionsForKey(c,b),queueReactionsForKey(c,ITERATE)),f},set:function a(b,c){var d=proxyToRaw.get(this),e=getPrototypeOf(this),f=e.get.call(d,b)!==c,g=e.set.apply(d,arguments);return f&&(queueReactionsForKey(d,b),queueReactionsForKey(d,ITERATE)),g},delete:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this),e=d.has.call(c,b),f=d.delete.apply(c,arguments);return e&&(queueReactionsForKey(c,b),queueReactionsForKey(c,ITERATE)),f},clear:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this),d=0!==b.size,e=c.clear.apply(b,arguments);return d&&queueReactionsForKey(b,ITERATE),e},forEach:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.forEach.apply(b,arguments)},keys:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.keys.apply(b,arguments)},values:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.values.apply(b,arguments)},entries:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.entries.apply(b,arguments)},get size(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)}};instrumentations[Symbol.iterator]=function(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)};var collectionHandlers={get:function a(b,c,d){return b=c in getPrototypeOf(b)?instrumentations:b,Reflect.get(b,c,d)}},dontInstrument=new Set([Date,RegExp]),handlers=new Map([[Map,collectionHandlers],[Set,collectionHandlers],[WeakMap,collectionHandlers],[WeakSet,collectionHandlers]]);function shouldInstrument(a){return'function'==typeof Node&&a instanceof Node?!1:!dontInstrument.has(a.constructor)}function getHandlers(a){return handlers.get(a.constructor)}var ENUMERATE=Symbol('enumerate');function get(a,b,c){var d=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof d?d:(a=proxyToRaw.get(a)||a,registerRunningReactionForKey(a,b),hasRunningReaction()&&'object'==typeof d&&null!==d?observable(d):rawToProxy.get(d)||d)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);var e=c!==a[b],f=Array.isArray(a)&&a.length,g=Reflect.set(a,b,c,d),h=!1!==f&&f!==a.length;return hasRunningReaction()?(console.error('Mutating observables in reactions is forbidden. You set '+b+' to '+c+'.'),g):a===proxyToRaw.get(d)?('symbol'!=typeof b&&e&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),h&&queueReactionsForKey(a,'length'),g):g}function deleteProperty(a,b){var c=b in a,d=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&c&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),d}var baseHandlers={get:get,ownKeys:ownKeys,set:set,deleteProperty:deleteProperty};function observable(a){if(void 0===a&&(a={}),'object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)||!shouldInstrument(a)?a:rawToProxy.get(a)||createObservable(a)}function createObservable(a){var b=getHandlers(a)||baseHandlers,c=new Proxy(a,b);return rawToProxy.set(a,c),proxyToRaw.set(c,a),storeObservable(a),c}function isObservable(a){return proxyToRaw.has(a)}function raw(a){return proxyToRaw.get(a)||a}exports.observe=observe,exports.unobserve=unobserve,exports.observable=observable,exports.isObservable=isObservable,exports.raw=raw;

@@ -165,202 +165,132 @@ 'use strict';

function has(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.has.apply(this, arguments);
const instrumentations = {
has(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
},
get(key) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
},
add(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = !proto.has.call(rawContext, value);
const result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
set(key, value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = proto.get.call(rawContext, key) !== value;
const result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
delete(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = proto.has.call(rawContext, value);
const result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
clear() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = rawContext.size !== 0;
const result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
forEach() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
},
keys() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
},
values() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
},
entries() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
},
[Symbol.iterator]() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
},
get size() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
}
};
function get(key) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.get.apply(this, arguments);
var collectionHandlers = {
get(target, key, receiver) {
// instrument methods and property accessors to be reactive
target = key in getPrototypeOf(target) ? instrumentations : target;
return Reflect.get(target, key, receiver);
}
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
}
};
function add(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.add.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = !proto.has.call(rawContext, value);
const result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// simple objects are not wrapped by Proxies, neither instrumented
const dontInstrument = new Set([Date, RegExp]);
function set(key, value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.set.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = proto.get.call(rawContext, key) !== value;
const result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' instead of the Proxy wrapper
// complex objects are wrapped with a Proxy of instrumented methods
// which switch the proxy to the raw object and to add reactive wiring
const handlers = new Map([[Map, collectionHandlers], [Set, collectionHandlers], [WeakMap, collectionHandlers], [WeakSet, collectionHandlers]]);
function deleteFn(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.delete.apply(this, arguments);
function shouldInstrument(obj) {
if (typeof Node === 'function' && obj instanceof Node) {
return false;
}
// forward the operation before queueing reactions
const valueChanged = proto.has.call(rawContext, value);
const result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
return !dontInstrument.has(obj.constructor);
}
function clear() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.clear.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = rawContext.size !== 0;
const result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
function getHandlers(obj) {
return handlers.get(obj.constructor);
}
function forEach() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.forEach.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
}
function keys() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.keys.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
}
function values() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.values.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
}
function entries() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.entries.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
}
function iterator() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto[Symbol.iterator].apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
}
function getSize() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return Reflect.get(proto, 'size', this);
}
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
function instrumentMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
map.clear = clear;
map.forEach = forEach;
map.keys = keys;
map.values = values;
map.entries = entries;
map[Symbol.iterator] = iterator;
Object.defineProperty(map, 'size', { get: getSize });
}
function instrumentSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
set$$1.clear = clear;
set$$1.forEach = forEach;
set$$1.keys = keys;
set$$1.values = values;
set$$1.entries = entries;
set$$1[Symbol.iterator] = iterator;
Object.defineProperty(set$$1, 'size', { get: getSize });
}
function instrumentWeakMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
}
function instrumentWeakSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' and when a Proxy instance is passed instead they break
// simple objects are not wrapped by Proxies or instrumented
// complex objects are wrapped and their methods are monkey patched
// to switch the proxy to the raw object and to add reactive wiring
var instrumentations = new Map([[Map.prototype, instrumentMap], [Set.prototype, instrumentSet], [WeakMap.prototype, instrumentWeakMap], [WeakSet.prototype, instrumentWeakSet], [Date.prototype, false], [RegExp.prototype, false]]);
const ENUMERATE = Symbol('enumerate');
// intercept get operations on observables to know which reaction uses their properties
function get$1(obj, key, receiver) {
// make sure to use the raw object here
const rawObj = proxyToRaw.get(obj) || obj;
// expose the raw object on observable.$raw
if (key === '$raw') {
return rawObj;
}
function get(obj, key, receiver) {
const result = Reflect.get(obj, key, receiver);

@@ -371,4 +301,6 @@ // do not register (observable.prop -> reaction) pairs for these cases

}
// make sure to use the raw object here, obj might be a Proxy because of inheritance
obj = proxyToRaw.get(obj) || obj;
// register and save (observable.prop -> runningReaction)
registerRunningReactionForKey(rawObj, key);
registerRunningReactionForKey(obj, key);
// if we are inside a reaction and observable.prop is an object wrap it in an observable too

@@ -389,3 +321,3 @@ // this is needed to intercept property access on that object too (dynamic observable tree)

// intercept set operations on observables to know when to trigger reactions
function set$1(obj, key, value, receiver) {
function set(obj, key, value, receiver) {
// make sure to do not pollute the raw object with observables

@@ -396,6 +328,9 @@ if (typeof value === 'object' && value !== null) {

// save if the value changed because of this set operation
// array 'length' is an exception here, because of it's exotic nature
const valueChanged = key === 'length' || value !== obj[key];
const valueChanged = value !== obj[key];
// length is lazy, it can change without an explicit length set operation
const prevLength = Array.isArray(obj) && obj.length;
// execute the set operation before running any reaction
const result = Reflect.set(obj, key, value, receiver);
// check if the length changed implicitly, because of out of bound set operations
const lengthChanged = prevLength !== false && prevLength !== obj.length;
// emit a warning and do not queue anything when another reaction is queued

@@ -407,9 +342,17 @@ // from an already running reaction

}
// if the target of the operation is not the raw receiver return
// (possible because of prototypal inheritance)
if (obj !== proxyToRaw.get(receiver)) {
return result;
}
// do not queue reactions if it is a symbol keyed property
// or the set operation resulted in no value change
// or if the target of the operation is not the raw object (possible because of prototypal inheritance)
if (typeof key !== 'symbol' && valueChanged && obj === proxyToRaw.get(receiver)) {
if (typeof key !== 'symbol' && valueChanged) {
queueReactionsForKey(obj, key);
queueReactionsForKey(obj, ENUMERATE);
}
// queue length reactions in case the length changed
if (lengthChanged) {
queueReactionsForKey(obj, 'length');
}
return result;

@@ -431,11 +374,4 @@ }

var handlers = { get: get$1, ownKeys, set: set$1, deleteProperty };
var baseHandlers = { get, ownKeys, set, deleteProperty };
function isObservable(obj) {
if (typeof obj !== 'object') {
throw new TypeError('First argument must be an object');
}
return proxyToRaw.has(obj);
}
function observable(obj = {}) {

@@ -445,37 +381,31 @@ if (typeof obj !== 'object') {

}
// if it is already an observable, return it
if (proxyToRaw.has(obj)) {
// if it is already an observable or it should not be wrapped, return it
if (proxyToRaw.has(obj) || !shouldInstrument(obj)) {
return obj;
}
return (
// if it already has a cached observable wrapper, return it
// if it is a special built-in object, instrument it then wrap it with an observable
// otherwise simply wrap the object with an observable
rawToProxy.get(obj) || instrumentObservable(obj) || createObservable(obj)
);
// if it already has a cached observable wrapper, return it
// otherwise create a new observable
return rawToProxy.get(obj) || createObservable(obj);
}
function instrumentObservable(obj) {
const instrument = instrumentations.get(Object.getPrototypeOf(obj));
// these objects break, when they are wrapped with proxies
if (instrument === false) {
return obj;
}
// these objects can be wrapped by Proxies, but require special instrumentation beforehand
if (typeof instrument === 'function') {
instrument(obj);
}
}
// wrap the object in a Proxy and save the obj-proxy, proxy-obj pairs
function createObservable(obj) {
// if it is a complex built-in object or a normal object, wrap it
const handlers = getHandlers(obj) || baseHandlers;
const observable = new Proxy(obj, handlers);
// save these to switch between the raw object and the wrapped object with ease later
rawToProxy.set(obj, observable);
proxyToRaw.set(observable, obj);
// init basic data structures to save and cleanup later (observable.prop -> reaction) connections
storeObservable(obj);
// save these to switch between the raw object and the wrapped object with ease later
proxyToRaw.set(observable, obj);
rawToProxy.set(obj, observable);
return observable;
}
function isObservable(obj) {
return proxyToRaw.has(obj);
}
function raw(obj) {
return proxyToRaw.get(obj) || obj;
}
exports.observe = observe;

@@ -485,1 +415,2 @@ exports.unobserve = unobserve;

exports.isObservable = isObservable;
exports.raw = raw;

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

'use strict';Object.defineProperty(exports,'__esModule',{value:!0});const connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){const d=connectionStore.get(a);let e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){const d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}let runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error(`Unobserved reactions can not be executed. You tried to run a reaction for ${b}`);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}const IS_REACTION=Symbol('is reaction');function observe(a,b={}){function c(){return runAsReaction(c,a,this,arguments)}if('function'!=typeof a)throw new TypeError(`The first argument must be a function instead of ${a}`);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError(`The second argument must be an options object instead of ${b}`);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions({lazy:b=!1,scheduler:a}){if('boolean'!=typeof b)throw new TypeError(`options.lazy must be a boolean or undefined instead of ${b}`);if('object'==typeof a&&null!==a){if('function'!=typeof a.add||'function'!=typeof a.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==a&&'function'!=typeof a)throw new TypeError(`options.scheduler must be a function, an object or undefined instead of ${a}`)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError(`The first argument must be a reaction instead of ${a}`);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}const proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf;function has(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.has.apply(b,arguments)):c.has.apply(this,arguments)}function get(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.get.apply(b,arguments)):c.get.apply(this,arguments)}function add(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.add.apply(this,arguments);const d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function set(a,b){const c=proxyToRaw.get(this),d=getPrototypeOf(this);if(!c)return d.set.apply(this,arguments);const e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(queueReactionsForKey(c,a),queueReactionsForKey(c,ITERATE)),f}function deleteFn(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.delete.apply(this,arguments);const d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function clear(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);if(!a)return b.clear.apply(this,arguments);const c=0!==a.size,d=b.clear.apply(a,arguments);return c&&queueReactionsForKey(a,ITERATE),d}function forEach(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.forEach.apply(a,arguments)):b.forEach.apply(this,arguments)}function keys(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.keys.apply(a,arguments)):b.keys.apply(this,arguments)}function values(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.values.apply(a,arguments)):b.values.apply(this,arguments)}function entries(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.entries.apply(a,arguments)):b.entries.apply(this,arguments)}function iterator(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)):b[Symbol.iterator].apply(this,arguments)}function getSize(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)):Reflect.get(b,'size',this)}function instrumentMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentSet(a){a.has=has,a.add=add,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentWeakMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn}function instrumentWeakSet(a){a.has=has,a.add=add,a.delete=deleteFn}var instrumentations=new Map([[Map.prototype,instrumentMap],[Set.prototype,instrumentSet],[WeakMap.prototype,instrumentWeakMap],[WeakSet.prototype,instrumentWeakSet],[Date.prototype,!1],[RegExp.prototype,!1]]);const ENUMERATE=Symbol('enumerate');function get$1(a,b,c){const d=proxyToRaw.get(a)||a;if('$raw'===b)return d;const e=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof e?e:(registerRunningReactionForKey(d,b),hasRunningReaction()&&'object'==typeof e&&null!==e?observable(e):rawToProxy.get(e)||e)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set$1(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);const e='length'===b||c!==a[b],f=Reflect.set(a,b,c,d);return hasRunningReaction()?(console.error(`Mutating observables in reactions is forbidden. You set ${b} to ${c}.`),f):('symbol'!=typeof b&&e&&a===proxyToRaw.get(d)&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),f)}function deleteProperty(a,b){const c=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&b in a&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),c}var handlers={get:get$1,ownKeys,set:set$1,deleteProperty};function isObservable(a){if('object'!=typeof a)throw new TypeError('First argument must be an object');return proxyToRaw.has(a)}function observable(a={}){if('object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)?a:rawToProxy.get(a)||instrumentObservable(a)||createObservable(a)}function instrumentObservable(a){const b=instrumentations.get(Object.getPrototypeOf(a));return!1===b?a:void('function'==typeof b&&b(a))}function createObservable(a){const b=new Proxy(a,handlers);return storeObservable(a),proxyToRaw.set(b,a),rawToProxy.set(a,b),b}exports.observe=observe,exports.unobserve=unobserve,exports.observable=observable,exports.isObservable=isObservable;
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});const connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){const d=connectionStore.get(a);let e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){const d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}let runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error(`Unobserved reactions can not be executed. You tried to run a reaction for ${b}`);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}const IS_REACTION=Symbol('is reaction');function observe(a,b={}){function c(){return runAsReaction(c,a,this,arguments)}if('function'!=typeof a)throw new TypeError(`The first argument must be a function instead of ${a}`);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError(`The second argument must be an options object instead of ${b}`);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions({lazy:b=!1,scheduler:a}){if('boolean'!=typeof b)throw new TypeError(`options.lazy must be a boolean or undefined instead of ${b}`);if('object'==typeof a&&null!==a){if('function'!=typeof a.add||'function'!=typeof a.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==a&&'function'!=typeof a)throw new TypeError(`options.scheduler must be a function, an object or undefined instead of ${a}`)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError(`The first argument must be a reaction instead of ${a}`);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}const proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf,instrumentations={has(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,a),c.has.apply(b,arguments)},get(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,a),c.get.apply(b,arguments)},add(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this),d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e},set(a,b){const c=proxyToRaw.get(this),d=getPrototypeOf(this),e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(queueReactionsForKey(c,a),queueReactionsForKey(c,ITERATE)),f},delete(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this),d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e},clear(){const a=proxyToRaw.get(this),b=getPrototypeOf(this),c=0!==a.size,d=b.clear.apply(a,arguments);return c&&queueReactionsForKey(a,ITERATE),d},forEach(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.forEach.apply(a,arguments)},keys(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.keys.apply(a,arguments)},values(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.values.apply(a,arguments)},entries(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.entries.apply(a,arguments)},[Symbol.iterator](){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)},get size(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)}};var collectionHandlers={get(a,b,c){return a=b in getPrototypeOf(a)?instrumentations:a,Reflect.get(a,b,c)}};const dontInstrument=new Set([Date,RegExp]),handlers=new Map([[Map,collectionHandlers],[Set,collectionHandlers],[WeakMap,collectionHandlers],[WeakSet,collectionHandlers]]);function shouldInstrument(a){return'function'==typeof Node&&a instanceof Node?!1:!dontInstrument.has(a.constructor)}function getHandlers(a){return handlers.get(a.constructor)}const ENUMERATE=Symbol('enumerate');function get(a,b,c){const d=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof d?d:(a=proxyToRaw.get(a)||a,registerRunningReactionForKey(a,b),hasRunningReaction()&&'object'==typeof d&&null!==d?observable(d):rawToProxy.get(d)||d)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);const e=c!==a[b],f=Array.isArray(a)&&a.length,g=Reflect.set(a,b,c,d),h=!1!==f&&f!==a.length;return hasRunningReaction()?(console.error(`Mutating observables in reactions is forbidden. You set ${b} to ${c}.`),g):a===proxyToRaw.get(d)?('symbol'!=typeof b&&e&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),h&&queueReactionsForKey(a,'length'),g):g}function deleteProperty(a,b){const c=b in a,d=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&c&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),d}var baseHandlers={get,ownKeys,set,deleteProperty};function observable(a={}){if('object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)||!shouldInstrument(a)?a:rawToProxy.get(a)||createObservable(a)}function createObservable(a){const b=getHandlers(a)||baseHandlers,c=new Proxy(a,b);return rawToProxy.set(a,c),proxyToRaw.set(c,a),storeObservable(a),c}function isObservable(a){return proxyToRaw.has(a)}function raw(a){return proxyToRaw.get(a)||a}exports.observe=observe,exports.unobserve=unobserve,exports.observable=observable,exports.isObservable=isObservable,exports.raw=raw;

@@ -166,202 +166,132 @@ var connectionStore = new WeakMap();

function has(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.has.apply(this, arguments);
var instrumentations = {
has: function has(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
},
get: function get(key) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
},
add: function add(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = !proto.has.call(rawContext, value);
var result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
set: function set(key, value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = proto.get.call(rawContext, key) !== value;
var result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
delete: function delete$1(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = proto.has.call(rawContext, value);
var result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
clear: function clear() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = rawContext.size !== 0;
var result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
forEach: function forEach() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
},
keys: function keys() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
},
values: function values() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
},
entries: function entries() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
},
get size() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
}
};
instrumentations[Symbol.iterator] = function () {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
};
function get(key) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.get.apply(this, arguments);
var collectionHandlers = {
get: function get(target, key, receiver) {
// instrument methods and property accessors to be reactive
target = key in getPrototypeOf(target) ? instrumentations : target;
return Reflect.get(target, key, receiver);
}
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
}
};
function add(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.add.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = !proto.has.call(rawContext, value);
var result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// simple objects are not wrapped by Proxies, neither instrumented
var dontInstrument = new Set([Date, RegExp]);
function set(key, value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.set.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = proto.get.call(rawContext, key) !== value;
var result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' instead of the Proxy wrapper
// complex objects are wrapped with a Proxy of instrumented methods
// which switch the proxy to the raw object and to add reactive wiring
var handlers = new Map([[Map, collectionHandlers], [Set, collectionHandlers], [WeakMap, collectionHandlers], [WeakSet, collectionHandlers]]);
function deleteFn(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.delete.apply(this, arguments);
function shouldInstrument(obj) {
if (typeof Node === 'function' && obj instanceof Node) {
return false;
}
// forward the operation before queueing reactions
var valueChanged = proto.has.call(rawContext, value);
var result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
return !dontInstrument.has(obj.constructor);
}
function clear() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.clear.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = rawContext.size !== 0;
var result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
function getHandlers(obj) {
return handlers.get(obj.constructor);
}
function forEach() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.forEach.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
}
function keys() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.keys.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
}
function values() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.values.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
}
function entries() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.entries.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
}
function iterator() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto[Symbol.iterator].apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
}
function getSize() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return Reflect.get(proto, 'size', this);
}
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
function instrumentMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
map.clear = clear;
map.forEach = forEach;
map.keys = keys;
map.values = values;
map.entries = entries;
map[Symbol.iterator] = iterator;
Object.defineProperty(map, 'size', { get: getSize });
}
function instrumentSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
set$$1.clear = clear;
set$$1.forEach = forEach;
set$$1.keys = keys;
set$$1.values = values;
set$$1.entries = entries;
set$$1[Symbol.iterator] = iterator;
Object.defineProperty(set$$1, 'size', { get: getSize });
}
function instrumentWeakMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
}
function instrumentWeakSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' and when a Proxy instance is passed instead they break
// simple objects are not wrapped by Proxies or instrumented
// complex objects are wrapped and their methods are monkey patched
// to switch the proxy to the raw object and to add reactive wiring
var instrumentations = new Map([[Map.prototype, instrumentMap], [Set.prototype, instrumentSet], [WeakMap.prototype, instrumentWeakMap], [WeakSet.prototype, instrumentWeakSet], [Date.prototype, false], [RegExp.prototype, false]]);
var ENUMERATE = Symbol('enumerate');
// intercept get operations on observables to know which reaction uses their properties
function get$1(obj, key, receiver) {
// make sure to use the raw object here
var rawObj = proxyToRaw.get(obj) || obj;
// expose the raw object on observable.$raw
if (key === '$raw') {
return rawObj;
}
function get(obj, key, receiver) {
var result = Reflect.get(obj, key, receiver);

@@ -372,4 +302,6 @@ // do not register (observable.prop -> reaction) pairs for these cases

}
// make sure to use the raw object here, obj might be a Proxy because of inheritance
obj = proxyToRaw.get(obj) || obj;
// register and save (observable.prop -> runningReaction)
registerRunningReactionForKey(rawObj, key);
registerRunningReactionForKey(obj, key);
// if we are inside a reaction and observable.prop is an object wrap it in an observable too

@@ -390,3 +322,3 @@ // this is needed to intercept property access on that object too (dynamic observable tree)

// intercept set operations on observables to know when to trigger reactions
function set$1(obj, key, value, receiver) {
function set(obj, key, value, receiver) {
// make sure to do not pollute the raw object with observables

@@ -397,6 +329,9 @@ if (typeof value === 'object' && value !== null) {

// save if the value changed because of this set operation
// array 'length' is an exception here, because of it's exotic nature
var valueChanged = key === 'length' || value !== obj[key];
var valueChanged = value !== obj[key];
// length is lazy, it can change without an explicit length set operation
var prevLength = Array.isArray(obj) && obj.length;
// execute the set operation before running any reaction
var result = Reflect.set(obj, key, value, receiver);
// check if the length changed implicitly, because of out of bound set operations
var lengthChanged = prevLength !== false && prevLength !== obj.length;
// emit a warning and do not queue anything when another reaction is queued

@@ -408,9 +343,17 @@ // from an already running reaction

}
// if the target of the operation is not the raw receiver return
// (possible because of prototypal inheritance)
if (obj !== proxyToRaw.get(receiver)) {
return result;
}
// do not queue reactions if it is a symbol keyed property
// or the set operation resulted in no value change
// or if the target of the operation is not the raw object (possible because of prototypal inheritance)
if (typeof key !== 'symbol' && valueChanged && obj === proxyToRaw.get(receiver)) {
if (typeof key !== 'symbol' && valueChanged) {
queueReactionsForKey(obj, key);
queueReactionsForKey(obj, ENUMERATE);
}
// queue length reactions in case the length changed
if (lengthChanged) {
queueReactionsForKey(obj, 'length');
}
return result;

@@ -432,11 +375,4 @@ }

var handlers = { get: get$1, ownKeys: ownKeys, set: set$1, deleteProperty: deleteProperty };
var baseHandlers = { get: get, ownKeys: ownKeys, set: set, deleteProperty: deleteProperty };
function isObservable(obj) {
if (typeof obj !== 'object') {
throw new TypeError('First argument must be an object');
}
return proxyToRaw.has(obj);
}
function observable(obj) {

@@ -448,37 +384,31 @@ if ( obj === void 0 ) obj = {};

}
// if it is already an observable, return it
if (proxyToRaw.has(obj)) {
// if it is already an observable or it should not be wrapped, return it
if (proxyToRaw.has(obj) || !shouldInstrument(obj)) {
return obj;
}
return (
// if it already has a cached observable wrapper, return it
// if it is a special built-in object, instrument it then wrap it with an observable
// otherwise simply wrap the object with an observable
rawToProxy.get(obj) || instrumentObservable(obj) || createObservable(obj)
);
// if it already has a cached observable wrapper, return it
// otherwise create a new observable
return rawToProxy.get(obj) || createObservable(obj);
}
function instrumentObservable(obj) {
var instrument = instrumentations.get(Object.getPrototypeOf(obj));
// these objects break, when they are wrapped with proxies
if (instrument === false) {
return obj;
}
// these objects can be wrapped by Proxies, but require special instrumentation beforehand
if (typeof instrument === 'function') {
instrument(obj);
}
}
// wrap the object in a Proxy and save the obj-proxy, proxy-obj pairs
function createObservable(obj) {
// if it is a complex built-in object or a normal object, wrap it
var handlers = getHandlers(obj) || baseHandlers;
var observable = new Proxy(obj, handlers);
// save these to switch between the raw object and the wrapped object with ease later
rawToProxy.set(obj, observable);
proxyToRaw.set(observable, obj);
// init basic data structures to save and cleanup later (observable.prop -> reaction) connections
storeObservable(obj);
// save these to switch between the raw object and the wrapped object with ease later
proxyToRaw.set(observable, obj);
rawToProxy.set(obj, observable);
return observable;
}
export { observe, unobserve, observable, isObservable };
function isObservable(obj) {
return proxyToRaw.has(obj);
}
function raw(obj) {
return proxyToRaw.get(obj) || obj;
}
export { observe, unobserve, observable, isObservable, raw };

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

var connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){var d=connectionStore.get(a),e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){var d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}var runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error('Unobserved reactions can not be executed. You tried to run a reaction for '+b);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}var IS_REACTION=Symbol('is reaction');function observe(a,b){function c(){return runAsReaction(c,a,this,arguments)}if(void 0===b&&(b={}),'function'!=typeof a)throw new TypeError('The first argument must be a function instead of '+a);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError('The second argument must be an options object instead of '+b);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions(a){var b=a.lazy;void 0===b&&(b=!1);var c=a.scheduler;if('boolean'!=typeof b)throw new TypeError('options.lazy must be a boolean or undefined instead of '+b);if('object'==typeof c&&null!==c){if('function'!=typeof c.add||'function'!=typeof c.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==c&&'function'!=typeof c)throw new TypeError('options.scheduler must be a function, an object or undefined instead of '+c)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError('The first argument must be a reaction instead of '+a);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}var proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf;function has(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.has.apply(b,arguments)):c.has.apply(this,arguments)}function get(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.get.apply(b,arguments)):c.get.apply(this,arguments)}function add(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.add.apply(this,arguments);var d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function set(a,b){var c=proxyToRaw.get(this),d=getPrototypeOf(this);if(!c)return d.set.apply(this,arguments);var e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(queueReactionsForKey(c,a),queueReactionsForKey(c,ITERATE)),f}function deleteFn(a){var b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.delete.apply(this,arguments);var d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function clear(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);if(!a)return b.clear.apply(this,arguments);var c=0!==a.size,d=b.clear.apply(a,arguments);return c&&queueReactionsForKey(a,ITERATE),d}function forEach(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.forEach.apply(a,arguments)):b.forEach.apply(this,arguments)}function keys(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.keys.apply(a,arguments)):b.keys.apply(this,arguments)}function values(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.values.apply(a,arguments)):b.values.apply(this,arguments)}function entries(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.entries.apply(a,arguments)):b.entries.apply(this,arguments)}function iterator(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)):b[Symbol.iterator].apply(this,arguments)}function getSize(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)):Reflect.get(b,'size',this)}function instrumentMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentSet(a){a.has=has,a.add=add,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentWeakMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn}function instrumentWeakSet(a){a.has=has,a.add=add,a.delete=deleteFn}var instrumentations=new Map([[Map.prototype,instrumentMap],[Set.prototype,instrumentSet],[WeakMap.prototype,instrumentWeakMap],[WeakSet.prototype,instrumentWeakSet],[Date.prototype,!1],[RegExp.prototype,!1]]),ENUMERATE=Symbol('enumerate');function get$1(a,b,c){var d=proxyToRaw.get(a)||a;if('$raw'===b)return d;var e=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof e?e:(registerRunningReactionForKey(d,b),hasRunningReaction()&&'object'==typeof e&&null!==e?observable(e):rawToProxy.get(e)||e)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set$1(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);var e='length'===b||c!==a[b],f=Reflect.set(a,b,c,d);return hasRunningReaction()?(console.error('Mutating observables in reactions is forbidden. You set '+b+' to '+c+'.'),f):('symbol'!=typeof b&&e&&a===proxyToRaw.get(d)&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),f)}function deleteProperty(a,b){var c=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&b in a&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),c}var handlers={get:get$1,ownKeys:ownKeys,set:set$1,deleteProperty:deleteProperty};function isObservable(a){if('object'!=typeof a)throw new TypeError('First argument must be an object');return proxyToRaw.has(a)}function observable(a){if(void 0===a&&(a={}),'object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)?a:rawToProxy.get(a)||instrumentObservable(a)||createObservable(a)}function instrumentObservable(a){var b=instrumentations.get(Object.getPrototypeOf(a));return!1===b?a:void('function'==typeof b&&b(a))}function createObservable(a){var b=new Proxy(a,handlers);return storeObservable(a),proxyToRaw.set(b,a),rawToProxy.set(a,b),b}export{observe,unobserve,observable,isObservable};
var connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){var d=connectionStore.get(a),e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){var d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}var runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error('Unobserved reactions can not be executed. You tried to run a reaction for '+b);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}var IS_REACTION=Symbol('is reaction');function observe(a,b){function c(){return runAsReaction(c,a,this,arguments)}if(void 0===b&&(b={}),'function'!=typeof a)throw new TypeError('The first argument must be a function instead of '+a);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError('The second argument must be an options object instead of '+b);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions(a){var b=a.lazy;void 0===b&&(b=!1);var c=a.scheduler;if('boolean'!=typeof b)throw new TypeError('options.lazy must be a boolean or undefined instead of '+b);if('object'==typeof c&&null!==c){if('function'!=typeof c.add||'function'!=typeof c.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==c&&'function'!=typeof c)throw new TypeError('options.scheduler must be a function, an object or undefined instead of '+c)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError('The first argument must be a reaction instead of '+a);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}var proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf,instrumentations={has:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this);return registerRunningReactionForKey(c,b),d.has.apply(c,arguments)},get:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this);return registerRunningReactionForKey(c,b),d.get.apply(c,arguments)},add:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this),e=!d.has.call(c,b),f=d.add.apply(c,arguments);return e&&(queueReactionsForKey(c,b),queueReactionsForKey(c,ITERATE)),f},set:function a(b,c){var d=proxyToRaw.get(this),e=getPrototypeOf(this),f=e.get.call(d,b)!==c,g=e.set.apply(d,arguments);return f&&(queueReactionsForKey(d,b),queueReactionsForKey(d,ITERATE)),g},delete:function a(b){var c=proxyToRaw.get(this),d=getPrototypeOf(this),e=d.has.call(c,b),f=d.delete.apply(c,arguments);return e&&(queueReactionsForKey(c,b),queueReactionsForKey(c,ITERATE)),f},clear:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this),d=0!==b.size,e=c.clear.apply(b,arguments);return d&&queueReactionsForKey(b,ITERATE),e},forEach:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.forEach.apply(b,arguments)},keys:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.keys.apply(b,arguments)},values:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.values.apply(b,arguments)},entries:function a(){var b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,ITERATE),c.entries.apply(b,arguments)},get size(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)}};instrumentations[Symbol.iterator]=function(){var a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)};var collectionHandlers={get:function a(b,c,d){return b=c in getPrototypeOf(b)?instrumentations:b,Reflect.get(b,c,d)}},dontInstrument=new Set([Date,RegExp]),handlers=new Map([[Map,collectionHandlers],[Set,collectionHandlers],[WeakMap,collectionHandlers],[WeakSet,collectionHandlers]]);function shouldInstrument(a){return'function'==typeof Node&&a instanceof Node?!1:!dontInstrument.has(a.constructor)}function getHandlers(a){return handlers.get(a.constructor)}var ENUMERATE=Symbol('enumerate');function get(a,b,c){var d=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof d?d:(a=proxyToRaw.get(a)||a,registerRunningReactionForKey(a,b),hasRunningReaction()&&'object'==typeof d&&null!==d?observable(d):rawToProxy.get(d)||d)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);var e=c!==a[b],f=Array.isArray(a)&&a.length,g=Reflect.set(a,b,c,d),h=!1!==f&&f!==a.length;return hasRunningReaction()?(console.error('Mutating observables in reactions is forbidden. You set '+b+' to '+c+'.'),g):a===proxyToRaw.get(d)?('symbol'!=typeof b&&e&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),h&&queueReactionsForKey(a,'length'),g):g}function deleteProperty(a,b){var c=b in a,d=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&c&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),d}var baseHandlers={get:get,ownKeys:ownKeys,set:set,deleteProperty:deleteProperty};function observable(a){if(void 0===a&&(a={}),'object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)||!shouldInstrument(a)?a:rawToProxy.get(a)||createObservable(a)}function createObservable(a){var b=getHandlers(a)||baseHandlers,c=new Proxy(a,b);return rawToProxy.set(a,c),proxyToRaw.set(c,a),storeObservable(a),c}function isObservable(a){return proxyToRaw.has(a)}function raw(a){return proxyToRaw.get(a)||a}export{observe,unobserve,observable,isObservable,raw};

@@ -161,202 +161,132 @@ const connectionStore = new WeakMap();

function has(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.has.apply(this, arguments);
const instrumentations = {
has(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
},
get(key) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
},
add(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = !proto.has.call(rawContext, value);
const result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
set(key, value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = proto.get.call(rawContext, key) !== value;
const result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
delete(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = proto.has.call(rawContext, value);
const result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
clear() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = rawContext.size !== 0;
const result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
forEach() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
},
keys() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
},
values() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
},
entries() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
},
[Symbol.iterator]() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
},
get size() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
}
};
function get(key) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.get.apply(this, arguments);
var collectionHandlers = {
get(target, key, receiver) {
// instrument methods and property accessors to be reactive
target = key in getPrototypeOf(target) ? instrumentations : target;
return Reflect.get(target, key, receiver);
}
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
}
};
function add(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.add.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = !proto.has.call(rawContext, value);
const result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// simple objects are not wrapped by Proxies, neither instrumented
const dontInstrument = new Set([Date, RegExp]);
function set(key, value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.set.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = proto.get.call(rawContext, key) !== value;
const result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' instead of the Proxy wrapper
// complex objects are wrapped with a Proxy of instrumented methods
// which switch the proxy to the raw object and to add reactive wiring
const handlers = new Map([[Map, collectionHandlers], [Set, collectionHandlers], [WeakMap, collectionHandlers], [WeakSet, collectionHandlers]]);
function deleteFn(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.delete.apply(this, arguments);
function shouldInstrument(obj) {
if (typeof Node === 'function' && obj instanceof Node) {
return false;
}
// forward the operation before queueing reactions
const valueChanged = proto.has.call(rawContext, value);
const result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
return !dontInstrument.has(obj.constructor);
}
function clear() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.clear.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = rawContext.size !== 0;
const result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
function getHandlers(obj) {
return handlers.get(obj.constructor);
}
function forEach() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.forEach.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
}
function keys() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.keys.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
}
function values() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.values.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
}
function entries() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.entries.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
}
function iterator() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto[Symbol.iterator].apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
}
function getSize() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return Reflect.get(proto, 'size', this);
}
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
function instrumentMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
map.clear = clear;
map.forEach = forEach;
map.keys = keys;
map.values = values;
map.entries = entries;
map[Symbol.iterator] = iterator;
Object.defineProperty(map, 'size', { get: getSize });
}
function instrumentSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
set$$1.clear = clear;
set$$1.forEach = forEach;
set$$1.keys = keys;
set$$1.values = values;
set$$1.entries = entries;
set$$1[Symbol.iterator] = iterator;
Object.defineProperty(set$$1, 'size', { get: getSize });
}
function instrumentWeakMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
}
function instrumentWeakSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' and when a Proxy instance is passed instead they break
// simple objects are not wrapped by Proxies or instrumented
// complex objects are wrapped and their methods are monkey patched
// to switch the proxy to the raw object and to add reactive wiring
var instrumentations = new Map([[Map.prototype, instrumentMap], [Set.prototype, instrumentSet], [WeakMap.prototype, instrumentWeakMap], [WeakSet.prototype, instrumentWeakSet], [Date.prototype, false], [RegExp.prototype, false]]);
const ENUMERATE = Symbol('enumerate');
// intercept get operations on observables to know which reaction uses their properties
function get$1(obj, key, receiver) {
// make sure to use the raw object here
const rawObj = proxyToRaw.get(obj) || obj;
// expose the raw object on observable.$raw
if (key === '$raw') {
return rawObj;
}
function get(obj, key, receiver) {
const result = Reflect.get(obj, key, receiver);

@@ -367,4 +297,6 @@ // do not register (observable.prop -> reaction) pairs for these cases

}
// make sure to use the raw object here, obj might be a Proxy because of inheritance
obj = proxyToRaw.get(obj) || obj;
// register and save (observable.prop -> runningReaction)
registerRunningReactionForKey(rawObj, key);
registerRunningReactionForKey(obj, key);
// if we are inside a reaction and observable.prop is an object wrap it in an observable too

@@ -385,3 +317,3 @@ // this is needed to intercept property access on that object too (dynamic observable tree)

// intercept set operations on observables to know when to trigger reactions
function set$1(obj, key, value, receiver) {
function set(obj, key, value, receiver) {
// make sure to do not pollute the raw object with observables

@@ -392,6 +324,9 @@ if (typeof value === 'object' && value !== null) {

// save if the value changed because of this set operation
// array 'length' is an exception here, because of it's exotic nature
const valueChanged = key === 'length' || value !== obj[key];
const valueChanged = value !== obj[key];
// length is lazy, it can change without an explicit length set operation
const prevLength = Array.isArray(obj) && obj.length;
// execute the set operation before running any reaction
const result = Reflect.set(obj, key, value, receiver);
// check if the length changed implicitly, because of out of bound set operations
const lengthChanged = prevLength !== false && prevLength !== obj.length;
// emit a warning and do not queue anything when another reaction is queued

@@ -403,9 +338,17 @@ // from an already running reaction

}
// if the target of the operation is not the raw receiver return
// (possible because of prototypal inheritance)
if (obj !== proxyToRaw.get(receiver)) {
return result;
}
// do not queue reactions if it is a symbol keyed property
// or the set operation resulted in no value change
// or if the target of the operation is not the raw object (possible because of prototypal inheritance)
if (typeof key !== 'symbol' && valueChanged && obj === proxyToRaw.get(receiver)) {
if (typeof key !== 'symbol' && valueChanged) {
queueReactionsForKey(obj, key);
queueReactionsForKey(obj, ENUMERATE);
}
// queue length reactions in case the length changed
if (lengthChanged) {
queueReactionsForKey(obj, 'length');
}
return result;

@@ -427,11 +370,4 @@ }

var handlers = { get: get$1, ownKeys, set: set$1, deleteProperty };
var baseHandlers = { get, ownKeys, set, deleteProperty };
function isObservable(obj) {
if (typeof obj !== 'object') {
throw new TypeError('First argument must be an object');
}
return proxyToRaw.has(obj);
}
function observable(obj = {}) {

@@ -441,37 +377,31 @@ if (typeof obj !== 'object') {

}
// if it is already an observable, return it
if (proxyToRaw.has(obj)) {
// if it is already an observable or it should not be wrapped, return it
if (proxyToRaw.has(obj) || !shouldInstrument(obj)) {
return obj;
}
return (
// if it already has a cached observable wrapper, return it
// if it is a special built-in object, instrument it then wrap it with an observable
// otherwise simply wrap the object with an observable
rawToProxy.get(obj) || instrumentObservable(obj) || createObservable(obj)
);
// if it already has a cached observable wrapper, return it
// otherwise create a new observable
return rawToProxy.get(obj) || createObservable(obj);
}
function instrumentObservable(obj) {
const instrument = instrumentations.get(Object.getPrototypeOf(obj));
// these objects break, when they are wrapped with proxies
if (instrument === false) {
return obj;
}
// these objects can be wrapped by Proxies, but require special instrumentation beforehand
if (typeof instrument === 'function') {
instrument(obj);
}
}
// wrap the object in a Proxy and save the obj-proxy, proxy-obj pairs
function createObservable(obj) {
// if it is a complex built-in object or a normal object, wrap it
const handlers = getHandlers(obj) || baseHandlers;
const observable = new Proxy(obj, handlers);
// save these to switch between the raw object and the wrapped object with ease later
rawToProxy.set(obj, observable);
proxyToRaw.set(observable, obj);
// init basic data structures to save and cleanup later (observable.prop -> reaction) connections
storeObservable(obj);
// save these to switch between the raw object and the wrapped object with ease later
proxyToRaw.set(observable, obj);
rawToProxy.set(obj, observable);
return observable;
}
export { observe, unobserve, observable, isObservable };
function isObservable(obj) {
return proxyToRaw.has(obj);
}
function raw(obj) {
return proxyToRaw.get(obj) || obj;
}
export { observe, unobserve, observable, isObservable, raw };

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

const connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){const d=connectionStore.get(a);let e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){const d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}let runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error(`Unobserved reactions can not be executed. You tried to run a reaction for ${b}`);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}const IS_REACTION=Symbol('is reaction');function observe(a,b={}){function c(){return runAsReaction(c,a,this,arguments)}if('function'!=typeof a)throw new TypeError(`The first argument must be a function instead of ${a}`);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError(`The second argument must be an options object instead of ${b}`);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions({lazy:b=!1,scheduler:a}){if('boolean'!=typeof b)throw new TypeError(`options.lazy must be a boolean or undefined instead of ${b}`);if('object'==typeof a&&null!==a){if('function'!=typeof a.add||'function'!=typeof a.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==a&&'function'!=typeof a)throw new TypeError(`options.scheduler must be a function, an object or undefined instead of ${a}`)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError(`The first argument must be a reaction instead of ${a}`);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}const proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf;function has(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.has.apply(b,arguments)):c.has.apply(this,arguments)}function get(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return b?(registerRunningReactionForKey(b,a),c.get.apply(b,arguments)):c.get.apply(this,arguments)}function add(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.add.apply(this,arguments);const d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function set(a,b){const c=proxyToRaw.get(this),d=getPrototypeOf(this);if(!c)return d.set.apply(this,arguments);const e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(queueReactionsForKey(c,a),queueReactionsForKey(c,ITERATE)),f}function deleteFn(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);if(!b)return c.delete.apply(this,arguments);const d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e}function clear(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);if(!a)return b.clear.apply(this,arguments);const c=0!==a.size,d=b.clear.apply(a,arguments);return c&&queueReactionsForKey(a,ITERATE),d}function forEach(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.forEach.apply(a,arguments)):b.forEach.apply(this,arguments)}function keys(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.keys.apply(a,arguments)):b.keys.apply(this,arguments)}function values(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.values.apply(a,arguments)):b.values.apply(this,arguments)}function entries(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b.entries.apply(a,arguments)):b.entries.apply(this,arguments)}function iterator(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)):b[Symbol.iterator].apply(this,arguments)}function getSize(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return a?(registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)):Reflect.get(b,'size',this)}function instrumentMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentSet(a){a.has=has,a.add=add,a.delete=deleteFn,a.clear=clear,a.forEach=forEach,a.keys=keys,a.values=values,a.entries=entries,a[Symbol.iterator]=iterator,Object.defineProperty(a,'size',{get:getSize})}function instrumentWeakMap(a){a.has=has,a.get=get,a.set=set,a.delete=deleteFn}function instrumentWeakSet(a){a.has=has,a.add=add,a.delete=deleteFn}var instrumentations=new Map([[Map.prototype,instrumentMap],[Set.prototype,instrumentSet],[WeakMap.prototype,instrumentWeakMap],[WeakSet.prototype,instrumentWeakSet],[Date.prototype,!1],[RegExp.prototype,!1]]);const ENUMERATE=Symbol('enumerate');function get$1(a,b,c){const d=proxyToRaw.get(a)||a;if('$raw'===b)return d;const e=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof e?e:(registerRunningReactionForKey(d,b),hasRunningReaction()&&'object'==typeof e&&null!==e?observable(e):rawToProxy.get(e)||e)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set$1(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);const e='length'===b||c!==a[b],f=Reflect.set(a,b,c,d);return hasRunningReaction()?(console.error(`Mutating observables in reactions is forbidden. You set ${b} to ${c}.`),f):('symbol'!=typeof b&&e&&a===proxyToRaw.get(d)&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),f)}function deleteProperty(a,b){const c=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&b in a&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),c}var handlers={get:get$1,ownKeys,set:set$1,deleteProperty};function isObservable(a){if('object'!=typeof a)throw new TypeError('First argument must be an object');return proxyToRaw.has(a)}function observable(a={}){if('object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)?a:rawToProxy.get(a)||instrumentObservable(a)||createObservable(a)}function instrumentObservable(a){const b=instrumentations.get(Object.getPrototypeOf(a));return!1===b?a:void('function'==typeof b&&b(a))}function createObservable(a){const b=new Proxy(a,handlers);return storeObservable(a),proxyToRaw.set(b,a),rawToProxy.set(a,b),b}export{observe,unobserve,observable,isObservable};
const connectionStore=new WeakMap;function storeObservable(a){connectionStore.set(a,Object.create(null))}function registerReactionForKey(a,b,c){const d=connectionStore.get(a);let e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function iterateReactionsForKey(a,b,c){const d=connectionStore.get(a)[b];d&&Array.from(d).forEach(c)}function releaseReaction(a){a.cleaners&&a.cleaners.forEach(releaseReactionKeyConnection,a),a.cleaners=void 0}function releaseReactionKeyConnection(a){a.delete(this)}let runningReaction;function runAsReaction(a,b,c,d){if(a.unobserved)throw new Error(`Unobserved reactions can not be executed. You tried to run a reaction for ${b}`);releaseReaction(a),a.cleaners=[];try{return runningReaction=a,b.apply(c,d)}finally{runningReaction=void 0}}function registerRunningReactionForKey(a,b){runningReaction&&registerReactionForKey(a,b,runningReaction)}function queueReactionsForKey(a,b){iterateReactionsForKey(a,b,queueReaction)}function queueReaction(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function hasRunningReaction(){return runningReaction!==void 0}const IS_REACTION=Symbol('is reaction');function observe(a,b={}){function c(){return runAsReaction(c,a,this,arguments)}if('function'!=typeof a)throw new TypeError(`The first argument must be a function instead of ${a}`);if(a[IS_REACTION])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError(`The second argument must be an options object instead of ${b}`);return validateOptions(b),c.scheduler=b.scheduler,c.runId=0,c[IS_REACTION]=!0,b.lazy||c(),c}function validateOptions({lazy:b=!1,scheduler:a}){if('boolean'!=typeof b)throw new TypeError(`options.lazy must be a boolean or undefined instead of ${b}`);if('object'==typeof a&&null!==a){if('function'!=typeof a.add||'function'!=typeof a.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==a&&'function'!=typeof a)throw new TypeError(`options.scheduler must be a function, an object or undefined instead of ${a}`)}function unobserve(a){if('function'!=typeof a||!a[IS_REACTION])throw new TypeError(`The first argument must be a reaction instead of ${a}`);a.unobserved||(a.unobserved=!0,releaseReaction(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}const proxyToRaw=new WeakMap,rawToProxy=new WeakMap,ITERATE=Symbol('iterate'),getPrototypeOf=Object.getPrototypeOf,instrumentations={has(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,a),c.has.apply(b,arguments)},get(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this);return registerRunningReactionForKey(b,a),c.get.apply(b,arguments)},add(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this),d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e},set(a,b){const c=proxyToRaw.get(this),d=getPrototypeOf(this),e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(queueReactionsForKey(c,a),queueReactionsForKey(c,ITERATE)),f},delete(a){const b=proxyToRaw.get(this),c=getPrototypeOf(this),d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(queueReactionsForKey(b,a),queueReactionsForKey(b,ITERATE)),e},clear(){const a=proxyToRaw.get(this),b=getPrototypeOf(this),c=0!==a.size,d=b.clear.apply(a,arguments);return c&&queueReactionsForKey(a,ITERATE),d},forEach(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.forEach.apply(a,arguments)},keys(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.keys.apply(a,arguments)},values(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.values.apply(a,arguments)},entries(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b.entries.apply(a,arguments)},[Symbol.iterator](){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),b[Symbol.iterator].apply(a,arguments)},get size(){const a=proxyToRaw.get(this),b=getPrototypeOf(this);return registerRunningReactionForKey(a,ITERATE),Reflect.get(b,'size',a)}};var collectionHandlers={get(a,b,c){return a=b in getPrototypeOf(a)?instrumentations:a,Reflect.get(a,b,c)}};const dontInstrument=new Set([Date,RegExp]),handlers=new Map([[Map,collectionHandlers],[Set,collectionHandlers],[WeakMap,collectionHandlers],[WeakSet,collectionHandlers]]);function shouldInstrument(a){return'function'==typeof Node&&a instanceof Node?!1:!dontInstrument.has(a.constructor)}function getHandlers(a){return handlers.get(a.constructor)}const ENUMERATE=Symbol('enumerate');function get(a,b,c){const d=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof d?d:(a=proxyToRaw.get(a)||a,registerRunningReactionForKey(a,b),hasRunningReaction()&&'object'==typeof d&&null!==d?observable(d):rawToProxy.get(d)||d)}function ownKeys(a){return registerRunningReactionForKey(a,ENUMERATE),Reflect.ownKeys(a)}function set(a,b,c,d){'object'==typeof c&&null!==c&&(c=proxyToRaw.get(c)||c);const e=c!==a[b],f=Array.isArray(a)&&a.length,g=Reflect.set(a,b,c,d),h=!1!==f&&f!==a.length;return hasRunningReaction()?(console.error(`Mutating observables in reactions is forbidden. You set ${b} to ${c}.`),g):a===proxyToRaw.get(d)?('symbol'!=typeof b&&e&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),h&&queueReactionsForKey(a,'length'),g):g}function deleteProperty(a,b){const c=b in a,d=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&c&&(queueReactionsForKey(a,b),queueReactionsForKey(a,ENUMERATE)),d}var baseHandlers={get,ownKeys,set,deleteProperty};function observable(a={}){if('object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return proxyToRaw.has(a)||!shouldInstrument(a)?a:rawToProxy.get(a)||createObservable(a)}function createObservable(a){const b=getHandlers(a)||baseHandlers,c=new Proxy(a,b);return rawToProxy.set(a,c),proxyToRaw.set(c,a),storeObservable(a),c}function isObservable(a){return proxyToRaw.has(a)}function raw(a){return proxyToRaw.get(a)||a}export{observe,unobserve,observable,isObservable,raw};

@@ -172,202 +172,132 @@ (function (global, factory) {

function has(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.has.apply(this, arguments);
var instrumentations = {
has: function has(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
},
get: function get(key) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
},
add: function add(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = !proto.has.call(rawContext, value);
var result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
set: function set(key, value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = proto.get.call(rawContext, key) !== value;
var result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
delete: function delete$1(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = proto.has.call(rawContext, value);
var result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
clear: function clear() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
// forward the operation before queueing reactions
var valueChanged = rawContext.size !== 0;
var result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
forEach: function forEach() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
},
keys: function keys() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
},
values: function values() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
},
entries: function entries() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
},
get size() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
}
};
instrumentations[Symbol.iterator] = function () {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
};
function get(key) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.get.apply(this, arguments);
var collectionHandlers = {
get: function get(target, key, receiver) {
// instrument methods and property accessors to be reactive
target = key in getPrototypeOf(target) ? instrumentations : target;
return Reflect.get(target, key, receiver);
}
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
}
};
function add(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.add.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = !proto.has.call(rawContext, value);
var result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// simple objects are not wrapped by Proxies, neither instrumented
var dontInstrument = new Set([Date, RegExp]);
function set(key, value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.set.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = proto.get.call(rawContext, key) !== value;
var result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' instead of the Proxy wrapper
// complex objects are wrapped with a Proxy of instrumented methods
// which switch the proxy to the raw object and to add reactive wiring
var handlers = new Map([[Map, collectionHandlers], [Set, collectionHandlers], [WeakMap, collectionHandlers], [WeakSet, collectionHandlers]]);
function deleteFn(value) {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.delete.apply(this, arguments);
function shouldInstrument(obj) {
if (typeof Node === 'function' && obj instanceof Node) {
return false;
}
// forward the operation before queueing reactions
var valueChanged = proto.has.call(rawContext, value);
var result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
return !dontInstrument.has(obj.constructor);
}
function clear() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.clear.apply(this, arguments);
}
// forward the operation before queueing reactions
var valueChanged = rawContext.size !== 0;
var result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
function getHandlers(obj) {
return handlers.get(obj.constructor);
}
function forEach() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.forEach.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
}
function keys() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.keys.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
}
function values() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.values.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
}
function entries() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto.entries.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
}
function iterator() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return proto[Symbol.iterator].apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
}
function getSize() {
var rawContext = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
if (!rawContext) {
return Reflect.get(proto, 'size', this);
}
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
function instrumentMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
map.clear = clear;
map.forEach = forEach;
map.keys = keys;
map.values = values;
map.entries = entries;
map[Symbol.iterator] = iterator;
Object.defineProperty(map, 'size', { get: getSize });
}
function instrumentSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
set$$1.clear = clear;
set$$1.forEach = forEach;
set$$1.keys = keys;
set$$1.values = values;
set$$1.entries = entries;
set$$1[Symbol.iterator] = iterator;
Object.defineProperty(set$$1, 'size', { get: getSize });
}
function instrumentWeakMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
}
function instrumentWeakSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' and when a Proxy instance is passed instead they break
// simple objects are not wrapped by Proxies or instrumented
// complex objects are wrapped and their methods are monkey patched
// to switch the proxy to the raw object and to add reactive wiring
var instrumentations = new Map([[Map.prototype, instrumentMap], [Set.prototype, instrumentSet], [WeakMap.prototype, instrumentWeakMap], [WeakSet.prototype, instrumentWeakSet], [Date.prototype, false], [RegExp.prototype, false]]);
var ENUMERATE = Symbol('enumerate');
// intercept get operations on observables to know which reaction uses their properties
function get$1(obj, key, receiver) {
// make sure to use the raw object here
var rawObj = proxyToRaw.get(obj) || obj;
// expose the raw object on observable.$raw
if (key === '$raw') {
return rawObj;
}
function get(obj, key, receiver) {
var result = Reflect.get(obj, key, receiver);

@@ -378,4 +308,6 @@ // do not register (observable.prop -> reaction) pairs for these cases

}
// make sure to use the raw object here, obj might be a Proxy because of inheritance
obj = proxyToRaw.get(obj) || obj;
// register and save (observable.prop -> runningReaction)
registerRunningReactionForKey(rawObj, key);
registerRunningReactionForKey(obj, key);
// if we are inside a reaction and observable.prop is an object wrap it in an observable too

@@ -396,3 +328,3 @@ // this is needed to intercept property access on that object too (dynamic observable tree)

// intercept set operations on observables to know when to trigger reactions
function set$1(obj, key, value, receiver) {
function set(obj, key, value, receiver) {
// make sure to do not pollute the raw object with observables

@@ -403,6 +335,9 @@ if (typeof value === 'object' && value !== null) {

// save if the value changed because of this set operation
// array 'length' is an exception here, because of it's exotic nature
var valueChanged = key === 'length' || value !== obj[key];
var valueChanged = value !== obj[key];
// length is lazy, it can change without an explicit length set operation
var prevLength = Array.isArray(obj) && obj.length;
// execute the set operation before running any reaction
var result = Reflect.set(obj, key, value, receiver);
// check if the length changed implicitly, because of out of bound set operations
var lengthChanged = prevLength !== false && prevLength !== obj.length;
// emit a warning and do not queue anything when another reaction is queued

@@ -414,9 +349,17 @@ // from an already running reaction

}
// if the target of the operation is not the raw receiver return
// (possible because of prototypal inheritance)
if (obj !== proxyToRaw.get(receiver)) {
return result;
}
// do not queue reactions if it is a symbol keyed property
// or the set operation resulted in no value change
// or if the target of the operation is not the raw object (possible because of prototypal inheritance)
if (typeof key !== 'symbol' && valueChanged && obj === proxyToRaw.get(receiver)) {
if (typeof key !== 'symbol' && valueChanged) {
queueReactionsForKey(obj, key);
queueReactionsForKey(obj, ENUMERATE);
}
// queue length reactions in case the length changed
if (lengthChanged) {
queueReactionsForKey(obj, 'length');
}
return result;

@@ -438,11 +381,4 @@ }

var handlers = { get: get$1, ownKeys: ownKeys, set: set$1, deleteProperty: deleteProperty };
var baseHandlers = { get: get, ownKeys: ownKeys, set: set, deleteProperty: deleteProperty };
function isObservable(obj) {
if (typeof obj !== 'object') {
throw new TypeError('First argument must be an object');
}
return proxyToRaw.has(obj);
}
function observable(obj) {

@@ -454,37 +390,31 @@ if ( obj === void 0 ) obj = {};

}
// if it is already an observable, return it
if (proxyToRaw.has(obj)) {
// if it is already an observable or it should not be wrapped, return it
if (proxyToRaw.has(obj) || !shouldInstrument(obj)) {
return obj;
}
return (
// if it already has a cached observable wrapper, return it
// if it is a special built-in object, instrument it then wrap it with an observable
// otherwise simply wrap the object with an observable
rawToProxy.get(obj) || instrumentObservable(obj) || createObservable(obj)
);
// if it already has a cached observable wrapper, return it
// otherwise create a new observable
return rawToProxy.get(obj) || createObservable(obj);
}
function instrumentObservable(obj) {
var instrument = instrumentations.get(Object.getPrototypeOf(obj));
// these objects break, when they are wrapped with proxies
if (instrument === false) {
return obj;
}
// these objects can be wrapped by Proxies, but require special instrumentation beforehand
if (typeof instrument === 'function') {
instrument(obj);
}
}
// wrap the object in a Proxy and save the obj-proxy, proxy-obj pairs
function createObservable(obj) {
// if it is a complex built-in object or a normal object, wrap it
var handlers = getHandlers(obj) || baseHandlers;
var observable = new Proxy(obj, handlers);
// save these to switch between the raw object and the wrapped object with ease later
rawToProxy.set(obj, observable);
proxyToRaw.set(observable, obj);
// init basic data structures to save and cleanup later (observable.prop -> reaction) connections
storeObservable(obj);
// save these to switch between the raw object and the wrapped object with ease later
proxyToRaw.set(observable, obj);
rawToProxy.set(obj, observable);
return observable;
}
function isObservable(obj) {
return proxyToRaw.has(obj);
}
function raw(obj) {
return proxyToRaw.get(obj) || obj;
}
exports.observe = observe;

@@ -494,2 +424,3 @@ exports.unobserve = unobserve;

exports.isObservable = isObservable;
exports.raw = raw;

@@ -496,0 +427,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

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

(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a.observer={})})(this,function(a){'use strict';function b(a){C.set(a,Object.create(null))}function c(a,b,c){var d=C.get(a),e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function d(a,b,c){var d=C.get(a)[b];d&&Array.from(d).forEach(c)}function e(a){a.cleaners&&a.cleaners.forEach(f,a),a.cleaners=void 0}function f(a){a.delete(this)}function g(a,b,c,d){if(a.unobserved)throw new Error('Unobserved reactions can not be executed. You tried to run a reaction for '+b);e(a),a.cleaners=[];try{return B=a,b.apply(c,d)}finally{B=void 0}}function h(a,b){B&&c(a,b,B)}function i(a,b){d(a,b,j)}function j(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function k(){return B!==void 0}function l(a){var b=a.lazy;void 0===b&&(b=!1);var c=a.scheduler;if('boolean'!=typeof b)throw new TypeError('options.lazy must be a boolean or undefined instead of '+b);if('object'==typeof c&&null!==c){if('function'!=typeof c.add||'function'!=typeof c.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==c&&'function'!=typeof c)throw new TypeError('options.scheduler must be a function, an object or undefined instead of '+c)}function m(a){var b=E.get(this),c=H(this);return b?(h(b,a),c.has.apply(b,arguments)):c.has.apply(this,arguments)}function n(a){var b=E.get(this),c=H(this);return b?(h(b,a),c.get.apply(b,arguments)):c.get.apply(this,arguments)}function o(a){var b=E.get(this),c=H(this);if(!b)return c.add.apply(this,arguments);var d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(i(b,a),i(b,G)),e}function p(a,b){var c=E.get(this),d=H(this);if(!c)return d.set.apply(this,arguments);var e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(i(c,a),i(c,G)),f}function q(a){var b=E.get(this),c=H(this);if(!b)return c.delete.apply(this,arguments);var d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(i(b,a),i(b,G)),e}function r(){var a=E.get(this),b=H(this);if(!a)return b.clear.apply(this,arguments);var c=0!==a.size,d=b.clear.apply(a,arguments);return c&&i(a,G),d}function s(){var a=E.get(this),b=H(this);return a?(h(a,G),b.forEach.apply(a,arguments)):b.forEach.apply(this,arguments)}function t(){var a=E.get(this),b=H(this);return a?(h(a,G),b.keys.apply(a,arguments)):b.keys.apply(this,arguments)}function u(){var a=E.get(this),b=H(this);return a?(h(a,G),b.values.apply(a,arguments)):b.values.apply(this,arguments)}function v(){var a=E.get(this),b=H(this);return a?(h(a,G),b.entries.apply(a,arguments)):b.entries.apply(this,arguments)}function w(){var a=E.get(this),b=H(this);return a?(h(a,G),b[Symbol.iterator].apply(a,arguments)):b[Symbol.iterator].apply(this,arguments)}function x(){var a=E.get(this),b=H(this);return a?(h(a,G),Reflect.get(b,'size',a)):Reflect.get(b,'size',this)}function y(a){if(void 0===a&&(a={}),'object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return E.has(a)?a:F.get(a)||z(a)||A(a)}function z(a){var b=I.get(Object.getPrototypeOf(a));return!1===b?a:void('function'==typeof b&&b(a))}function A(a){var c=new Proxy(a,K);return b(a),E.set(c,a),F.set(a,c),c}var B,C=new WeakMap,D=Symbol('is reaction'),E=new WeakMap,F=new WeakMap,G=Symbol('iterate'),H=Object.getPrototypeOf,I=new Map([[Map.prototype,function(a){a.has=m,a.get=n,a.set=p,a.delete=q,a.clear=r,a.forEach=s,a.keys=t,a.values=u,a.entries=v,a[Symbol.iterator]=w,Object.defineProperty(a,'size',{get:x})}],[Set.prototype,function(a){a.has=m,a.add=o,a.delete=q,a.clear=r,a.forEach=s,a.keys=t,a.values=u,a.entries=v,a[Symbol.iterator]=w,Object.defineProperty(a,'size',{get:x})}],[WeakMap.prototype,function(a){a.has=m,a.get=n,a.set=p,a.delete=q}],[WeakSet.prototype,function(a){a.has=m,a.add=o,a.delete=q}],[Date.prototype,!1],[RegExp.prototype,!1]]),J=Symbol('enumerate'),K={get:function(a,b,c){var d=E.get(a)||a;if('$raw'===b)return d;var e=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof e?e:(h(d,b),k()&&'object'==typeof e&&null!==e?y(e):F.get(e)||e)},ownKeys:function(a){return h(a,J),Reflect.ownKeys(a)},set:function(a,b,c,d){'object'==typeof c&&null!==c&&(c=E.get(c)||c);var e='length'===b||c!==a[b],f=Reflect.set(a,b,c,d);return k()?(console.error('Mutating observables in reactions is forbidden. You set '+b+' to '+c+'.'),f):('symbol'!=typeof b&&e&&a===E.get(d)&&(i(a,b),i(a,J)),f)},deleteProperty:function(a,b){var c=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&b in a&&(i(a,b),i(a,J)),c}};a.observe=function(a,b){function c(){return g(c,a,this,arguments)}if(void 0===b&&(b={}),'function'!=typeof a)throw new TypeError('The first argument must be a function instead of '+a);if(a[D])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError('The second argument must be an options object instead of '+b);return l(b),c.scheduler=b.scheduler,c.runId=0,c[D]=!0,b.lazy||c(),c},a.unobserve=function(a){if('function'!=typeof a||!a[D])throw new TypeError('The first argument must be a reaction instead of '+a);a.unobserved||(a.unobserved=!0,e(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)},a.observable=y,a.isObservable=function(a){if('object'!=typeof a)throw new TypeError('First argument must be an object');return E.has(a)},Object.defineProperty(a,'__esModule',{value:!0})});
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a.observer={})})(this,function(a){'use strict';function b(a){z.set(a,Object.create(null))}function c(a,b,c){var d=z.get(a),e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function d(a,b,c){var d=z.get(a)[b];d&&Array.from(d).forEach(c)}function e(a){a.cleaners&&a.cleaners.forEach(f,a),a.cleaners=void 0}function f(a){a.delete(this)}function g(a,b,c,d){if(a.unobserved)throw new Error('Unobserved reactions can not be executed. You tried to run a reaction for '+b);e(a),a.cleaners=[];try{return y=a,b.apply(c,d)}finally{y=void 0}}function h(a,b){y&&c(a,b,y)}function i(a,b){d(a,b,j)}function j(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function k(){return y!==void 0}function l(a,b){function c(){return g(c,a,this,arguments)}if(void 0===b&&(b={}),'function'!=typeof a)throw new TypeError('The first argument must be a function instead of '+a);if(a[A])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError('The second argument must be an options object instead of '+b);return m(b),c.scheduler=b.scheduler,c.runId=0,c[A]=!0,b.lazy||c(),c}function m(a){var b=a.lazy;void 0===b&&(b=!1);var c=a.scheduler;if('boolean'!=typeof b)throw new TypeError('options.lazy must be a boolean or undefined instead of '+b);if('object'==typeof c&&null!==c){if('function'!=typeof c.add||'function'!=typeof c.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==c&&'function'!=typeof c)throw new TypeError('options.scheduler must be a function, an object or undefined instead of '+c)}function n(a){if('function'!=typeof a||!a[A])throw new TypeError('The first argument must be a reaction instead of '+a);a.unobserved||(a.unobserved=!0,e(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}function o(a){return'function'==typeof Node&&a instanceof Node?!1:!H.has(a.constructor)}function p(a){return I.get(a.constructor)}function q(a,b,c){var d=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof d?d:(a=B.get(a)||a,h(a,b),k()&&'object'==typeof d&&null!==d?u(d):C.get(d)||d)}function r(a){return h(a,J),Reflect.ownKeys(a)}function s(a,b,c,d){'object'==typeof c&&null!==c&&(c=B.get(c)||c);var e=c!==a[b],f=Array.isArray(a)&&a.length,g=Reflect.set(a,b,c,d),h=!1!==f&&f!==a.length;return k()?(console.error('Mutating observables in reactions is forbidden. You set '+b+' to '+c+'.'),g):a===B.get(d)?('symbol'!=typeof b&&e&&(i(a,b),i(a,J)),h&&i(a,'length'),g):g}function t(a,b){var c=b in a,d=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&c&&(i(a,b),i(a,J)),d}function u(a){if(void 0===a&&(a={}),'object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return B.has(a)||!o(a)?a:C.get(a)||v(a)}function v(a){var c=p(a)||K,d=new Proxy(a,c);return C.set(a,d),B.set(d,a),b(a),d}function w(a){return B.has(a)}function x(a){return B.get(a)||a}var y,z=new WeakMap,A=Symbol('is reaction'),B=new WeakMap,C=new WeakMap,D=Symbol('iterate'),E=Object.getPrototypeOf,F={has:function a(b){var c=B.get(this),d=E(this);return h(c,b),d.has.apply(c,arguments)},get:function a(b){var c=B.get(this),d=E(this);return h(c,b),d.get.apply(c,arguments)},add:function a(b){var c=B.get(this),d=E(this),e=!d.has.call(c,b),f=d.add.apply(c,arguments);return e&&(i(c,b),i(c,D)),f},set:function a(b,c){var d=B.get(this),e=E(this),f=e.get.call(d,b)!==c,g=e.set.apply(d,arguments);return f&&(i(d,b),i(d,D)),g},delete:function a(b){var c=B.get(this),d=E(this),e=d.has.call(c,b),f=d.delete.apply(c,arguments);return e&&(i(c,b),i(c,D)),f},clear:function a(){var b=B.get(this),c=E(this),d=0!==b.size,e=c.clear.apply(b,arguments);return d&&i(b,D),e},forEach:function a(){var b=B.get(this),c=E(this);return h(b,D),c.forEach.apply(b,arguments)},keys:function a(){var b=B.get(this),c=E(this);return h(b,D),c.keys.apply(b,arguments)},values:function a(){var b=B.get(this),c=E(this);return h(b,D),c.values.apply(b,arguments)},entries:function a(){var b=B.get(this),c=E(this);return h(b,D),c.entries.apply(b,arguments)},get size(){var a=B.get(this),b=E(this);return h(a,D),Reflect.get(b,'size',a)}};F[Symbol.iterator]=function(){var a=B.get(this),b=E(this);return h(a,D),b[Symbol.iterator].apply(a,arguments)};var G={get:function a(b,c,d){return b=c in E(b)?F:b,Reflect.get(b,c,d)}},H=new Set([Date,RegExp]),I=new Map([[Map,G],[Set,G],[WeakMap,G],[WeakSet,G]]),J=Symbol('enumerate'),K={get:q,ownKeys:r,set:s,deleteProperty:t};a.observe=l,a.unobserve=n,a.observable=u,a.isObservable=w,a.raw=x,Object.defineProperty(a,'__esModule',{value:!0})});

@@ -167,202 +167,132 @@ (function (global, factory) {

function has(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.has.apply(this, arguments);
const instrumentations = {
has(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
},
get(key) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
},
add(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = !proto.has.call(rawContext, value);
const result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
set(key, value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = proto.get.call(rawContext, key) !== value;
const result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
delete(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = proto.has.call(rawContext, value);
const result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
clear() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
// forward the operation before queueing reactions
const valueChanged = rawContext.size !== 0;
const result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
},
forEach() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
},
keys() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
},
values() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
},
entries() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
},
[Symbol.iterator]() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
},
get size() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
registerRunningReactionForKey(rawContext, value);
return proto.has.apply(rawContext, arguments);
}
};
function get(key) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.get.apply(this, arguments);
var collectionHandlers = {
get(target, key, receiver) {
// instrument methods and property accessors to be reactive
target = key in getPrototypeOf(target) ? instrumentations : target;
return Reflect.get(target, key, receiver);
}
registerRunningReactionForKey(rawContext, key);
return proto.get.apply(rawContext, arguments);
}
};
function add(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.add.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = !proto.has.call(rawContext, value);
const result = proto.add.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// simple objects are not wrapped by Proxies, neither instrumented
const dontInstrument = new Set([Date, RegExp]);
function set(key, value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.set.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = proto.get.call(rawContext, key) !== value;
const result = proto.set.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, key);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' instead of the Proxy wrapper
// complex objects are wrapped with a Proxy of instrumented methods
// which switch the proxy to the raw object and to add reactive wiring
const handlers = new Map([[Map, collectionHandlers], [Set, collectionHandlers], [WeakMap, collectionHandlers], [WeakSet, collectionHandlers]]);
function deleteFn(value) {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.delete.apply(this, arguments);
function shouldInstrument(obj) {
if (typeof Node === 'function' && obj instanceof Node) {
return false;
}
// forward the operation before queueing reactions
const valueChanged = proto.has.call(rawContext, value);
const result = proto.delete.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, value);
queueReactionsForKey(rawContext, ITERATE);
}
return result;
return !dontInstrument.has(obj.constructor);
}
function clear() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.clear.apply(this, arguments);
}
// forward the operation before queueing reactions
const valueChanged = rawContext.size !== 0;
const result = proto.clear.apply(rawContext, arguments);
if (valueChanged) {
queueReactionsForKey(rawContext, ITERATE);
}
return result;
function getHandlers(obj) {
return handlers.get(obj.constructor);
}
function forEach() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.forEach.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.forEach.apply(rawContext, arguments);
}
function keys() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.keys.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.keys.apply(rawContext, arguments);
}
function values() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.values.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.values.apply(rawContext, arguments);
}
function entries() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto.entries.apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto.entries.apply(rawContext, arguments);
}
function iterator() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return proto[Symbol.iterator].apply(this, arguments);
}
registerRunningReactionForKey(rawContext, ITERATE);
return proto[Symbol.iterator].apply(rawContext, arguments);
}
function getSize() {
const rawContext = proxyToRaw.get(this);
const proto = getPrototypeOf(this);
if (!rawContext) {
return Reflect.get(proto, 'size', this);
}
registerRunningReactionForKey(rawContext, ITERATE);
return Reflect.get(proto, 'size', rawContext);
}
function instrumentMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
map.clear = clear;
map.forEach = forEach;
map.keys = keys;
map.values = values;
map.entries = entries;
map[Symbol.iterator] = iterator;
Object.defineProperty(map, 'size', { get: getSize });
}
function instrumentSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
set$$1.clear = clear;
set$$1.forEach = forEach;
set$$1.keys = keys;
set$$1.values = values;
set$$1.entries = entries;
set$$1[Symbol.iterator] = iterator;
Object.defineProperty(set$$1, 'size', { get: getSize });
}
function instrumentWeakMap(map) {
map.has = has;
map.get = get;
map.set = set;
map.delete = deleteFn;
}
function instrumentWeakSet(set$$1) {
set$$1.has = has;
set$$1.add = add;
set$$1.delete = deleteFn;
}
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' and when a Proxy instance is passed instead they break
// simple objects are not wrapped by Proxies or instrumented
// complex objects are wrapped and their methods are monkey patched
// to switch the proxy to the raw object and to add reactive wiring
var instrumentations = new Map([[Map.prototype, instrumentMap], [Set.prototype, instrumentSet], [WeakMap.prototype, instrumentWeakMap], [WeakSet.prototype, instrumentWeakSet], [Date.prototype, false], [RegExp.prototype, false]]);
const ENUMERATE = Symbol('enumerate');
// intercept get operations on observables to know which reaction uses their properties
function get$1(obj, key, receiver) {
// make sure to use the raw object here
const rawObj = proxyToRaw.get(obj) || obj;
// expose the raw object on observable.$raw
if (key === '$raw') {
return rawObj;
}
function get(obj, key, receiver) {
const result = Reflect.get(obj, key, receiver);

@@ -373,4 +303,6 @@ // do not register (observable.prop -> reaction) pairs for these cases

}
// make sure to use the raw object here, obj might be a Proxy because of inheritance
obj = proxyToRaw.get(obj) || obj;
// register and save (observable.prop -> runningReaction)
registerRunningReactionForKey(rawObj, key);
registerRunningReactionForKey(obj, key);
// if we are inside a reaction and observable.prop is an object wrap it in an observable too

@@ -391,3 +323,3 @@ // this is needed to intercept property access on that object too (dynamic observable tree)

// intercept set operations on observables to know when to trigger reactions
function set$1(obj, key, value, receiver) {
function set(obj, key, value, receiver) {
// make sure to do not pollute the raw object with observables

@@ -398,6 +330,9 @@ if (typeof value === 'object' && value !== null) {

// save if the value changed because of this set operation
// array 'length' is an exception here, because of it's exotic nature
const valueChanged = key === 'length' || value !== obj[key];
const valueChanged = value !== obj[key];
// length is lazy, it can change without an explicit length set operation
const prevLength = Array.isArray(obj) && obj.length;
// execute the set operation before running any reaction
const result = Reflect.set(obj, key, value, receiver);
// check if the length changed implicitly, because of out of bound set operations
const lengthChanged = prevLength !== false && prevLength !== obj.length;
// emit a warning and do not queue anything when another reaction is queued

@@ -409,9 +344,17 @@ // from an already running reaction

}
// if the target of the operation is not the raw receiver return
// (possible because of prototypal inheritance)
if (obj !== proxyToRaw.get(receiver)) {
return result;
}
// do not queue reactions if it is a symbol keyed property
// or the set operation resulted in no value change
// or if the target of the operation is not the raw object (possible because of prototypal inheritance)
if (typeof key !== 'symbol' && valueChanged && obj === proxyToRaw.get(receiver)) {
if (typeof key !== 'symbol' && valueChanged) {
queueReactionsForKey(obj, key);
queueReactionsForKey(obj, ENUMERATE);
}
// queue length reactions in case the length changed
if (lengthChanged) {
queueReactionsForKey(obj, 'length');
}
return result;

@@ -433,11 +376,4 @@ }

var handlers = { get: get$1, ownKeys, set: set$1, deleteProperty };
var baseHandlers = { get, ownKeys, set, deleteProperty };
function isObservable(obj) {
if (typeof obj !== 'object') {
throw new TypeError('First argument must be an object');
}
return proxyToRaw.has(obj);
}
function observable(obj = {}) {

@@ -447,37 +383,31 @@ if (typeof obj !== 'object') {

}
// if it is already an observable, return it
if (proxyToRaw.has(obj)) {
// if it is already an observable or it should not be wrapped, return it
if (proxyToRaw.has(obj) || !shouldInstrument(obj)) {
return obj;
}
return (
// if it already has a cached observable wrapper, return it
// if it is a special built-in object, instrument it then wrap it with an observable
// otherwise simply wrap the object with an observable
rawToProxy.get(obj) || instrumentObservable(obj) || createObservable(obj)
);
// if it already has a cached observable wrapper, return it
// otherwise create a new observable
return rawToProxy.get(obj) || createObservable(obj);
}
function instrumentObservable(obj) {
const instrument = instrumentations.get(Object.getPrototypeOf(obj));
// these objects break, when they are wrapped with proxies
if (instrument === false) {
return obj;
}
// these objects can be wrapped by Proxies, but require special instrumentation beforehand
if (typeof instrument === 'function') {
instrument(obj);
}
}
// wrap the object in a Proxy and save the obj-proxy, proxy-obj pairs
function createObservable(obj) {
// if it is a complex built-in object or a normal object, wrap it
const handlers = getHandlers(obj) || baseHandlers;
const observable = new Proxy(obj, handlers);
// save these to switch between the raw object and the wrapped object with ease later
rawToProxy.set(obj, observable);
proxyToRaw.set(observable, obj);
// init basic data structures to save and cleanup later (observable.prop -> reaction) connections
storeObservable(obj);
// save these to switch between the raw object and the wrapped object with ease later
proxyToRaw.set(observable, obj);
rawToProxy.set(obj, observable);
return observable;
}
function isObservable(obj) {
return proxyToRaw.has(obj);
}
function raw(obj) {
return proxyToRaw.get(obj) || obj;
}
exports.observe = observe;

@@ -487,2 +417,3 @@ exports.unobserve = unobserve;

exports.isObservable = isObservable;
exports.raw = raw;

@@ -489,0 +420,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

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

(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a.observer={})})(this,function(a){'use strict';function b(a){B.set(a,Object.create(null))}function c(a,b,c){const d=B.get(a);let e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function d(a,b,c){const d=B.get(a)[b];d&&Array.from(d).forEach(c)}function e(a){a.cleaners&&a.cleaners.forEach(f,a),a.cleaners=void 0}function f(a){a.delete(this)}function g(a,b,c,d){if(a.unobserved)throw new Error(`Unobserved reactions can not be executed. You tried to run a reaction for ${b}`);e(a),a.cleaners=[];try{return C=a,b.apply(c,d)}finally{C=void 0}}function h(a,b){C&&c(a,b,C)}function i(a,b){d(a,b,j)}function j(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function k(){return C!==void 0}function l({lazy:b=!1,scheduler:a}){if('boolean'!=typeof b)throw new TypeError(`options.lazy must be a boolean or undefined instead of ${b}`);if('object'==typeof a&&null!==a){if('function'!=typeof a.add||'function'!=typeof a.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==a&&'function'!=typeof a)throw new TypeError(`options.scheduler must be a function, an object or undefined instead of ${a}`)}function m(a){const b=E.get(this),c=H(this);return b?(h(b,a),c.has.apply(b,arguments)):c.has.apply(this,arguments)}function n(a){const b=E.get(this),c=H(this);return b?(h(b,a),c.get.apply(b,arguments)):c.get.apply(this,arguments)}function o(a){const b=E.get(this),c=H(this);if(!b)return c.add.apply(this,arguments);const d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(i(b,a),i(b,G)),e}function p(a,b){const c=E.get(this),d=H(this);if(!c)return d.set.apply(this,arguments);const e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(i(c,a),i(c,G)),f}function q(a){const b=E.get(this),c=H(this);if(!b)return c.delete.apply(this,arguments);const d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(i(b,a),i(b,G)),e}function r(){const a=E.get(this),b=H(this);if(!a)return b.clear.apply(this,arguments);const c=0!==a.size,d=b.clear.apply(a,arguments);return c&&i(a,G),d}function s(){const a=E.get(this),b=H(this);return a?(h(a,G),b.forEach.apply(a,arguments)):b.forEach.apply(this,arguments)}function t(){const a=E.get(this),b=H(this);return a?(h(a,G),b.keys.apply(a,arguments)):b.keys.apply(this,arguments)}function u(){const a=E.get(this),b=H(this);return a?(h(a,G),b.values.apply(a,arguments)):b.values.apply(this,arguments)}function v(){const a=E.get(this),b=H(this);return a?(h(a,G),b.entries.apply(a,arguments)):b.entries.apply(this,arguments)}function w(){const a=E.get(this),b=H(this);return a?(h(a,G),b[Symbol.iterator].apply(a,arguments)):b[Symbol.iterator].apply(this,arguments)}function x(){const a=E.get(this),b=H(this);return a?(h(a,G),Reflect.get(b,'size',a)):Reflect.get(b,'size',this)}function y(a={}){if('object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return E.has(a)?a:F.get(a)||z(a)||A(a)}function z(a){const b=I.get(Object.getPrototypeOf(a));return!1===b?a:void('function'==typeof b&&b(a))}function A(a){const c=new Proxy(a,K);return b(a),E.set(c,a),F.set(a,c),c}const B=new WeakMap;let C;const D=Symbol('is reaction'),E=new WeakMap,F=new WeakMap,G=Symbol('iterate'),H=Object.getPrototypeOf;var I=new Map([[Map.prototype,function(a){a.has=m,a.get=n,a.set=p,a.delete=q,a.clear=r,a.forEach=s,a.keys=t,a.values=u,a.entries=v,a[Symbol.iterator]=w,Object.defineProperty(a,'size',{get:x})}],[Set.prototype,function(a){a.has=m,a.add=o,a.delete=q,a.clear=r,a.forEach=s,a.keys=t,a.values=u,a.entries=v,a[Symbol.iterator]=w,Object.defineProperty(a,'size',{get:x})}],[WeakMap.prototype,function(a){a.has=m,a.get=n,a.set=p,a.delete=q}],[WeakSet.prototype,function(a){a.has=m,a.add=o,a.delete=q}],[Date.prototype,!1],[RegExp.prototype,!1]]);const J=Symbol('enumerate');var K={get:function(a,b,c){const d=E.get(a)||a;if('$raw'===b)return d;const e=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof e?e:(h(d,b),k()&&'object'==typeof e&&null!==e?y(e):F.get(e)||e)},ownKeys:function(a){return h(a,J),Reflect.ownKeys(a)},set:function(a,b,c,d){'object'==typeof c&&null!==c&&(c=E.get(c)||c);const e='length'===b||c!==a[b],f=Reflect.set(a,b,c,d);return k()?(console.error(`Mutating observables in reactions is forbidden. You set ${b} to ${c}.`),f):('symbol'!=typeof b&&e&&a===E.get(d)&&(i(a,b),i(a,J)),f)},deleteProperty:function(a,b){const c=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&b in a&&(i(a,b),i(a,J)),c}};a.observe=function(a,b={}){function c(){return g(c,a,this,arguments)}if('function'!=typeof a)throw new TypeError(`The first argument must be a function instead of ${a}`);if(a[D])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError(`The second argument must be an options object instead of ${b}`);return l(b),c.scheduler=b.scheduler,c.runId=0,c[D]=!0,b.lazy||c(),c},a.unobserve=function(a){if('function'!=typeof a||!a[D])throw new TypeError(`The first argument must be a reaction instead of ${a}`);a.unobserved||(a.unobserved=!0,e(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)},a.observable=y,a.isObservable=function(a){if('object'!=typeof a)throw new TypeError('First argument must be an object');return E.has(a)},Object.defineProperty(a,'__esModule',{value:!0})});
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a.observer={})})(this,function(a){'use strict';function b(a){y.set(a,Object.create(null))}function c(a,b,c){const d=y.get(a);let e=d[b];e?!e.has(c)&&(e.add(c),c.cleaners.push(e)):(d[b]=e=new Set,e.add(c),c.cleaners.push(e))}function d(a,b,c){const d=y.get(a)[b];d&&Array.from(d).forEach(c)}function e(a){a.cleaners&&a.cleaners.forEach(f,a),a.cleaners=void 0}function f(a){a.delete(this)}function g(a,b,c,d){if(a.unobserved)throw new Error(`Unobserved reactions can not be executed. You tried to run a reaction for ${b}`);e(a),a.cleaners=[];try{return z=a,b.apply(c,d)}finally{z=void 0}}function h(a,b){z&&c(a,b,z)}function i(a,b){d(a,b,j)}function j(a){'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function k(){return z!==void 0}function l(a,b={}){function c(){return g(c,a,this,arguments)}if('function'!=typeof a)throw new TypeError(`The first argument must be a function instead of ${a}`);if(a[A])throw new TypeError('The first argument must not be an already observed reaction');if('object'!=typeof b||null===b)throw new TypeError(`The second argument must be an options object instead of ${b}`);return m(b),c.scheduler=b.scheduler,c.runId=0,c[A]=!0,b.lazy||c(),c}function m({lazy:b=!1,scheduler:a}){if('boolean'!=typeof b)throw new TypeError(`options.lazy must be a boolean or undefined instead of ${b}`);if('object'==typeof a&&null!==a){if('function'!=typeof a.add||'function'!=typeof a.delete)throw new TypeError('options.scheduler object must have an add and delete method');}else if(void 0!==a&&'function'!=typeof a)throw new TypeError(`options.scheduler must be a function, an object or undefined instead of ${a}`)}function n(a){if('function'!=typeof a||!a[A])throw new TypeError(`The first argument must be a reaction instead of ${a}`);a.unobserved||(a.unobserved=!0,e(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}function o(a){return'function'==typeof Node&&a instanceof Node?!1:!H.has(a.constructor)}function p(a){return I.get(a.constructor)}function q(a,b,c){const d=Reflect.get(a,b,c);return'symbol'==typeof b||'function'==typeof d?d:(a=B.get(a)||a,h(a,b),k()&&'object'==typeof d&&null!==d?u(d):C.get(d)||d)}function r(a){return h(a,J),Reflect.ownKeys(a)}function s(a,b,c,d){'object'==typeof c&&null!==c&&(c=B.get(c)||c);const e=c!==a[b],f=Array.isArray(a)&&a.length,g=Reflect.set(a,b,c,d),h=!1!==f&&f!==a.length;return k()?(console.error(`Mutating observables in reactions is forbidden. You set ${b} to ${c}.`),g):a===B.get(d)?('symbol'!=typeof b&&e&&(i(a,b),i(a,J)),h&&i(a,'length'),g):g}function t(a,b){const c=b in a,d=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&c&&(i(a,b),i(a,J)),d}function u(a={}){if('object'!=typeof a)throw new TypeError('Observable first argument must be an object or undefined');return B.has(a)||!o(a)?a:C.get(a)||v(a)}function v(a){const c=p(a)||K,d=new Proxy(a,c);return C.set(a,d),B.set(d,a),b(a),d}function w(a){return B.has(a)}function x(a){return B.get(a)||a}const y=new WeakMap;let z;const A=Symbol('is reaction'),B=new WeakMap,C=new WeakMap,D=Symbol('iterate'),E=Object.getPrototypeOf,F={has(a){const b=B.get(this),c=E(this);return h(b,a),c.has.apply(b,arguments)},get(a){const b=B.get(this),c=E(this);return h(b,a),c.get.apply(b,arguments)},add(a){const b=B.get(this),c=E(this),d=!c.has.call(b,a),e=c.add.apply(b,arguments);return d&&(i(b,a),i(b,D)),e},set(a,b){const c=B.get(this),d=E(this),e=d.get.call(c,a)!==b,f=d.set.apply(c,arguments);return e&&(i(c,a),i(c,D)),f},delete(a){const b=B.get(this),c=E(this),d=c.has.call(b,a),e=c.delete.apply(b,arguments);return d&&(i(b,a),i(b,D)),e},clear(){const a=B.get(this),b=E(this),c=0!==a.size,d=b.clear.apply(a,arguments);return c&&i(a,D),d},forEach(){const a=B.get(this),b=E(this);return h(a,D),b.forEach.apply(a,arguments)},keys(){const a=B.get(this),b=E(this);return h(a,D),b.keys.apply(a,arguments)},values(){const a=B.get(this),b=E(this);return h(a,D),b.values.apply(a,arguments)},entries(){const a=B.get(this),b=E(this);return h(a,D),b.entries.apply(a,arguments)},[Symbol.iterator](){const a=B.get(this),b=E(this);return h(a,D),b[Symbol.iterator].apply(a,arguments)},get size(){const a=B.get(this),b=E(this);return h(a,D),Reflect.get(b,'size',a)}};var G={get(a,b,c){return a=b in E(a)?F:a,Reflect.get(a,b,c)}};const H=new Set([Date,RegExp]),I=new Map([[Map,G],[Set,G],[WeakMap,G],[WeakSet,G]]),J=Symbol('enumerate');var K={get:q,ownKeys:r,set:s,deleteProperty:t};a.observe=l,a.unobserve=n,a.observable=u,a.isObservable=w,a.raw=x,Object.defineProperty(a,'__esModule',{value:!0})});
{
"name": "@nx-js/observer-util",
"version": "3.1.4",
"description": "An NX utility, responsible for powerful transparent reactivity with ES6 Proxies.",
"version": "4.0.0",
"description": "Simple transparent reactivity with 100% language coverage. Made with ES6 Proxies.",
"main": "dist/cjs.es5.js",

@@ -13,2 +13,3 @@ "module": "dist/es.es5.js",

"test-builds": "node ./scripts/testBuilds.js",
"debug": "node ./scripts/debug.js",
"lint": "standard",

@@ -58,2 +59,3 @@ "lint-fix": "prettier --ignore-path '.gitignore' --write '**/!(bundle).js' && standard --fix",

"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-rollup-preprocessor": "^5.0.1",

@@ -60,0 +62,0 @@ "karma-source-map-support": "^1.2.0",

@@ -1,9 +0,7 @@

# The observer utility
# The Observer Utility
Simple transparent reactivity with 100% language coverage. Made with :heart: and ES6 Proxies.
[![Build](https://img.shields.io/circleci/project/github/nx-js/observer-util/master.svg)](https://circleci.com/gh/nx-js/observer-util/tree/master) [![Coverage Status](https://coveralls.io/repos/github/nx-js/observer-util/badge.svg)](https://coveralls.io/github/nx-js/observer-util) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Package size](http://img.badgesize.io/https://unpkg.com/@nx-js/observer-util/dist/umd.es6.min.js?compression=gzip&label=minzip_size)](https://unpkg.com/@nx-js/observer-util/dist/umd.es6.min.js) [![Version](https://img.shields.io/npm/v/@nx-js/observer-util.svg)](https://www.npmjs.com/package/@nx-js/observer-util) [![dependencies Status](https://david-dm.org/nx-js/observer-util/status.svg)](https://david-dm.org/nx-js/observer-util) [![License](https://img.shields.io/npm/l/@nx-js/observer-util.svg)](https://www.npmjs.com/package/@nx-js/observer-util)
Transparent reactivity without special syntax and with a **100% language observability** coverage. It uses **ES6 Proxies** internally to work seamlessly with a minimal interface.
[React Easy State](https://github.com/solkimicreb/react-easy-state) is a React state management solution - based on this library. This library is part of the [NX framework](https://nx-framework.com).
<details>

@@ -15,16 +13,16 @@ <summary><strong>Table of Contents</strong></summary>

* [Motivation](#motivation)
* [Bindings](#bindings)
* [Installation](#installation)
* [Usage](#usage)
* [Key features](#key-features)
+ [Observables](#observables)
+ [Reactions](#reactions)
+ [Reaction scheduling](#reaction-scheduling)
* [API](#api)
+ [Proxy = observable(object)](#proxy--observableobject)
+ [boolean = isObservable(object)](#boolean--isobservableobject)
+ [reaction = observe(function, config)](#reaction--observefunction-config)
+ [unobserve(reaction)](#unobservereaction)
+ [obj = raw(observable)](#obj--rawobservable)
* [Platform support](#platform-support)
* [API](#api)
+ [const object = observable(object)](#const-object--observableobject)
+ [const boolean = isObservable(object)](#const-boolean--isobservableobject)
+ [const function = observe(function)](#const-function--observefunction)
+ [unobserve(function)](#unobservefunction)
+ [unqueue(function)](#unqueuefunction)
+ [exec(function)](#execfunction)
+ [const promise = nextTick(function)](#const-promise--nexttickfunction)
+ [observable.$raw](#observableraw)
* [Examples](#examples)
* [Alternative builds](#alternative-builds)

@@ -37,151 +35,215 @@ * [Contributing](#contributing)

## Installation
## Motivation
```
$ npm install @nx-js/observer-util
```
Popular frontend frameworks - like Angular, React and Vue - use a reactivity system to automatically update the view when the state changes. This is necessary for creating modern web apps and staying sane at the same time.
## Usage
The Observer Utililty is a similar reactivity system, with a modern twist. It uses [ES6 Proxies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) to achieve true transparency and a 100% language coverage. Ideally you would like to manage your state with plain JS code and expect the view to update where needed. In practice some reactivity systems require extra syntax - like React's `setState`. Others have limits on the language features, which they can react on - like dynamic properties or the `delete` keyword. These are small nuisances, but they lead to long hours lost among special docs and related issues.
This library has two main functions. `observable` turns the passed object into an observable object and `observe` turns the passed function into a reaction. A reaction is automatically executed whenever an observable property - which is used inside the reaction - changes value. Reactions are executed in an async batch, after a small delay.
The Observer Utility aims to eradicate these edge cases. It comes with a tiny learning curve and with a promise that you won't have to dig up hidden docs and issues later. Give it a try, things will just work.
```js
import { observable, observe } from '@nx-js/observer-util'
## Bindings
const person = observable({ firstName: 'Bob', lastName: 'Smith' })
This is a framework independent library, which powers the reactivity system behind other state management solutions. These are the currently available bindings.
// this reaction automatically re-runs whenever person.firstName or person.lastName changes
observe(() => console.log(`${person.firstName} ${person.lastName}`))
- [React Easy State](https://github.com/solkimicreb/react-easy-state) is a state management solution for React with a minimal learning curve.
// this logs 'John Smith' to the console
setTimeout(() => person.firstName = 'John')
## Installation
```
$ npm install @nx-js/observer-util
```
## Key features
## Usage
- Any JavaScript code is correctly observed in reactions - including expando properties, loops, getters/setters, inheritance and ES6 collections. Check out the [examples](#examples) section for more.
The two building blocks of reactivity are **observables** and **reactions**. Observable objects represent the state and reactions are functions, that react to state changes. In case of transparent reactivity, these reactions are called automatically on relevant state changes.
- No special syntax or setup is required, you will likely use the `observable` and `observe` functions only.
### Observables
- Observable objects are not modified at all. The underlying raw object can be easily retrieved and used when you don't want to trigger reactions.
Observables are transparent Proxies, which can be created with the `observable` function. From the outside they behave exactly like plain JS objects.
- Triggered reactions run asynchronously, but always before the next repaint in browsers. Your reactions reach a stable and fresh state before repaints.
```js
import { observable } from '@nx-js/observer-util'
- Duplicates and loops are automatically removed from triggered reactions. This ensures that your code won't run twice without a reason.
const counter = observable({ num: 0 })
## Platform support
// observables behave like plain JS objects
counter.num = 12
```
- Node: 6.5 and above
- Chrome: 49 and above
- Firefox: 38 and above
- Safari: 10 and above
- Edge: 12 and above
- Opera: 36 and above
- IE is not supported
### Reactions
## API
Reactions are functions, which use observables. They can be created with the `observe` function and they are automatically executed whenever the observables - used by them - change.
### const object = observable(object)
#### Vanilla JavaScript
Creates and returns an observable object.
```js
import { observable, observe } from '@nx-js/observer-util'
- If no argument is provided, it returns an empty observable object.
- If an object is passed as argument, it wraps the passed object in an observable.
- If an observable object is passed, it simply returns the passed observable object.
const counter = observable({ num: 0 })
const countLogger = observe(() => console.log(counter.num))
```js
import { observable } from '@nx-js/observer-util'
const person = observable({ name: 'Ann' })
// this calls countLogger and logs 1
counter.num++
```
### const boolean = isObservable(object)
#### React Component
Returns true if the passed object is an observable, otherwise returns false.
```js
import { observable, isObservable } from '@nx-js/observer-util'
import { store, view } from 'react-easy-state'
const person = observable()
const isPersonObservable = isObservable(person)
// this is an observable store
const counter = store({
num: 0,
up () {
this.num++
}
})
// this is a reactive component, which re-renders whenever counter.num changes
const UserComp = view(() => <div onClick={counter.up}>{counter.num}</div>)
```
### const function = observe(function)
#### More examples
Turns the passed function into a reaction, then executes and returns it. A reaction automatically reruns when a property of an observable - which is used by the reaction - changes.
<details>
<summary>Dynamic properties</summary>
```js
import { observable, observe } from '@nx-js/observer-util'
const counter = observable({ num: 0 })
const profile = observable()
observe(() => console.log(profile.name))
// this logs the value of counter.num whenever it changes
const logger = observe(() => console.log(counter.num))
// logs 'Bob'
profile.name = 'Bob'
```
</details>
<details>
<summary>Nested properties</summary>
```js
import { observable, observe } from '@nx-js/observer-util'
### unobserve(function)
const person = observable({
name: {
first: 'John',
last: 'Smith'
},
age: 22
})
Unobserves the passed reaction. Unobserved reactions won't be automatically run anymore.
observe(() => console.log(`${person.name.first} ${person.name.last}`))
// logs 'Bob Smith'
person.name.first = 'Bob'
```
</details>
<details>
<summary>Computed properties</summary>
```js
import { observable,observe, unobserve } from '@nx-js/observer-util'
import { observable, observe } from '@nx-js/observer-util'
const counter = observable({ num: 0 })
const logger = observe(() => console.log(counter.num))
const person = observable({
firstName: 'Bob',
lastName: 'Smith',
get name () {
return `${firstName} ${lastName}`
}
})
// after this counter.num won't be automatically logged on changes
unobserve(logger)
observe(() => console.log(person.name))
// logs 'Ann Smith'
observable.firstName = 'Ann'
```
</details>
<details>
<summary>Conditionals</summary>
```js
import { observable, observe } from '@nx-js/observer-util'
### unqueue(function)
const person = observable({
gender: 'male',
name: 'Potato'
})
Removes the the reaction function from the queue of triggered reactions. This means that the reaction won't run in the next batch, unless another observable mutation triggers it.
observe(() => {
if (person.gender === 'male') {
console.log(`Mr. ${person.name}`)
} else {
console.log(`Ms. ${person.name}`)
}
})
// logs 'Ms. Potato'
person.gender = 'female'
```
</details>
<details>
<summary>Arrays</summary>
```js
import { observe, unqueue } from '@nx-js/observer-util'
import { observable, observe } from '@nx-js/observer-util'
const counter = observable({ num: 0 })
const logger = observe(() => console.log(counter.num))
const users = observable([])
// counter.num is changed and it queues the logger reaction
counter.num++
observe(() => console.log(users.join(', ')))
// this removes the logger reaction from the queue, so it won't run
unqueue(logger)
// logs 'Bob'
users.push('Bob')
// logs 'Bob, John'
users.push('John')
// logs 'Bob'
users.pop()
```
</details>
<details>
<summary>ES6 collections</summary>
```js
import { observable, observe } from '@nx-js/observer-util'
### exec(function)
const people = observable(new Map())
Immediately runs the passed reaction. Never run a reaction directly, use this method instead. Running the reaction with a direct call may cause it to not discover observable property access in some of its parts.
observe(() => {
for (let [name, age] of people) {
console.log(`${name}, ${age}`)
}
})
```js
import { observable, observe, exec } from '@nx-js/observer-util'
// logs 'Bob, 22'
people.set('Bob', 22)
const person = observable({ name: 'Bob' })
const logger = observe(() => console.log(person.name))
exec(logger)
// logs 'Bob, 22' and 'John, 35'
people.set('John', 35)
```
</details>
<details>
<summary>Inherited properties</summary>
```js
import { observable, observe } from '@nx-js/observer-util'
### const promise = nextTick(function)
const defaultUser = observable({
name: 'Unknown',
job: 'developer'
})
const user = observable(Object.create(defaultUser))
Runs the passed callback after the queued reactions run. It also returns a Promise, which resolves after the reactions. This comes handy for testing.
// logs 'Unknown is a developer'
observe(() => console.log(`${user.name} is a ${user.job}`))
```js
import { observable, observe, nextTick } from '@nx-js/observer-util'
// logs 'Bob is a developer'
user.name = 'Bob'
let dummy
const counter = observable({num: 0})
observe(() => dummy = counter.num)
// logs 'Bob is a stylist'
user.job = 'stylist'
counter.num = 7
await nextTick()
// the reactions ran during the tick, the 'dummy' is already updated to be 7
expect(dummy).to.equal(7)
// logs 'Unknown is a stylist'
delete user.name
```
</details>
### observable.$raw
**This is all you need to know to get started!** The following sections are about advanced topics - like custom reaction scheduling and cleanup.
Every observable object has a `$raw` virtual property. It can be used to access the underlying non-observable object. Modifying and accessing the raw object doesn't trigger reactions.
### Reaction scheduling
#### Using `$raw` for property access in reactions
Reactions are scheduled to run whenever the relevant observable state changes. The default scheduler runs the reactions synchronously, but custom schedulers can be passed to change this behavior. Schedulers are usually functions which receive the scheduled reaction as argument.

@@ -191,164 +253,160 @@ ```js

const person = observable()
const logger = observe(() => console.log(person.name))
// this scheduler delays reactions by 1 second
const scheduler = reaction => setTimeout(reaction, 1000)
// this logs 'Bob'
setTimeout(() => person.name = 'Bob')
const person = observable({ name: 'Josh' })
observe(() => console.log(person.name), { scheduler })
// this won't log anything
setTimeout(() => person.$raw.name = 'John')
// this logs 'Barbie' after a one second delay
person.name = 'Barbie'
```
#### Using `$raw` at observable mutations
Alternatively schedulers can be objects with an `add` and `delete` method. Check out the below examples for more.
#### More examples
<details>
<summary>React Scheduler</summary>
The React scheduler simply calls `setState` on relevant observable changes. This delegates the render scheduling to React Fiber. It works roughly like this.
```js
import { observable, observe } from '@nx-js/observer-util'
import { observe } from '@nx-js/observer-util'
const person = observable({ age: 20 })
observe(() => console.log(`${person.name}: ${person.$raw.age}`))
class ReactiveComp extends BaseComp {
constructor () {
// ...
this.render = observe(this.render, {
scheduler: () => this.setState()
})
}
}
// this logs 'Bob: 20'
setTimeout(() => person.name = 'Bob')
// this won't log anything
setTimeout(() => person.age = 33)
```
</details>
<details>
<summary>Batched updates with ES6 Sets</summary>
## Examples
Schedulers can be objects with an `add` and `delete` method, which schedule and unschedule reactions. ES6 Sets can be used as a scheduler, that automatically removes duplicate reactions.
#### Observing expando properties
```js
import { observable, observe } from '@nx-js/observer-util'
const profile = observer.observable()
observe(() => console.log(profile.name))
const reactions = new Set()
const person = observable({ name: 'Josh' })
observe(() => console.log(person), { scheduler: reactions })
// logs 'Bob'
setTimeout(() => profile.name = 'Bob')
// this throttles reactions to run with a minimal 1 second interval
setInterval(() => {
reactions.forEach(reaction => reaction())
}, 1000)
// these will cause { name: 'Barbie', age: 30 } to be logged once
person.name = 'Barbie'
person.age = 87
```
</details>
<details>
<summary>Batched updates with queues</summary>
#### Observing conditionals
Queues from the [Queue Util](https://github.com/nx-js/queue-util) can be used to implement complex scheduling patterns by combining automatic priority based and manual execution.
```js
import { observable, observe } from '@nx-js/observer-util'
import { Queue, priorities } from '@nx-js/queue-util'
const person = observable({
gender: 'male',
name: 'Potato'
})
const scheduler = new Queue(priorities.LOW)
const person = observable({ name: 'Josh' })
observe(() => console.log(person), { scheduler })
observe(() => {
if (person.gender === 'male') {
console.log(`Mr. ${person.name}`)
} else {
console.log(`Ms. ${person.name}`)
}
})
// logs 'Ms. Potato'
setTimeout(() => person.gender = 'female')
// these will cause { name: 'Barbie', age: 30 } to be logged once
// when everything is idle and there is free time to do it
person.name = 'Barbie'
person.age = 87
```
#### Observing nested properties
Queues are automatically scheduling reactions - based on their priority - but they can also be stopped, started and cleared manually at any time. Learn more about them [here]().
</details>
```js
import { observable, observe } from '@nx-js/observer-util'
## API
const person = observable({
name: {
first: 'John',
last: 'Smith'
},
age: 22
})
### Proxy = observable(object)
//
observe(() => console.log(`${person.name.first} ${person.name.last}`))
Creates and returns a proxied observable object, which behaves just like the originally passed object. The original object is **not modified**.
// logs 'Bob Smith'
setTimeout(() => person.name.first = 'Bob')
```
- If no argument is provided, it returns an empty observable object.
- If an object is passed as argument, it wraps the passed object in an observable.
- If an observable object is passed, it returns the passed observable object.
#### Observing native getters/setters
### boolean = isObservable(object)
```js
import { observable, observe } from '@nx-js/observer-util'
Returns true if the passed object is an observable, returns false otherwise.
const person = observable({
firstName: 'Bob',
lastName: 'Smith',
get name () {
return `${firstName} ${lastName}`
}
})
### reaction = observe(function, config)
observe(() => console.log(person.name))
Wraps the passed function with a reaction, which behaves just like the original function. The reaction is automatically scheduled to run whenever an observable - used by it - changes. The original function is **not modified**.
// logs 'Ann Smith'
setTimeout(() => observable.firstName = 'Ann')
```
`observe` also accepts an optional config object with the following options.
#### Observing arrays
- `lazy`: A boolean, which controls if the reaction is executed when it is created or not. If it is true, the reaction has to be called once manually to trigger the reactivity process. Defaults to false.
```js
import { observable, observe } from '@nx-js/observer-util'
- `scheduler`: A function, which is called with the reaction when it is scheduled to run. It can also be an object with an `add` and `delete` method - which schedule and unschedule reactions. The default scheduler runs the reaction synchronously on related observable mutations.
const users = observable([])
### unobserve(reaction)
observe(() => console.log(users.join(', ')))
Unobserves the passed reaction. Unobserved reactions won't be automatically run anymore.
// logs 'Bob'
setTimeout(() => users.push('Bob'))
```js
import { observable, observe, unobserve } from '@nx-js/observer-util'
// logs 'Bob, John'
setTimeout(() => users.push('John'))
const counter = observable({ num: 0 })
const logger = observe(() => console.log(counter.num))
// logs 'Bob'
setTimeout(() => users.pop())
// after this the logger won't be automatically called on counter.num changes
unobserve(logger)
```
#### Observing ES6 collections
### obj = raw(observable)
Original objects are never modified, but transparently wrapped by observable proxies. `raw` can access the original non-reactive object. Modifying and accessing properties on the raw object doesn't trigger reactions.
#### Using `raw` at property access
```js
import { observable, observe } from '@nx-js/observer-util'
import { observable, observe, raw } from '@nx-js/observer-util'
const people = observable(new Map())
const person = observable()
const logger = observe(() => console.log(person.name))
observe(() => {
for (let [name, age] of people) {
console.log(`${name}, ${age}`)
}
})
// this logs 'Bob'
person.name = 'Bob'
// logs 'Bob, 22'
setTimeout(() => people.set('Bob', 22))
// logs 'Bob, 22' and 'John, 35'
setTimeout(() => people.set('John', 35))
// `name` is used from the raw non-reactive object, this won't log anything
raw(person).name = 'John'
```
#### Observing inherited properties
#### Using `raw` at property mutation
```js
import { observable, observe } from '@nx-js/observer-util'
import { observable, observe, raw } from '@nx-js/observer-util'
const defaultUser = observable({
name: 'Unknown',
job: 'developer'
})
const user = observable(Object.create(defaultUser))
const person = observable({ age: 20 })
observe(() => console.log(`${person.name}: ${raw(person).age}`))
// logs 'Unknown is a developer'
observe(() => console.log(`${user.name} is a ${user.job}`))
// this logs 'Bob: 20'
person.name = 'Bob'
// logs 'Bob is a developer'
setTimeout(() => user.name = 'Bob')
// `age` is used from the raw non-reactive object, this won't log anything
person.age = 33
```
// logs 'Bob is a stylist'
setTimeout(() => user.job = 'stylist')
## Platform support
// logs 'Unknown is a stylist'
setTimeout(() => delete user.name)
```
- Node: 6.5 and above
- Chrome: 49 and above
- Firefox: 38 and above
- Safari: 10 and above
- Edge: 12 and above
- Opera: 36 and above
- IE is not supported

@@ -355,0 +413,0 @@ ## Alternative builds

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