Socket
Socket
Sign inDemoInstall

@politie/sherlock

Package Overview
Dependencies
1
Maintainers
7
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.8 to 3.3.9

utils/is-error.d.ts

2

derivable/base-derivable.d.ts

@@ -33,3 +33,3 @@ import { Derivable, MaybeFinalState } from '../interfaces';

getMaybeFinalState(): MaybeFinalState<V>;
getState(): import("../interfaces").State<V>;
getState(): typeof import("../symbols").unresolved | import("../utils").ErrorWrapper | V;
abstract [internalGetState](): MaybeFinalState<V>;

@@ -36,0 +36,0 @@ /**

@@ -1,3 +0,4 @@

import { MaybeFinalState, SettableDerivable } from '../interfaces';
import { MaybeFinalState, SettableDerivable, State } from '../interfaces';
import { connect, disconnect, internalGetState, rollback } from '../symbols';
import { ErrorWrapper, FinalWrapper } from '../utils';
import { BaseDerivable } from './base-derivable';

@@ -26,3 +27,3 @@ export declare abstract class PullDataSource<V> extends BaseDerivable<V> implements SettableDerivable<V> {

*/
[internalGetState](): MaybeFinalState<V>;
[internalGetState](): typeof import("../symbols").unresolved | ErrorWrapper | V | FinalWrapper<State<V>>;
/**

@@ -29,0 +30,0 @@ * Sets the value of this datasource, throws when not settable, fires reactors when expected.

import { Derivable, MaybeFinalState, State } from '../interfaces';
import { dependencies, dependencyVersions, disconnect, finalize, internalGetState, mark, rollback } from '../symbols';
import { dependencies, dependencyVersions, disconnect, finalize, internalGetState, mark, rollback, unresolved } from '../symbols';
import { TrackedObservable, TrackedReactor } from '../tracking';
import { FinalWrapper } from '../utils';
import { ErrorWrapper, FinalWrapper } from '../utils';
import { BaseDerivable } from './base-derivable';

@@ -18,3 +18,3 @@ export declare abstract class BaseDerivation<V> extends BaseDerivable<V> implements Derivable<V> {

*/
[internalGetState](): MaybeFinalState<V>;
[internalGetState](): typeof unresolved | ErrorWrapper | V | FinalWrapper<State<V>>;
/**

@@ -21,0 +21,0 @@ * Mark this derivation and all observers of this derivation as "possible outdated" or "state unknown". If this derivation is already

@@ -6,3 +6,3 @@ import * as symbols from './symbols';

export { processChangedState } from './transaction';
export { augmentStack } from './utils';
export { augmentStack, isError } from './utils';
export { symbols };
{
"name": "@politie/sherlock",
"version": "3.3.8",
"version": "3.3.9",
"private": false,

@@ -55,10 +55,10 @@ "description": "A reactive programming library for JavaScript applications, built with TypeScript.",

"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-commonjs": "^21.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@types/jest": "^26.0.23",
"@types/node": "^15.6.1",
"@types/jest": "^27.0.2",
"@types/node": "^16.10.2",
"expect-more-jest": "^5.4.0",
"gzip-size": "^6.0.0",
"immutable": "^4.0.0-rc.12",
"jest": "^27.0.3",
"jest-extended": "^0.11.5",
"nodemon": "^2.0.4",

@@ -76,4 +76,4 @@ "npm-run-all": "^4.1.5",

"tslint": "^6.1.2",
"typescript": "^3.9.2"
"typescript": "^4.4.3"
}
}

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

Object.defineProperty(exports,"__esModule",{value:!0});var t,n=require("tslib"),i=Symbol("autoCacheMode"),r=Symbol("connect"),e=Symbol("dependencies"),o=Symbol("dependencyVersions"),u=Symbol("derivableAtom"),s=Symbol("disconnect"),c=Symbol("emptyCache"),f=Symbol("finalize"),h=Symbol("internalGetState"),a=Symbol("mark"),v=Symbol("observers"),l=Symbol("rollback"),b=Symbol("sherlockInstances"),d=Symbol("unresolved"),p=Object.freeze({__proto__:null,autoCacheMode:i,connect:r,dependencies:e,dependencyVersions:o,derivableAtom:u,disconnect:s,emptyCache:c,finalize:f,internalGetState:h,mark:a,observers:v,rollback:l,sherlockInstances:b,unresolved:d});function w(){return!!t}function y(n){t?t.t[n.id]=n:n[f]()}function m(n,i,r){t&&k(t,n,i,r)}function O(n){if(t)j(n,t.i);else{var i=[];j(n,i),g(i)}}function j(t,n){for(var i=0,r=t[v];i<r.length;i++)r[i][a](n)}function g(t){for(var n=0,i=t;n<i.length;n++)i[n].o()}function x(n){var i;t={u:[],h:{},v:{},t:{},i:[],l:t};try{i=n()}catch(n){throw function(){var n=t;if(!n)throw Error();t=n.l,n.u.forEach((function(t){return t[l](n.h[t.id],n.v[t.id])}))}(),n}return function(){var n,i=t;if(!i)throw Error();(t=i.l)?(i.u.forEach((function(n){return k(t,n,i.h[n.id],i.v[n.id])})),(n=t.i).push.apply(n,i.i),Object.assign(t.t,i.t)):(Object.values(i.t).forEach((function(t){return t[f]()})),g(i.i))}(),i}function S(t){return w()?t():x(t)}function _(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return S((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&_(i.value)}}function k(t,n,i,r){var e=n.id;e in t.h||(t.u.push(n),t.h[e]=i,t.v[e]=r)}var E=Object.getOwnPropertyDescriptors||function(t){for(var n={},i=0,r=R(t);i<r.length;i++){var e=r[i];n[e]=Object.getOwnPropertyDescriptor(t,e)}return n},R="undefined"!=typeof Reflect?Reflect.ownKeys:function(t){return n.__spreadArrays(Object.getOwnPropertyNames(t),Object.getOwnPropertySymbols(t))};function A(t){return Array.isArray(t)?function(t){try{return Object.defineProperties(new t.constructor,E(t))}catch(t){throw Object.assign(Error("could not clone Array: "+(t&&t.message)),{jse_cause:t})}}(t):Object.create(Object.getPrototypeOf(t),E(t))}var T={equals:function(t,n){return(i=t)&&"function"==typeof i.equals&&!!t.equals(n);var i},plucker:{get:function(t,n){return C(t)?t.get(n):t[n]},set:function(t,n,i){if(C(n)){if("function"==typeof n.set)return n.set(i,t);throw Error("object is readonly")}var r=A(n);return r[i]=t,r}},debugMode:!1};function C(t){return t&&"function"==typeof t.get}function D(t,n){return Object.is(t,n)||T.equals(t,n)}var F=function(){function t(t){this.error=t}return t.prototype.equals=function(n){return this===n||n instanceof t&&D(this.error,n.error)},t}(),I=function(){function t(t){this.value=t}return t.wrap=function(n){return n instanceof t?n:new t(n)},t.unwrap=function(n){return n instanceof t?n.value:n},t.map=function(n,i){return n instanceof t?t.wrap(i(n.value)):i(n)},t.prototype.equals=function(n){return this===n||n instanceof t&&D(this.value,n.value)},t}();function M(t,n){var i=n.creationStack;return i?Object.defineProperty(A(t),"stack",{value:t.stack+"\n"+i}):t}function V(t,n){if(t instanceof I){var i=V(t.value,n);if(i!==t.value)return I.wrap(i)}return n.creationStack&&t instanceof F?new F(M(t.error,n)):t}function q(t){if(T.debugMode){var n=Error().stack;return t.constructor.name+" created:\n"+(n&&n.substr(n.indexOf("\n")+1))}}var z,B,G,N,P=0;function U(){return P++}function L(t){for(var n=z;n;){if(n.p===t)throw M(Error("cyclic dependency between derivables detected"),t);n=n.m}z={p:t,O:0,m:z,t:{}}}function $(){var t=z;if(!t)throw Error("No active recording!");z=t.m;for(var n=t.O,i=t.p,r=t.t,u=i[e],s=i[o],c=n,f=u.length;c<f;c++)Y(u[c],i);u.length=n;for(var h=0,a=u;h<a.length;h++){var v=a[h];s[v.id]=v.version}Object.values(r).forEach(y)}function H(){return!!z}function J(){if(!z)return!1;for(var t=z.O,n=z.t,i=z.p[e],r=0;r<t;r++)if(!(i[r].id in n))return!1;return!0}function K(t){var n=z;z=void 0;try{return t()}finally{z=n}}function Q(t){z?z.t[t.id]=t:y(t)}function W(t,n){if(z&&!t.finalized){n&&(z.t[t.id]=t);var i=z.p,r=i[e];if(r[z.O]===t)z.O++;else{var o=r.indexOf(t);o<0?(X(t,i),z.O===r.length?r.push(t):(r.push(r[z.O]),r[z.O]=t),z.O++):o>z.O&&(r[o]=r[z.O],r[z.O]=t,z.O++)}}}function X(t,n){var i=t[v];i.push(n),1!==i.length||t.connected||t[r]()}function Y(t,n){var r=t[v],e=r.indexOf(n);if(e<0)throw Error("Inconsistent state!");r.splice(e,1),0===r.length&&t.connected&&(t[i]?Z(t):t[s]())}function Z(t){B?B.push(t):(B=[t],setTimeout((function(){var t=B;B=void 0,t.forEach((function(t){return t.connected&&0===t[v].length&&t[s]()}))}),0))}var tt=function(){function t(){this.id=U(),this.creationStack=q(this),this[G]=[],this[N]=!1,this.connected=!1,this.j=void 0,this.finalized=!1}return t.prototype.autoCache=function(){return this[i]=!0,this},t.prototype.getMaybeFinalState=function(){return this.connected||(this[i]?(this[r](),Z(this)):H()&&this[r]()),this[h]()},t.prototype.getState=function(){return I.unwrap(this.getMaybeFinalState())},t.prototype[(G=v,N=i,r)]=function(){this.finalized||nt(this,!0)},t.prototype[s]=function(){nt(this,!1)},t.prototype[f]=function(){this.finalized=!0,this.connected&&this[s]()},t}();function nt(t,n){t.connected=n,t.j&&K((function(){return t.j.set(n)}))}var it,rt,et=function(t){function i(n){var i=t.call(this)||this;return i.version=0,i.g=V(n,i),i.S()&&i[f](),i}return n.__extends(i,t),Object.defineProperty(i.prototype,"settable",{get:function(){return!this.S()},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this.g instanceof I},i.prototype[h]=function(){return W(this,this.S()),this.g},i.prototype.set=function(t){var n=this.g;if(!D(t,n)){if(this.S())throw M(Error("cannot set a final derivable"),this);this.g=V(t,this),m(this,n,this.version++),O(this),this.S()&&Q(this)}},i.prototype[l]=function(t,n){this.g=t,this.version=n,j(this,[])},i}(tt),ot=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n._=c,n.version=0,n}return n.__extends(i,t),i.prototype.S=function(){return this._ instanceof I},i.prototype[h]=function(){return this.connected?(W(this,this.S()),this._):this.S()?this._:this.k()},i.prototype.set=function(t){if(!this.acceptNewValue)throw M(Error("DataSource is not settable"),this);this.acceptNewValue(t)},i.prototype.checkForChanges=function(){var t=this;if(this.connected){var n=K((function(){return t.k()})),i=this._;D(n,i)||(this._=n,m(this,i,this.version++),O(this))}},i.prototype.k=function(){try{return this.calculateCurrentValue()}catch(t){return new F(M(t,this))}},i.prototype[l]=function(t,n){this.version++,j(this,[])},i.prototype[r]=function(){t.prototype[r].call(this),this.connected&&this.checkForChanges()},i.prototype[s]=function(){t.prototype[s].call(this),this.finalized||(this._=c)},Object.defineProperty(i.prototype,"settable",{get:function(){return!!this.acceptNewValue},enumerable:!1,configurable:!0}),i}(tt);function ut(t){return t instanceof tt?t.get():t}function st(t){return t instanceof tt?t.value:t}var ct=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n.R=!1,n._=c,n.A=0,n}return n.__extends(i,t),Object.defineProperty(i.prototype,"version",{get:function(){return this.T(),this.A},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this._ instanceof I},i.prototype[h]=function(){if(this.connected)return this.T(),W(this,this.S()),this._;if(this.S())return this._;var t=this.C();return t instanceof I&&(this._=t,m(this,void 0,this.A++),Q(this)),t},i.prototype.T=function(){this.connected&&!this.R&&(this._!==c&&(this.R=this.S()||this.D()),this.R||this.F())},i.prototype.F=function(){var t=this.C();D(t,this._)||(this._=t,m(this,void 0,this.A++),this.S()&&Q(this)),this.R=!0},i.prototype[a]=function(t){this.R&&(this.R=!1,j(this,t))},i.prototype[l]=function(t,n){this._=c,this.A=n,this[a]([])},i.prototype[s]=function(){t.prototype[s].call(this),this.R=!1,this.finalized||(this._=c)},i}(tt),ft=0,ht=function(t){function i(n,i){var r=t.call(this)||this;return r.I=n,r.M=i,r[it]=[],r[rt]={},r}return n.__extends(i,t),i.prototype.F=function(){L(this);try{t.prototype.F.call(this)}finally{$()}},i.prototype.C=function(){++ft;try{var t=this.M?this.I.apply(this,this.M.map(ut)):this.I();return J()?I.wrap(t):t}catch(t){return t===d?d:new F(M(t,this))}finally{--ft}},i.prototype.D=function(){var t=this;return this[e].every((function(n){return t[o][n.id]===n.version}))},i.prototype[(it=e,rt=o,s)]=function(){for(var n=0,i=this[e];n<i.length;n++)Y(i[n],this);this[e].length=0,t.prototype[s].call(this)},i.prototype[f]=function(){t.prototype[f].call(this),this.I=void 0,this.M=void 0},i}(ct),at=function(t){function i(n,i){var r=n.get,e=n.set,o=t.call(this,r,i)||this;return o.V=e,o}return n.__extends(i,t),i.prototype.set=function(t){if(this.finalized)throw M(Error("cannot set a final derivable"),this);this.M?this.V.apply(this,n.__spreadArrays([t],this.M.map(st))):this.V(t)},n.__decorate([_()],i.prototype,"set",null),i}(ht),vt=function(t){function i(n,i){var r=t.call(this)||this;return r.q=n,r.B=i,r.G=0,r}return n.__extends(i,t),i.prototype.F=function(){this.G=this.q.version,t.prototype.F.call(this)},i.prototype.C=function(){var t=this;try{return K((function(){var n=t.q.getMaybeFinalState();return I.map(n,(function(n){return t.B(n)}))}))}catch(t){return new F(M(t,this))}},i.prototype.D=function(){return this.G===this.q.version},i.prototype[r]=function(){t.prototype[r].call(this),this.connected&&X(this.q,this)},i.prototype[s]=function(){Y(this.q,this),t.prototype[s].call(this)},i.prototype[f]=function(){t.prototype[f].call(this),this.q=void 0,this.B=void 0},i}(ct),lt=function(t){function i(n,i,r){var e=t.call(this,n,i)||this;return e.N=r,e}return n.__extends(i,t),i.prototype.set=function(t){var n=this;if(this.finalized)throw M(Error("cannot set a final derivable"),this);this.q.set(I.map(t,(function(t){return n.N(t)})))},Object.defineProperty(i.prototype,"settable",{get:function(){return this.q.settable},enumerable:!1,configurable:!0}),i.prototype[f]=function(){t.prototype[f].call(this),this.N=void 0},i}(vt);function bt(t){return t.settable}function dt(t){return"function"==typeof t?t():ut(t)}function pt(){var t=this.getState();return t===d||t instanceof F?void 0:t}function wt(t){return this.set(t)}function yt(t){return t instanceof tt}var mt=I.wrap(d);function Ot(t){return new et(t)}function jt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new ht(t,n.length?n:void 0)}function gt(t){return Ot.final(t)}function xt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new at(t,n.length?n:void 0)}function St(t){var n=this,i=T.plucker,r=i.get,e=i.set,o=this;return yt(t)?xt({get:function(){return r.call(this,o.get(),t.get())},set:function(n){o.set(e.call(this,n,o.value,t.get()))}}):o.map((function(i){return r.call(n,i,t)}),(function(i){return e.call(n,i,o.value,t)}))}function _t(){this.set(d)}function kt(t){this.set(new F(t))}function Et(t){this.set(I.wrap(t))}function Rt(t){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];this.set(t.apply(void 0,n.__spreadArrays([this.value],i.map(st))))}!function(t){function n(t){return new et(I.wrap(t))}t.unresolved=function(){return new et(d)},t.error=function(t){return new et(new F(t))},t.final=n,function(t){t.unresolved=function(){return new et(mt)},t.error=function(t){return new et(I.wrap(new F(t)))}}(n=t.final||(t.final={}))}(Ot||(Ot={})),function(t){t.unresolved=function(){return Ot.final.unresolved()},t.error=function(t){return Ot.final.error(t)}}(gt||(gt={}));var At=new et(I.wrap(!0)),Tt=new et(I.wrap(!1)),Ct=Symbol("skipped"),Dt=I.wrap(Ct);function Ft(t,n,i,r){if(void 0!==t){var e=t?At:Tt;if(!function(t,n){return t===n||t instanceof et&&t.g instanceof I&&t.g.value===n}(t,i)){if("function"==typeof t){var o=t;t=new ht((function(){return o(n)})).derive(ut)}return yt(t)?void 0!==r?t.mapState((function(t){return t===r?I.wrap(t):t})):t:e}}}function It(t){var n=I.unwrap(t);return n!==d&&!(n instanceof F)}Object.defineProperties(tt.prototype,{get:{value:function(){var t=this.getState();if(t instanceof F)throw t.error;if(t!==d)return t;if(ft>0)throw d;throw M(Error("Could not get value, derivable is unresolved"),this)}},getOr:{value:function(t){var n=this.getState();if(n instanceof F)throw n.error;return n===d?dt(t):n}},value:{get:pt},resolved:{get:function(){return this.getState()!==d}},settable:{value:!1},final:{get:function(){return this.getMaybeFinalState()instanceof I}},errored:{get:function(){return this.getState()instanceof F}},error:{get:function(){var t=this.getState();return t instanceof F?t.error:void 0}},connected$:{get:function(){return this.j||(this.j=new et(this.connected))}},derive:{value:function(t){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];return new ht(t,n.__spreadArrays([this],i))}},map:{value:function(t,n){var i=function(n){return n===d||n instanceof F?n:t.call(this,n)};return n&&bt(this)?new lt(this,i,(function(t){return t===d||t instanceof F?t:n.call(this,t,this.q.value)})):new vt(this,i)}},mapState:{value:function(t,n){return n&&bt(this)?new lt(this,t,(function(t){return n.call(this,t,this.q.getState())})):new vt(this,t)}},flatMap:{value:function(t){return this.map(t).derive((function(t){return t.getState()}))}},pluck:{value:function(t){var n=this,i=T.plucker.get;return yt(t)?this.derive(i,t):this.map((function(r){return i.call(n,r,t)}))}},fallbackTo:{value:function(t){var n=this;return yt(t)?jt((function(){return n.getOr(t)})):this.mapState((function(n){return n===d?dt(t):n}))}},take:{value:function(t){var n=this,i=t.from,r=t.when,e=t.until,o=t.once,u=t.stopOnError,s=t.skipFirst,c=Ft(i,this,!0,!0),f=Ft(r,this,!0),h=Ft(e,this,!1,!0),a=s?new et(d):void 0;if(!(c||f||h||o||u||a))return this;var v=(h||f)&&new et(d);function l(t){return v&&v.set(t),t}return new ht((function(){if(c&&!c.get())return d;if(h&&h.get())return l(I.wrap(v.g));if(f&&!f.getOr(!1))return v.g;var t=n.getMaybeFinalState();if(a&&!Dt.equals(a.g)){if(!It(t))return l(t);if(a.g===d||D(t,a.g))return a.set(t),l(d);a.set(Dt)}return l(o&&It(t)||u&&t instanceof F?I.wrap(t):t)}))}},and:{value:function(t){return yt(t)?this.derive((function(n){return n&&t.get()})):this.map((function(n){return n&&t}))}},or:{value:function(t){return yt(t)?this.derive((function(n){return n||t.get()})):this.map((function(n){return n||t}))}},not:{value:function(){return this.map((function(t){return!t}))}},is:{value:function(t){return yt(t)?this.derive(D,t):this.map((function(n){return D(n,t)}))}}}),[et,ot,lt,at].forEach((function(t){return Object.defineProperties(t.prototype,{value:{get:pt,set:wt},swap:{value:Rt},pluck:{value:St}})})),[et,lt].forEach((function(t){return Object.defineProperties(t.prototype,{unset:{value:_t},setError:{value:kt},setFinal:{value:Et}})})),Object.defineProperties(at.prototype,{settable:{value:!0}}),tt.prototype.react=function(t,n){var i=this;return K((function(){return Vt.create(i,t,n)}))},tt.prototype.toPromise=function(t){var i=this;return new Promise((function(r,e){return i.react(r,n.__assign(n.__assign({},t),{once:!0,onError:function(t,n){n(),e(t)}}))}))};var Mt,Vt=function(){function t(t,n,i,r){this.P=t,this.U=n,this.L=i,this.ended=r,this.$=!1,this.id=U(),this.H=0,this.creationStack=q(this),this.J=c}return t.prototype.K=function(){X(this.P,this),this.$=!0,this.o()},t.prototype.o=function(){var t=this;if(this.$){var n=function(n){return function(){n===d||D(t.J,n)||(t.J=n,n instanceof F?t.U(n.error):t.W(n))}},i=this.P[h]();i instanceof I?this.X(n(i.value)):n(i)()}},t.prototype.W=function(t){var n=this;this.H++;try{if(this.H>100)throw Error("Too deeply nested synchronous cyclical reactions disallowed. Use setImmediate.");this.L(t,(function(){return n.X()}))}catch(t){this.U(M(t,this))}finally{this.H--}},t.prototype.X=function(t){this.$&&(this.$=!1,Y(this.P,this),t&&t(),this.ended&&this.ended())},t.prototype[a]=function(t){t.indexOf(this)<0&&t.push(this)},t.create=function(n,i,r,e){var o=new t(r?n.take(r):n,(function(t){if(!r||!r.onError)throw u(),t;r.onError(t,u)}),i,e);function u(){o.X()}return o.K(),u},t}(),qt=Object.freeze({__proto__:null,symbols:p,Atom:et,BaseDerivable:tt,BaseDerivation:ct,Derivation:ht,Lens:at,resolveFallback:dt,safeUnwrap:st,Reactor:Vt,isRecordingObservations:H,addObserver:X,allDependenciesAreFinal:J,independentTracking:K,markFinal:Q,maybeDisconnectInNextTick:Z,recordObservation:W,removeObserver:Y,startRecordingObservations:L,stopRecordingObservations:$,processChangedState:O,augmentStack:M}),zt={clone:A,equals:D,isPlainObject:function(t){if("object"!=typeof t||null==t)return!1;var n=Object.getPrototypeOf(t);return n===Object.prototype||null===n||t.constructor===Object},resolveFallback:dt};(Mt="undefined"!=typeof window?window:global)[b]?(Mt[b]++,console.warn(Mt[b]+" instances of Sherlock detected. This could cause unexpected results.")):Mt[b]=1,exports.ErrorWrapper=F,exports.FinalWrapper=I,exports.PullDataSource=ot,exports._internal=qt,exports.atom=Ot,exports.atomic=_,exports.atomically=S,exports.config=T,exports.constant=gt,exports.derive=jt,exports.inTransaction=w,exports.isDerivable=yt,exports.isDerivableAtom=function t(n){return n instanceof et&&n.settable||n instanceof lt&&t(n.q)},exports.isSettableDerivable=function(t){return yt(t)&&t.settable},exports.lens=xt,exports.safeUnwrap=st,exports.transact=x,exports.transaction=function t(n){return n?function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];var r=this;return x((function(){return n.apply(r,t)}))}:function(n,i,r){r.value=r.value&&t(r.value)}},exports.unresolved=d,exports.unwrap=ut,exports.utils=zt;
Object.defineProperty(exports,"__esModule",{value:!0});var t,n=require("tslib"),i=Symbol("autoCacheMode"),r=Symbol("connect"),e=Symbol("dependencies"),o=Symbol("dependencyVersions"),u=Symbol("derivableAtom"),s=Symbol("disconnect"),c=Symbol("emptyCache"),f=Symbol("finalize"),h=Symbol("internalGetState"),a=Symbol("mark"),v=Symbol("observers"),l=Symbol("rollback"),b=Symbol("sherlockInstances"),d=Symbol("unresolved"),p=Object.freeze({__proto__:null,autoCacheMode:i,connect:r,dependencies:e,dependencyVersions:o,derivableAtom:u,disconnect:s,emptyCache:c,finalize:f,internalGetState:h,mark:a,observers:v,rollback:l,sherlockInstances:b,unresolved:d});function w(){return!!t}function y(n){t?t.t[n.id]=n:n[f]()}function m(n,i,r){t&&k(t,n,i,r)}function O(n){if(t)g(n,t.i);else{var i=[];g(n,i),j(i)}}function g(t,n){for(var i=0,r=t[v];i<r.length;i++)r[i][a](n)}function j(t){for(var n=0,i=t;n<i.length;n++)i[n].o()}function x(n){var i;t={u:[],h:{},v:{},t:{},i:[],l:t};try{i=n()}catch(n){throw function(){var n=t;if(!n)throw Error();t=n.l,n.u.forEach((function(t){return t[l](n.h[t.id],n.v[t.id])}))}(),n}return function(){var n,i=t;if(!i)throw Error();(t=i.l)?(i.u.forEach((function(n){return k(t,n,i.h[n.id],i.v[n.id])})),(n=t.i).push.apply(n,i.i),Object.assign(t.t,i.t)):(Object.values(i.t).forEach((function(t){return t[f]()})),j(i.i))}(),i}function S(t){return w()?t():x(t)}function _(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return S((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&_(i.value)}}function k(t,n,i,r){var e=n.id;e in t.h||(t.u.push(n),t.h[e]=i,t.v[e]=r)}function E(t){if(!t||"object"!=typeof t)return!1;var n=t;return"string"==typeof n.message&&"string"==typeof n.name&&(void 0===n.stack||"string"==typeof n.stack)}var R=Object.getOwnPropertyDescriptors||function(t){for(var n={},i=0,r=A(t);i<r.length;i++){var e=r[i];n[e]=Object.getOwnPropertyDescriptor(t,e)}return n},A="undefined"!=typeof Reflect?Reflect.ownKeys:function(t){return n.__spreadArray(n.__spreadArray([],Object.getOwnPropertyNames(t),!0),Object.getOwnPropertySymbols(t),!0)};function T(t){return Array.isArray(t)?function(t){try{return Object.defineProperties(new t.constructor,R(t))}catch(t){throw Object.assign(Error("could not clone Array: "+(E(t)&&t.message)),{jse_cause:t})}}(t):Object.create(Object.getPrototypeOf(t),R(t))}var C={equals:function(t,n){return(i=t)&&"function"==typeof i.equals&&!!t.equals(n);var i},plucker:{get:function(t,n){return D(t)?t.get(n):t[n]},set:function(t,n,i){if(D(n)){if("function"==typeof n.set)return n.set(i,t);throw Error("object is readonly")}var r=T(n);return r[i]=t,r}},debugMode:!1};function D(t){return t&&"function"==typeof t.get}function F(t,n){return Object.is(t,n)||C.equals(t,n)}var I=function(){function t(t){this.error=t}return t.prototype.equals=function(n){return this===n||n instanceof t&&F(this.error,n.error)},t}(),M=function(){function t(t){this.value=t}return t.wrap=function(n){return n instanceof t?n:new t(n)},t.unwrap=function(n){return n instanceof t?n.value:n},t.map=function(n,i){return n instanceof t?t.wrap(i(n.value)):i(n)},t.prototype.equals=function(n){return this===n||n instanceof t&&F(this.value,n.value)},t}();function V(t,n){var i=n.creationStack;return i?Object.defineProperty(T(t),"stack",{value:t.stack+"\n"+i}):t}function q(t,n){if(t instanceof M){var i=q(t.value,n);if(i!==t.value)return M.wrap(i)}return n.creationStack&&t instanceof I?new I(V(t.error,n)):t}function z(t){if(C.debugMode){var n=Error().stack;return t.constructor.name+" created:\n"+(n&&n.substr(n.indexOf("\n")+1))}}var B,G,N,P,U=0;function L(){return U++}function $(t){for(var n=B;n;){if(n.p===t)throw V(Error("cyclic dependency between derivables detected"),t);n=n.m}B={p:t,O:0,m:B,t:{}}}function H(){var t=B;if(!t)throw Error("No active recording!");B=t.m;for(var n=t.O,i=t.p,r=t.t,u=i[e],s=i[o],c=n,f=u.length;c<f;c++)Z(u[c],i);u.length=n;for(var h=0,a=u;h<a.length;h++){var v=a[h];s[v.id]=v.version}Object.values(r).forEach(y)}function J(){return!!B}function K(){if(!B)return!1;for(var t=B.O,n=B.t,i=B.p[e],r=0;r<t;r++)if(!(i[r].id in n))return!1;return!0}function Q(t){var n=B;B=void 0;try{return t()}finally{B=n}}function W(t){B?B.t[t.id]=t:y(t)}function X(t,n){if(B&&!t.finalized){n&&(B.t[t.id]=t);var i=B.p,r=i[e];if(r[B.O]===t)B.O++;else{var o=r.indexOf(t);o<0?(Y(t,i),B.O===r.length?r.push(t):(r.push(r[B.O]),r[B.O]=t),B.O++):o>B.O&&(r[o]=r[B.O],r[B.O]=t,B.O++)}}}function Y(t,n){var i=t[v];i.push(n),1!==i.length||t.connected||t[r]()}function Z(t,n){var r=t[v],e=r.indexOf(n);if(e<0)throw Error("Inconsistent state!");r.splice(e,1),0===r.length&&t.connected&&(t[i]?tt(t):t[s]())}function tt(t){G?G.push(t):(G=[t],setTimeout((function(){var t=G;G=void 0,t.forEach((function(t){return t.connected&&0===t[v].length&&t[s]()}))}),0))}var nt=function(){function t(){this.id=L(),this.creationStack=z(this),this[N]=[],this[P]=!1,this.connected=!1,this.g=void 0,this.finalized=!1}return t.prototype.autoCache=function(){return this[i]=!0,this},t.prototype.getMaybeFinalState=function(){return this.connected||(this[i]?(this[r](),tt(this)):J()&&this[r]()),this[h]()},t.prototype.getState=function(){return M.unwrap(this.getMaybeFinalState())},t.prototype[(N=v,P=i,r)]=function(){this.finalized||it(this,!0)},t.prototype[s]=function(){it(this,!1)},t.prototype[f]=function(){this.finalized=!0,this.connected&&this[s]()},t}();function it(t,n){t.connected=n,t.g&&Q((function(){return t.g.set(n)}))}var rt,et,ot=function(t){function i(n){var i=t.call(this)||this;return i.version=0,i.j=q(n,i),i.S()&&i[f](),i}return n.__extends(i,t),Object.defineProperty(i.prototype,"settable",{get:function(){return!this.S()},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this.j instanceof M},i.prototype[h]=function(){return X(this,this.S()),this.j},i.prototype.set=function(t){var n=this.j;if(!F(t,n)){if(this.S())throw V(Error("cannot set a final derivable"),this);this.j=q(t,this),m(this,n,this.version++),O(this),this.S()&&W(this)}},i.prototype[l]=function(t,n){this.j=t,this.version=n,g(this,[])},i}(nt),ut=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n._=c,n.version=0,n}return n.__extends(i,t),i.prototype.S=function(){return this._ instanceof M},i.prototype[h]=function(){return this.connected?(X(this,this.S()),this._):this.S()?this._:this.k()},i.prototype.set=function(t){if(!this.acceptNewValue)throw V(Error("DataSource is not settable"),this);this.acceptNewValue(t)},i.prototype.checkForChanges=function(){var t=this;if(this.connected){var n=Q((function(){return t.k()})),i=this._;F(n,i)||(this._=n,m(this,i,this.version++),O(this))}},i.prototype.k=function(){try{return this.calculateCurrentValue()}catch(t){return new I(V(t,this))}},i.prototype[l]=function(t,n){this.version++,g(this,[])},i.prototype[r]=function(){t.prototype[r].call(this),this.connected&&this.checkForChanges()},i.prototype[s]=function(){t.prototype[s].call(this),this.finalized||(this._=c)},Object.defineProperty(i.prototype,"settable",{get:function(){return!!this.acceptNewValue},enumerable:!1,configurable:!0}),i}(nt);function st(t){return t instanceof nt?t.get():t}function ct(t){return t instanceof nt?t.value:t}var ft=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n.R=!1,n._=c,n.A=0,n}return n.__extends(i,t),Object.defineProperty(i.prototype,"version",{get:function(){return this.T(),this.A},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this._ instanceof M},i.prototype[h]=function(){if(this.connected)return this.T(),X(this,this.S()),this._;if(this.S())return this._;var t=this.C();return t instanceof M&&(this._=t,m(this,void 0,this.A++),W(this)),t},i.prototype.T=function(){this.connected&&!this.R&&(this._!==c&&(this.R=this.S()||this.D()),this.R||this.F())},i.prototype.F=function(){var t=this.C();F(t,this._)||(this._=t,m(this,void 0,this.A++),this.S()&&W(this)),this.R=!0},i.prototype[a]=function(t){this.R&&(this.R=!1,g(this,t))},i.prototype[l]=function(t,n){this._=c,this.A=n,this[a]([])},i.prototype[s]=function(){t.prototype[s].call(this),this.R=!1,this.finalized||(this._=c)},i}(nt),ht=0,at=function(t){function i(n,i){var r=t.call(this)||this;return r.I=n,r.M=i,r[rt]=[],r[et]={},r}return n.__extends(i,t),i.prototype.F=function(){$(this);try{t.prototype.F.call(this)}finally{H()}},i.prototype.C=function(){++ht;try{var t=this.M?this.I.apply(this,this.M.map(st)):this.I();return K()?M.wrap(t):t}catch(t){return t===d?d:new I(V(t,this))}finally{--ht}},i.prototype.D=function(){var t=this;return this[e].every((function(n){return t[o][n.id]===n.version}))},i.prototype[(rt=e,et=o,s)]=function(){for(var n=0,i=this[e];n<i.length;n++)Z(i[n],this);this[e].length=0,t.prototype[s].call(this)},i.prototype[f]=function(){t.prototype[f].call(this),this.I=void 0,this.M=void 0},i}(ft),vt=function(t){function i(n,i){var r=n.get,e=n.set,o=t.call(this,r,i)||this;return o.V=e,o}return n.__extends(i,t),i.prototype.set=function(t){if(this.finalized)throw V(Error("cannot set a final derivable"),this);this.M?this.V.apply(this,n.__spreadArray([t],this.M.map(ct),!1)):this.V(t)},n.__decorate([_()],i.prototype,"set",null),i}(at),lt=function(t){function i(n,i){var r=t.call(this)||this;return r.q=n,r.B=i,r.G=0,r}return n.__extends(i,t),i.prototype.F=function(){this.G=this.q.version,t.prototype.F.call(this)},i.prototype.C=function(){var t=this;try{return Q((function(){var n=t.q.getMaybeFinalState();return M.map(n,(function(n){return t.B(n)}))}))}catch(t){return new I(V(t,this))}},i.prototype.D=function(){return this.G===this.q.version},i.prototype[r]=function(){t.prototype[r].call(this),this.connected&&Y(this.q,this)},i.prototype[s]=function(){Z(this.q,this),t.prototype[s].call(this)},i.prototype[f]=function(){t.prototype[f].call(this),this.q=void 0,this.B=void 0},i}(ft),bt=function(t){function i(n,i,r){var e=t.call(this,n,i)||this;return e.N=r,e}return n.__extends(i,t),i.prototype.set=function(t){var n=this;if(this.finalized)throw V(Error("cannot set a final derivable"),this);this.q.set(M.map(t,(function(t){return n.N(t)})))},Object.defineProperty(i.prototype,"settable",{get:function(){return this.q.settable},enumerable:!1,configurable:!0}),i.prototype[f]=function(){t.prototype[f].call(this),this.N=void 0},i}(lt);function dt(t){return t.settable}function pt(t){return"function"==typeof t?t():st(t)}function wt(){var t=this.getState();return t===d||t instanceof I?void 0:t}function yt(t){return this.set(t)}function mt(t){return t instanceof nt}var Ot=M.wrap(d);function gt(t){return new ot(t)}function jt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new at(t,n.length?n:void 0)}function xt(t){return gt.final(t)}function St(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new vt(t,n.length?n:void 0)}function _t(t){var n=this,i=C.plucker,r=i.get,e=i.set,o=this;return mt(t)?St({get:function(){return r.call(this,o.get(),t.get())},set:function(n){o.set(e.call(this,n,o.value,t.get()))}}):o.map((function(i){return r.call(n,i,t)}),(function(i){return e.call(n,i,o.value,t)}))}function kt(){this.set(d)}function Et(t){this.set(new I(t))}function Rt(t){this.set(M.wrap(t))}function At(t){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];this.set(t.apply(void 0,n.__spreadArray([this.value],i.map(ct),!1)))}!function(t){function n(t){return new ot(M.wrap(t))}t.unresolved=function(){return new ot(d)},t.error=function(t){return new ot(new I(t))},t.final=n,function(t){t.unresolved=function(){return new ot(Ot)},t.error=function(t){return new ot(M.wrap(new I(t)))}}(n=t.final||(t.final={}))}(gt||(gt={})),function(t){t.unresolved=function(){return gt.final.unresolved()},t.error=function(t){return gt.final.error(t)}}(xt||(xt={}));var Tt=new ot(M.wrap(!0)),Ct=new ot(M.wrap(!1)),Dt=Symbol("skipped"),Ft=M.wrap(Dt);function It(t,n,i,r){if(void 0!==t){var e=t?Tt:Ct;if(!function(t,n){return t===n||t instanceof ot&&t.j instanceof M&&t.j.value===n}(t,i)){if("function"==typeof t){var o=t;t=new at((function(){return o(n)})).derive(st)}return mt(t)?void 0!==r?t.mapState((function(t){return t===r?M.wrap(t):t})):t:e}}}function Mt(t){var n=M.unwrap(t);return n!==d&&!(n instanceof I)}Object.defineProperties(nt.prototype,{get:{value:function(){var t=this.getState();if(t instanceof I)throw t.error;if(t!==d)return t;if(ht>0)throw d;throw V(Error("Could not get value, derivable is unresolved"),this)}},getOr:{value:function(t){var n=this.getState();if(n instanceof I)throw n.error;return n===d?pt(t):n}},value:{get:wt},resolved:{get:function(){return this.getState()!==d}},settable:{value:!1},final:{get:function(){return this.getMaybeFinalState()instanceof M}},errored:{get:function(){return this.getState()instanceof I}},error:{get:function(){var t=this.getState();return t instanceof I?t.error:void 0}},connected$:{get:function(){return this.g||(this.g=new ot(this.connected))}},derive:{value:function(t){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];return new at(t,n.__spreadArray([this],i,!0))}},map:{value:function(t,n){var i=function(n){return n===d||n instanceof I?n:t.call(this,n)};return n&&dt(this)?new bt(this,i,(function(t){return t===d||t instanceof I?t:n.call(this,t,this.q.value)})):new lt(this,i)}},mapState:{value:function(t,n){return n&&dt(this)?new bt(this,t,(function(t){return n.call(this,t,this.q.getState())})):new lt(this,t)}},flatMap:{value:function(t){return this.map(t).derive((function(t){return t.getState()}))}},pluck:{value:function(t){var n=this,i=C.plucker.get;return mt(t)?this.derive(i,t):this.map((function(r){return i.call(n,r,t)}))}},fallbackTo:{value:function(t){var n=this;return mt(t)?jt((function(){return n.getOr(t)})):this.mapState((function(n){return n===d?pt(t):n}))}},take:{value:function(t){var n=this,i=t.from,r=t.when,e=t.until,o=t.once,u=t.stopOnError,s=t.skipFirst,c=It(i,this,!0,!0),f=It(r,this,!0),h=It(e,this,!1,!0),a=s?new ot(d):void 0;if(!(c||f||h||o||u||a))return this;var v=(h||f)&&new ot(d);function l(t){return v&&v.set(t),t}return new at((function(){if(c&&!c.get())return d;if(h&&h.get())return l(M.wrap(v.j));if(f&&!f.getOr(!1))return v.j;var t=n.getMaybeFinalState();if(a&&!Ft.equals(a.j)){if(!Mt(t))return l(t);if(a.j===d||F(t,a.j))return a.set(t),l(d);a.set(Ft)}return l(o&&Mt(t)||u&&t instanceof I?M.wrap(t):t)}))}},and:{value:function(t){return mt(t)?this.derive((function(n){return n&&t.get()})):this.map((function(n){return n&&t}))}},or:{value:function(t){return mt(t)?this.derive((function(n){return n||t.get()})):this.map((function(n){return n||t}))}},not:{value:function(){return this.map((function(t){return!t}))}},is:{value:function(t){return mt(t)?this.derive(F,t):this.map((function(n){return F(n,t)}))}}}),[ot,ut,bt,vt].forEach((function(t){return Object.defineProperties(t.prototype,{value:{get:wt,set:yt},swap:{value:At},pluck:{value:_t}})})),[ot,bt].forEach((function(t){return Object.defineProperties(t.prototype,{unset:{value:kt},setError:{value:Et},setFinal:{value:Rt}})})),Object.defineProperties(vt.prototype,{settable:{value:!0}}),nt.prototype.react=function(t,n){var i=this;return Q((function(){return qt.create(i,t,n)}))},nt.prototype.toPromise=function(t){var i=this;return new Promise((function(r,e){return i.react(r,n.__assign(n.__assign({},t),{once:!0,onError:function(t,n){n(),e(t)}}))}))};var Vt,qt=function(){function t(t,n,i,r){this.P=t,this.U=n,this.L=i,this.ended=r,this.$=!1,this.id=L(),this.H=0,this.creationStack=z(this),this.J=c}return t.prototype.K=function(){Y(this.P,this),this.$=!0,this.o()},t.prototype.o=function(){var t=this;if(this.$){var n=function(n){return function(){n===d||F(t.J,n)||(t.J=n,n instanceof I?t.U(n.error):t.W(n))}},i=this.P[h]();i instanceof M?this.X(n(i.value)):n(i)()}},t.prototype.W=function(t){var n=this;this.H++;try{if(this.H>100)throw Error("Too deeply nested synchronous cyclical reactions disallowed. Use setImmediate.");this.L(t,(function(){return n.X()}))}catch(t){this.U(V(t,this))}finally{this.H--}},t.prototype.X=function(t){this.$&&(this.$=!1,Z(this.P,this),t&&t(),this.ended&&this.ended())},t.prototype[a]=function(t){t.indexOf(this)<0&&t.push(this)},t.create=function(n,i,r,e){var o=new t(r?n.take(r):n,(function(t){if(!r||!r.onError)throw u(),t;r.onError(t,u)}),i,e);function u(){o.X()}return o.K(),u},t}(),zt=Object.freeze({__proto__:null,symbols:p,Atom:ot,BaseDerivable:nt,BaseDerivation:ft,Derivation:at,Lens:vt,resolveFallback:pt,safeUnwrap:ct,Reactor:qt,isRecordingObservations:J,addObserver:Y,allDependenciesAreFinal:K,independentTracking:Q,markFinal:W,maybeDisconnectInNextTick:tt,recordObservation:X,removeObserver:Z,startRecordingObservations:$,stopRecordingObservations:H,processChangedState:O,augmentStack:V,isError:E}),Bt={clone:T,equals:F,isPlainObject:function(t){if("object"!=typeof t||null==t)return!1;var n=Object.getPrototypeOf(t);return n===Object.prototype||null===n||t.constructor===Object},resolveFallback:pt};(Vt="undefined"!=typeof window?window:global)[b]?(Vt[b]++,console.warn(Vt[b]+" instances of Sherlock detected. This could cause unexpected results.")):Vt[b]=1,exports.ErrorWrapper=I,exports.FinalWrapper=M,exports.PullDataSource=ut,exports._internal=zt,exports.atom=gt,exports.atomic=_,exports.atomically=S,exports.config=C,exports.constant=xt,exports.derive=jt,exports.inTransaction=w,exports.isDerivable=mt,exports.isDerivableAtom=function t(n){return n instanceof ot&&n.settable||n instanceof bt&&t(n.q)},exports.isSettableDerivable=function(t){return mt(t)&&t.settable},exports.lens=St,exports.safeUnwrap=ct,exports.transact=x,exports.transaction=function t(n){return n?function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];var r=this;return x((function(){return n.apply(r,t)}))}:function(n,i,r){r.value=r.value&&t(r.value)}},exports.unresolved=d,exports.unwrap=st,exports.utils=Bt;
//# sourceMappingURL=sherlock.cjs.min.js.map

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

import{__spreadArrays as t,__extends as n,__decorate as i,__assign as r}from"tslib";var e,u=Symbol("autoCacheMode"),o=Symbol("connect"),s=Symbol("dependencies"),c=Symbol("dependencyVersions"),f=Symbol("derivableAtom"),h=Symbol("disconnect"),a=Symbol("emptyCache"),v=Symbol("finalize"),l=Symbol("internalGetState"),b=Symbol("mark"),d=Symbol("observers"),w=Symbol("rollback"),y=Symbol("sherlockInstances"),m=Symbol("unresolved"),p=Object.freeze({__proto__:null,autoCacheMode:u,connect:o,dependencies:s,dependencyVersions:c,derivableAtom:f,disconnect:h,emptyCache:a,finalize:v,internalGetState:l,mark:b,observers:d,rollback:w,sherlockInstances:y,unresolved:m});function O(){return!!e}function g(t){e?e.t[t.id]=t:t[v]()}function j(t,n,i){e&&C(e,t,n,i)}function S(t){if(e)k(t,e.i);else{var n=[];k(t,n),_(n)}}function k(t,n){for(var i=0,r=t[d];i<r.length;i++)r[i][b](n)}function _(t){for(var n=0,i=t;n<i.length;n++)i[n].u()}function E(t){var n;e={o:[],h:{},v:{},t:{},i:[],l:e};try{n=t()}catch(t){throw function(){var t=e;if(!t)throw Error();e=t.l,t.o.forEach((function(n){return n[w](t.h[n.id],t.v[n.id])}))}(),t}return function(){var t,n=e;if(!n)throw Error();(e=n.l)?(n.o.forEach((function(t){return C(e,t,n.h[t.id],n.v[t.id])})),(t=e.i).push.apply(t,n.i),Object.assign(e.t,n.t)):(Object.values(n.t).forEach((function(t){return t[v]()})),_(n.i))}(),n}function R(t){return O()?t():E(t)}function A(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return R((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&A(i.value)}}function T(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return E((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&T(i.value)}}function C(t,n,i,r){var e=n.id;e in t.h||(t.o.push(n),t.h[e]=i,t.v[e]=r)}var D=Object.getOwnPropertyDescriptors||function(t){for(var n={},i=0,r=F(t);i<r.length;i++){var e=r[i];n[e]=Object.getOwnPropertyDescriptor(t,e)}return n},F="undefined"!=typeof Reflect?Reflect.ownKeys:function(n){return t(Object.getOwnPropertyNames(n),Object.getOwnPropertySymbols(n))};function I(t){return Array.isArray(t)?function(t){try{return Object.defineProperties(new t.constructor,D(t))}catch(t){throw Object.assign(Error("could not clone Array: "+(t&&t.message)),{jse_cause:t})}}(t):Object.create(Object.getPrototypeOf(t),D(t))}var M={equals:function(t,n){return(i=t)&&"function"==typeof i.equals&&!!t.equals(n);var i},plucker:{get:function(t,n){return V(t)?t.get(n):t[n]},set:function(t,n,i){if(V(n)){if("function"==typeof n.set)return n.set(i,t);throw Error("object is readonly")}var r=I(n);return r[i]=t,r}},debugMode:!1};function V(t){return t&&"function"==typeof t.get}function x(t,n){return Object.is(t,n)||M.equals(t,n)}var q=function(){function t(t){this.error=t}return t.prototype.equals=function(n){return this===n||n instanceof t&&x(this.error,n.error)},t}(),z=function(){function t(t){this.value=t}return t.wrap=function(n){return n instanceof t?n:new t(n)},t.unwrap=function(n){return n instanceof t?n.value:n},t.map=function(n,i){return n instanceof t?t.wrap(i(n.value)):i(n)},t.prototype.equals=function(n){return this===n||n instanceof t&&x(this.value,n.value)},t}();function B(t,n){var i=n.creationStack;return i?Object.defineProperty(I(t),"stack",{value:t.stack+"\n"+i}):t}function G(t,n){if(t instanceof z){var i=G(t.value,n);if(i!==t.value)return z.wrap(i)}return n.creationStack&&t instanceof q?new q(B(t.error,n)):t}function N(t){if(M.debugMode){var n=Error().stack;return t.constructor.name+" created:\n"+(n&&n.substr(n.indexOf("\n")+1))}}var P,U,L,$,H=0;function J(){return H++}function K(t){for(var n=P;n;){if(n.m===t)throw B(Error("cyclic dependency between derivables detected"),t);n=n.p}P={m:t,O:0,p:P,t:{}}}function Q(){var t=P;if(!t)throw Error("No active recording!");P=t.p;for(var n=t.O,i=t.m,r=t.t,e=i[s],u=i[c],o=n,f=e.length;o<f;o++)it(e[o],i);e.length=n;for(var h=0,a=e;h<a.length;h++){var v=a[h];u[v.id]=v.version}Object.values(r).forEach(g)}function W(){return!!P}function X(){if(!P)return!1;for(var t=P.O,n=P.t,i=P.m[s],r=0;r<t;r++)if(!(i[r].id in n))return!1;return!0}function Y(t){var n=P;P=void 0;try{return t()}finally{P=n}}function Z(t){P?P.t[t.id]=t:g(t)}function tt(t,n){if(P&&!t.finalized){n&&(P.t[t.id]=t);var i=P.m,r=i[s];if(r[P.O]===t)P.O++;else{var e=r.indexOf(t);e<0?(nt(t,i),P.O===r.length?r.push(t):(r.push(r[P.O]),r[P.O]=t),P.O++):e>P.O&&(r[e]=r[P.O],r[P.O]=t,P.O++)}}}function nt(t,n){var i=t[d];i.push(n),1!==i.length||t.connected||t[o]()}function it(t,n){var i=t[d],r=i.indexOf(n);if(r<0)throw Error("Inconsistent state!");i.splice(r,1),0===i.length&&t.connected&&(t[u]?rt(t):t[h]())}function rt(t){U?U.push(t):(U=[t],setTimeout((function(){var t=U;U=void 0,t.forEach((function(t){return t.connected&&0===t[d].length&&t[h]()}))}),0))}var et=function(){function t(){this.id=J(),this.creationStack=N(this),this[L]=[],this[$]=!1,this.connected=!1,this.g=void 0,this.finalized=!1}return t.prototype.autoCache=function(){return this[u]=!0,this},t.prototype.getMaybeFinalState=function(){return this.connected||(this[u]?(this[o](),rt(this)):W()&&this[o]()),this[l]()},t.prototype.getState=function(){return z.unwrap(this.getMaybeFinalState())},t.prototype[(L=d,$=u,o)]=function(){this.finalized||ut(this,!0)},t.prototype[h]=function(){ut(this,!1)},t.prototype[v]=function(){this.finalized=!0,this.connected&&this[h]()},t}();function ut(t,n){t.connected=n,t.g&&Y((function(){return t.g.set(n)}))}var ot,st,ct=function(t){function i(n){var i=t.call(this)||this;return i.version=0,i.j=G(n,i),i.S()&&i[v](),i}return n(i,t),Object.defineProperty(i.prototype,"settable",{get:function(){return!this.S()},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this.j instanceof z},i.prototype[l]=function(){return tt(this,this.S()),this.j},i.prototype.set=function(t){var n=this.j;if(!x(t,n)){if(this.S())throw B(Error("cannot set a final derivable"),this);this.j=G(t,this),j(this,n,this.version++),S(this),this.S()&&Z(this)}},i.prototype[w]=function(t,n){this.j=t,this.version=n,k(this,[])},i}(et),ft=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n.k=a,n.version=0,n}return n(i,t),i.prototype.S=function(){return this.k instanceof z},i.prototype[l]=function(){return this.connected?(tt(this,this.S()),this.k):this.S()?this.k:this._()},i.prototype.set=function(t){if(!this.acceptNewValue)throw B(Error("DataSource is not settable"),this);this.acceptNewValue(t)},i.prototype.checkForChanges=function(){var t=this;if(this.connected){var n=Y((function(){return t._()})),i=this.k;x(n,i)||(this.k=n,j(this,i,this.version++),S(this))}},i.prototype._=function(){try{return this.calculateCurrentValue()}catch(t){return new q(B(t,this))}},i.prototype[w]=function(t,n){this.version++,k(this,[])},i.prototype[o]=function(){t.prototype[o].call(this),this.connected&&this.checkForChanges()},i.prototype[h]=function(){t.prototype[h].call(this),this.finalized||(this.k=a)},Object.defineProperty(i.prototype,"settable",{get:function(){return!!this.acceptNewValue},enumerable:!1,configurable:!0}),i}(et);function ht(t){return t instanceof et?t.get():t}function at(t){return t instanceof et?t.value:t}var vt=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n.R=!1,n.k=a,n.A=0,n}return n(i,t),Object.defineProperty(i.prototype,"version",{get:function(){return this.T(),this.A},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this.k instanceof z},i.prototype[l]=function(){if(this.connected)return this.T(),tt(this,this.S()),this.k;if(this.S())return this.k;var t=this.C();return t instanceof z&&(this.k=t,j(this,void 0,this.A++),Z(this)),t},i.prototype.T=function(){this.connected&&!this.R&&(this.k!==a&&(this.R=this.S()||this.D()),this.R||this.F())},i.prototype.F=function(){var t=this.C();x(t,this.k)||(this.k=t,j(this,void 0,this.A++),this.S()&&Z(this)),this.R=!0},i.prototype[b]=function(t){this.R&&(this.R=!1,k(this,t))},i.prototype[w]=function(t,n){this.k=a,this.A=n,this[b]([])},i.prototype[h]=function(){t.prototype[h].call(this),this.R=!1,this.finalized||(this.k=a)},i}(et),lt=0,bt=function(t){function i(n,i){var r=t.call(this)||this;return r.I=n,r.M=i,r[ot]=[],r[st]={},r}return n(i,t),i.prototype.F=function(){K(this);try{t.prototype.F.call(this)}finally{Q()}},i.prototype.C=function(){++lt;try{var t=this.M?this.I.apply(this,this.M.map(ht)):this.I();return X()?z.wrap(t):t}catch(t){return t===m?m:new q(B(t,this))}finally{--lt}},i.prototype.D=function(){var t=this;return this[s].every((function(n){return t[c][n.id]===n.version}))},i.prototype[(ot=s,st=c,h)]=function(){for(var n=0,i=this[s];n<i.length;n++)it(i[n],this);this[s].length=0,t.prototype[h].call(this)},i.prototype[v]=function(){t.prototype[v].call(this),this.I=void 0,this.M=void 0},i}(vt),dt=function(r){function e(t,n){var i=t.get,e=t.set,u=r.call(this,i,n)||this;return u.V=e,u}return n(e,r),e.prototype.set=function(n){if(this.finalized)throw B(Error("cannot set a final derivable"),this);this.M?this.V.apply(this,t([n],this.M.map(at))):this.V(n)},i([A()],e.prototype,"set",null),e}(bt),wt=function(t){function i(n,i){var r=t.call(this)||this;return r.q=n,r.B=i,r.G=0,r}return n(i,t),i.prototype.F=function(){this.G=this.q.version,t.prototype.F.call(this)},i.prototype.C=function(){var t=this;try{return Y((function(){var n=t.q.getMaybeFinalState();return z.map(n,(function(n){return t.B(n)}))}))}catch(t){return new q(B(t,this))}},i.prototype.D=function(){return this.G===this.q.version},i.prototype[o]=function(){t.prototype[o].call(this),this.connected&&nt(this.q,this)},i.prototype[h]=function(){it(this.q,this),t.prototype[h].call(this)},i.prototype[v]=function(){t.prototype[v].call(this),this.q=void 0,this.B=void 0},i}(vt),yt=function(t){function i(n,i,r){var e=t.call(this,n,i)||this;return e.N=r,e}return n(i,t),i.prototype.set=function(t){var n=this;if(this.finalized)throw B(Error("cannot set a final derivable"),this);this.q.set(z.map(t,(function(t){return n.N(t)})))},Object.defineProperty(i.prototype,"settable",{get:function(){return this.q.settable},enumerable:!1,configurable:!0}),i.prototype[v]=function(){t.prototype[v].call(this),this.N=void 0},i}(wt);function mt(t){return t.settable}function pt(t){return"function"==typeof t?t():ht(t)}function Ot(){var t=this.getState();return t===m||t instanceof q?void 0:t}function gt(t){return this.set(t)}function jt(t){return t instanceof et}function St(t){return jt(t)&&t.settable}function kt(t){return t instanceof ct&&t.settable||t instanceof yt&&kt(t.q)}var _t=z.wrap(m);function Et(t){return new ct(t)}function Rt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new bt(t,n.length?n:void 0)}function At(t){return Et.final(t)}function Tt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new dt(t,n.length?n:void 0)}function Ct(t){var n=this,i=M.plucker,r=i.get,e=i.set,u=this;return jt(t)?Tt({get:function(){return r.call(this,u.get(),t.get())},set:function(n){u.set(e.call(this,n,u.value,t.get()))}}):u.map((function(i){return r.call(n,i,t)}),(function(i){return e.call(n,i,u.value,t)}))}function Dt(){this.set(m)}function Ft(t){this.set(new q(t))}function It(t){this.set(z.wrap(t))}function Mt(n){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];this.set(n.apply(void 0,t([this.value],i.map(at))))}!function(t){function n(t){return new ct(z.wrap(t))}t.unresolved=function(){return new ct(m)},t.error=function(t){return new ct(new q(t))},t.final=n,function(t){t.unresolved=function(){return new ct(_t)},t.error=function(t){return new ct(z.wrap(new q(t)))}}(n=t.final||(t.final={}))}(Et||(Et={})),function(t){t.unresolved=function(){return Et.final.unresolved()},t.error=function(t){return Et.final.error(t)}}(At||(At={}));var Vt=new ct(z.wrap(!0)),xt=new ct(z.wrap(!1)),qt=Symbol("skipped"),zt=z.wrap(qt);function Bt(t,n,i,r){if(void 0!==t){var e=t?Vt:xt;if(!function(t,n){return t===n||t instanceof ct&&t.j instanceof z&&t.j.value===n}(t,i)){if("function"==typeof t){var u=t;t=new bt((function(){return u(n)})).derive(ht)}return jt(t)?void 0!==r?t.mapState((function(t){return t===r?z.wrap(t):t})):t:e}}}function Gt(t){var n=z.unwrap(t);return n!==m&&!(n instanceof q)}Object.defineProperties(et.prototype,{get:{value:function(){var t=this.getState();if(t instanceof q)throw t.error;if(t!==m)return t;if(lt>0)throw m;throw B(Error("Could not get value, derivable is unresolved"),this)}},getOr:{value:function(t){var n=this.getState();if(n instanceof q)throw n.error;return n===m?pt(t):n}},value:{get:Ot},resolved:{get:function(){return this.getState()!==m}},settable:{value:!1},final:{get:function(){return this.getMaybeFinalState()instanceof z}},errored:{get:function(){return this.getState()instanceof q}},error:{get:function(){var t=this.getState();return t instanceof q?t.error:void 0}},connected$:{get:function(){return this.g||(this.g=new ct(this.connected))}},derive:{value:function(n){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];return new bt(n,t([this],i))}},map:{value:function(t,n){var i=function(n){return n===m||n instanceof q?n:t.call(this,n)};return n&&mt(this)?new yt(this,i,(function(t){return t===m||t instanceof q?t:n.call(this,t,this.q.value)})):new wt(this,i)}},mapState:{value:function(t,n){return n&&mt(this)?new yt(this,t,(function(t){return n.call(this,t,this.q.getState())})):new wt(this,t)}},flatMap:{value:function(t){return this.map(t).derive((function(t){return t.getState()}))}},pluck:{value:function(t){var n=this,i=M.plucker.get;return jt(t)?this.derive(i,t):this.map((function(r){return i.call(n,r,t)}))}},fallbackTo:{value:function(t){var n=this;return jt(t)?Rt((function(){return n.getOr(t)})):this.mapState((function(n){return n===m?pt(t):n}))}},take:{value:function(t){var n=this,i=t.from,r=t.when,e=t.until,u=t.once,o=t.stopOnError,s=t.skipFirst,c=Bt(i,this,!0,!0),f=Bt(r,this,!0),h=Bt(e,this,!1,!0),a=s?new ct(m):void 0;if(!(c||f||h||u||o||a))return this;var v=(h||f)&&new ct(m);function l(t){return v&&v.set(t),t}return new bt((function(){if(c&&!c.get())return m;if(h&&h.get())return l(z.wrap(v.j));if(f&&!f.getOr(!1))return v.j;var t=n.getMaybeFinalState();if(a&&!zt.equals(a.j)){if(!Gt(t))return l(t);if(a.j===m||x(t,a.j))return a.set(t),l(m);a.set(zt)}return l(u&&Gt(t)||o&&t instanceof q?z.wrap(t):t)}))}},and:{value:function(t){return jt(t)?this.derive((function(n){return n&&t.get()})):this.map((function(n){return n&&t}))}},or:{value:function(t){return jt(t)?this.derive((function(n){return n||t.get()})):this.map((function(n){return n||t}))}},not:{value:function(){return this.map((function(t){return!t}))}},is:{value:function(t){return jt(t)?this.derive(x,t):this.map((function(n){return x(n,t)}))}}}),[ct,ft,yt,dt].forEach((function(t){return Object.defineProperties(t.prototype,{value:{get:Ot,set:gt},swap:{value:Mt},pluck:{value:Ct}})})),[ct,yt].forEach((function(t){return Object.defineProperties(t.prototype,{unset:{value:Dt},setError:{value:Ft},setFinal:{value:It}})})),Object.defineProperties(dt.prototype,{settable:{value:!0}}),et.prototype.react=function(t,n){var i=this;return Y((function(){return Pt.create(i,t,n)}))},et.prototype.toPromise=function(t){var n=this;return new Promise((function(i,e){return n.react(i,r(r({},t),{once:!0,onError:function(t,n){n(),e(t)}}))}))};var Nt,Pt=function(){function t(t,n,i,r){this.P=t,this.U=n,this.L=i,this.ended=r,this.$=!1,this.id=J(),this.H=0,this.creationStack=N(this),this.J=a}return t.prototype.K=function(){nt(this.P,this),this.$=!0,this.u()},t.prototype.u=function(){var t=this;if(this.$){var n=function(n){return function(){n===m||x(t.J,n)||(t.J=n,n instanceof q?t.U(n.error):t.W(n))}},i=this.P[l]();i instanceof z?this.X(n(i.value)):n(i)()}},t.prototype.W=function(t){var n=this;this.H++;try{if(this.H>100)throw Error("Too deeply nested synchronous cyclical reactions disallowed. Use setImmediate.");this.L(t,(function(){return n.X()}))}catch(t){this.U(B(t,this))}finally{this.H--}},t.prototype.X=function(t){this.$&&(this.$=!1,it(this.P,this),t&&t(),this.ended&&this.ended())},t.prototype[b]=function(t){t.indexOf(this)<0&&t.push(this)},t.create=function(n,i,r,e){var u=new t(r?n.take(r):n,(function(t){if(!r||!r.onError)throw o(),t;r.onError(t,o)}),i,e);function o(){u.X()}return u.K(),o},t}(),Ut=Object.freeze({__proto__:null,symbols:p,Atom:ct,BaseDerivable:et,BaseDerivation:vt,Derivation:bt,Lens:dt,resolveFallback:pt,safeUnwrap:at,Reactor:Pt,isRecordingObservations:W,addObserver:nt,allDependenciesAreFinal:X,independentTracking:Y,markFinal:Z,maybeDisconnectInNextTick:rt,recordObservation:tt,removeObserver:it,startRecordingObservations:K,stopRecordingObservations:Q,processChangedState:S,augmentStack:B}),Lt={clone:I,equals:x,isPlainObject:function(t){if("object"!=typeof t||null==t)return!1;var n=Object.getPrototypeOf(t);return n===Object.prototype||null===n||t.constructor===Object},resolveFallback:pt};(Nt="undefined"!=typeof window?window:global)[y]?(Nt[y]++,console.warn(Nt[y]+" instances of Sherlock detected. This could cause unexpected results.")):Nt[y]=1;export{q as ErrorWrapper,z as FinalWrapper,ft as PullDataSource,Ut as _internal,Et as atom,A as atomic,R as atomically,M as config,At as constant,Rt as derive,O as inTransaction,jt as isDerivable,kt as isDerivableAtom,St as isSettableDerivable,Tt as lens,at as safeUnwrap,E as transact,T as transaction,m as unresolved,ht as unwrap,Lt as utils};
import{__spreadArray as t,__extends as n,__decorate as i,__assign as r}from"tslib";var e,u=Symbol("autoCacheMode"),o=Symbol("connect"),s=Symbol("dependencies"),c=Symbol("dependencyVersions"),f=Symbol("derivableAtom"),h=Symbol("disconnect"),a=Symbol("emptyCache"),v=Symbol("finalize"),l=Symbol("internalGetState"),b=Symbol("mark"),d=Symbol("observers"),w=Symbol("rollback"),y=Symbol("sherlockInstances"),m=Symbol("unresolved"),p=Object.freeze({__proto__:null,autoCacheMode:u,connect:o,dependencies:s,dependencyVersions:c,derivableAtom:f,disconnect:h,emptyCache:a,finalize:v,internalGetState:l,mark:b,observers:d,rollback:w,sherlockInstances:y,unresolved:m});function O(){return!!e}function g(t){e?e.t[t.id]=t:t[v]()}function j(t,n,i){e&&C(e,t,n,i)}function S(t){if(e)k(t,e.i);else{var n=[];k(t,n),_(n)}}function k(t,n){for(var i=0,r=t[d];i<r.length;i++)r[i][b](n)}function _(t){for(var n=0,i=t;n<i.length;n++)i[n].u()}function E(t){var n;e={o:[],h:{},v:{},t:{},i:[],l:e};try{n=t()}catch(t){throw function(){var t=e;if(!t)throw Error();e=t.l,t.o.forEach((function(n){return n[w](t.h[n.id],t.v[n.id])}))}(),t}return function(){var t,n=e;if(!n)throw Error();(e=n.l)?(n.o.forEach((function(t){return C(e,t,n.h[t.id],n.v[t.id])})),(t=e.i).push.apply(t,n.i),Object.assign(e.t,n.t)):(Object.values(n.t).forEach((function(t){return t[v]()})),_(n.i))}(),n}function R(t){return O()?t():E(t)}function A(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return R((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&A(i.value)}}function T(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return E((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&T(i.value)}}function C(t,n,i,r){var e=n.id;e in t.h||(t.o.push(n),t.h[e]=i,t.v[e]=r)}function D(t){if(!t||"object"!=typeof t)return!1;var n=t;return"string"==typeof n.message&&"string"==typeof n.name&&(void 0===n.stack||"string"==typeof n.stack)}var F=Object.getOwnPropertyDescriptors||function(t){for(var n={},i=0,r=I(t);i<r.length;i++){var e=r[i];n[e]=Object.getOwnPropertyDescriptor(t,e)}return n},I="undefined"!=typeof Reflect?Reflect.ownKeys:function(n){return t(t([],Object.getOwnPropertyNames(n),!0),Object.getOwnPropertySymbols(n),!0)};function M(t){return Array.isArray(t)?function(t){try{return Object.defineProperties(new t.constructor,F(t))}catch(t){throw Object.assign(Error("could not clone Array: "+(D(t)&&t.message)),{jse_cause:t})}}(t):Object.create(Object.getPrototypeOf(t),F(t))}var V={equals:function(t,n){return(i=t)&&"function"==typeof i.equals&&!!t.equals(n);var i},plucker:{get:function(t,n){return x(t)?t.get(n):t[n]},set:function(t,n,i){if(x(n)){if("function"==typeof n.set)return n.set(i,t);throw Error("object is readonly")}var r=M(n);return r[i]=t,r}},debugMode:!1};function x(t){return t&&"function"==typeof t.get}function q(t,n){return Object.is(t,n)||V.equals(t,n)}var z=function(){function t(t){this.error=t}return t.prototype.equals=function(n){return this===n||n instanceof t&&q(this.error,n.error)},t}(),B=function(){function t(t){this.value=t}return t.wrap=function(n){return n instanceof t?n:new t(n)},t.unwrap=function(n){return n instanceof t?n.value:n},t.map=function(n,i){return n instanceof t?t.wrap(i(n.value)):i(n)},t.prototype.equals=function(n){return this===n||n instanceof t&&q(this.value,n.value)},t}();function G(t,n){var i=n.creationStack;return i?Object.defineProperty(M(t),"stack",{value:t.stack+"\n"+i}):t}function N(t,n){if(t instanceof B){var i=N(t.value,n);if(i!==t.value)return B.wrap(i)}return n.creationStack&&t instanceof z?new z(G(t.error,n)):t}function P(t){if(V.debugMode){var n=Error().stack;return t.constructor.name+" created:\n"+(n&&n.substr(n.indexOf("\n")+1))}}var U,L,$,H,J=0;function K(){return J++}function Q(t){for(var n=U;n;){if(n.m===t)throw G(Error("cyclic dependency between derivables detected"),t);n=n.p}U={m:t,O:0,p:U,t:{}}}function W(){var t=U;if(!t)throw Error("No active recording!");U=t.p;for(var n=t.O,i=t.m,r=t.t,e=i[s],u=i[c],o=n,f=e.length;o<f;o++)rt(e[o],i);e.length=n;for(var h=0,a=e;h<a.length;h++){var v=a[h];u[v.id]=v.version}Object.values(r).forEach(g)}function X(){return!!U}function Y(){if(!U)return!1;for(var t=U.O,n=U.t,i=U.m[s],r=0;r<t;r++)if(!(i[r].id in n))return!1;return!0}function Z(t){var n=U;U=void 0;try{return t()}finally{U=n}}function tt(t){U?U.t[t.id]=t:g(t)}function nt(t,n){if(U&&!t.finalized){n&&(U.t[t.id]=t);var i=U.m,r=i[s];if(r[U.O]===t)U.O++;else{var e=r.indexOf(t);e<0?(it(t,i),U.O===r.length?r.push(t):(r.push(r[U.O]),r[U.O]=t),U.O++):e>U.O&&(r[e]=r[U.O],r[U.O]=t,U.O++)}}}function it(t,n){var i=t[d];i.push(n),1!==i.length||t.connected||t[o]()}function rt(t,n){var i=t[d],r=i.indexOf(n);if(r<0)throw Error("Inconsistent state!");i.splice(r,1),0===i.length&&t.connected&&(t[u]?et(t):t[h]())}function et(t){L?L.push(t):(L=[t],setTimeout((function(){var t=L;L=void 0,t.forEach((function(t){return t.connected&&0===t[d].length&&t[h]()}))}),0))}var ut=function(){function t(){this.id=K(),this.creationStack=P(this),this[$]=[],this[H]=!1,this.connected=!1,this.g=void 0,this.finalized=!1}return t.prototype.autoCache=function(){return this[u]=!0,this},t.prototype.getMaybeFinalState=function(){return this.connected||(this[u]?(this[o](),et(this)):X()&&this[o]()),this[l]()},t.prototype.getState=function(){return B.unwrap(this.getMaybeFinalState())},t.prototype[($=d,H=u,o)]=function(){this.finalized||ot(this,!0)},t.prototype[h]=function(){ot(this,!1)},t.prototype[v]=function(){this.finalized=!0,this.connected&&this[h]()},t}();function ot(t,n){t.connected=n,t.g&&Z((function(){return t.g.set(n)}))}var st,ct,ft=function(t){function i(n){var i=t.call(this)||this;return i.version=0,i.j=N(n,i),i.S()&&i[v](),i}return n(i,t),Object.defineProperty(i.prototype,"settable",{get:function(){return!this.S()},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this.j instanceof B},i.prototype[l]=function(){return nt(this,this.S()),this.j},i.prototype.set=function(t){var n=this.j;if(!q(t,n)){if(this.S())throw G(Error("cannot set a final derivable"),this);this.j=N(t,this),j(this,n,this.version++),S(this),this.S()&&tt(this)}},i.prototype[w]=function(t,n){this.j=t,this.version=n,k(this,[])},i}(ut),ht=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n.k=a,n.version=0,n}return n(i,t),i.prototype.S=function(){return this.k instanceof B},i.prototype[l]=function(){return this.connected?(nt(this,this.S()),this.k):this.S()?this.k:this._()},i.prototype.set=function(t){if(!this.acceptNewValue)throw G(Error("DataSource is not settable"),this);this.acceptNewValue(t)},i.prototype.checkForChanges=function(){var t=this;if(this.connected){var n=Z((function(){return t._()})),i=this.k;q(n,i)||(this.k=n,j(this,i,this.version++),S(this))}},i.prototype._=function(){try{return this.calculateCurrentValue()}catch(t){return new z(G(t,this))}},i.prototype[w]=function(t,n){this.version++,k(this,[])},i.prototype[o]=function(){t.prototype[o].call(this),this.connected&&this.checkForChanges()},i.prototype[h]=function(){t.prototype[h].call(this),this.finalized||(this.k=a)},Object.defineProperty(i.prototype,"settable",{get:function(){return!!this.acceptNewValue},enumerable:!1,configurable:!0}),i}(ut);function at(t){return t instanceof ut?t.get():t}function vt(t){return t instanceof ut?t.value:t}var lt=function(t){function i(){var n=null!==t&&t.apply(this,arguments)||this;return n.R=!1,n.k=a,n.A=0,n}return n(i,t),Object.defineProperty(i.prototype,"version",{get:function(){return this.T(),this.A},enumerable:!1,configurable:!0}),i.prototype.S=function(){return this.k instanceof B},i.prototype[l]=function(){if(this.connected)return this.T(),nt(this,this.S()),this.k;if(this.S())return this.k;var t=this.C();return t instanceof B&&(this.k=t,j(this,void 0,this.A++),tt(this)),t},i.prototype.T=function(){this.connected&&!this.R&&(this.k!==a&&(this.R=this.S()||this.D()),this.R||this.F())},i.prototype.F=function(){var t=this.C();q(t,this.k)||(this.k=t,j(this,void 0,this.A++),this.S()&&tt(this)),this.R=!0},i.prototype[b]=function(t){this.R&&(this.R=!1,k(this,t))},i.prototype[w]=function(t,n){this.k=a,this.A=n,this[b]([])},i.prototype[h]=function(){t.prototype[h].call(this),this.R=!1,this.finalized||(this.k=a)},i}(ut),bt=0,dt=function(t){function i(n,i){var r=t.call(this)||this;return r.I=n,r.M=i,r[st]=[],r[ct]={},r}return n(i,t),i.prototype.F=function(){Q(this);try{t.prototype.F.call(this)}finally{W()}},i.prototype.C=function(){++bt;try{var t=this.M?this.I.apply(this,this.M.map(at)):this.I();return Y()?B.wrap(t):t}catch(t){return t===m?m:new z(G(t,this))}finally{--bt}},i.prototype.D=function(){var t=this;return this[s].every((function(n){return t[c][n.id]===n.version}))},i.prototype[(st=s,ct=c,h)]=function(){for(var n=0,i=this[s];n<i.length;n++)rt(i[n],this);this[s].length=0,t.prototype[h].call(this)},i.prototype[v]=function(){t.prototype[v].call(this),this.I=void 0,this.M=void 0},i}(lt),wt=function(r){function e(t,n){var i=t.get,e=t.set,u=r.call(this,i,n)||this;return u.V=e,u}return n(e,r),e.prototype.set=function(n){if(this.finalized)throw G(Error("cannot set a final derivable"),this);this.M?this.V.apply(this,t([n],this.M.map(vt),!1)):this.V(n)},i([A()],e.prototype,"set",null),e}(dt),yt=function(t){function i(n,i){var r=t.call(this)||this;return r.q=n,r.B=i,r.G=0,r}return n(i,t),i.prototype.F=function(){this.G=this.q.version,t.prototype.F.call(this)},i.prototype.C=function(){var t=this;try{return Z((function(){var n=t.q.getMaybeFinalState();return B.map(n,(function(n){return t.B(n)}))}))}catch(t){return new z(G(t,this))}},i.prototype.D=function(){return this.G===this.q.version},i.prototype[o]=function(){t.prototype[o].call(this),this.connected&&it(this.q,this)},i.prototype[h]=function(){rt(this.q,this),t.prototype[h].call(this)},i.prototype[v]=function(){t.prototype[v].call(this),this.q=void 0,this.B=void 0},i}(lt),mt=function(t){function i(n,i,r){var e=t.call(this,n,i)||this;return e.N=r,e}return n(i,t),i.prototype.set=function(t){var n=this;if(this.finalized)throw G(Error("cannot set a final derivable"),this);this.q.set(B.map(t,(function(t){return n.N(t)})))},Object.defineProperty(i.prototype,"settable",{get:function(){return this.q.settable},enumerable:!1,configurable:!0}),i.prototype[v]=function(){t.prototype[v].call(this),this.N=void 0},i}(yt);function pt(t){return t.settable}function Ot(t){return"function"==typeof t?t():at(t)}function gt(){var t=this.getState();return t===m||t instanceof z?void 0:t}function jt(t){return this.set(t)}function St(t){return t instanceof ut}function kt(t){return St(t)&&t.settable}function _t(t){return t instanceof ft&&t.settable||t instanceof mt&&_t(t.q)}var Et=B.wrap(m);function Rt(t){return new ft(t)}function At(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new dt(t,n.length?n:void 0)}function Tt(t){return Rt.final(t)}function Ct(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new wt(t,n.length?n:void 0)}function Dt(t){var n=this,i=V.plucker,r=i.get,e=i.set,u=this;return St(t)?Ct({get:function(){return r.call(this,u.get(),t.get())},set:function(n){u.set(e.call(this,n,u.value,t.get()))}}):u.map((function(i){return r.call(n,i,t)}),(function(i){return e.call(n,i,u.value,t)}))}function Ft(){this.set(m)}function It(t){this.set(new z(t))}function Mt(t){this.set(B.wrap(t))}function Vt(n){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];this.set(n.apply(void 0,t([this.value],i.map(vt),!1)))}!function(t){function n(t){return new ft(B.wrap(t))}t.unresolved=function(){return new ft(m)},t.error=function(t){return new ft(new z(t))},t.final=n,function(t){t.unresolved=function(){return new ft(Et)},t.error=function(t){return new ft(B.wrap(new z(t)))}}(n=t.final||(t.final={}))}(Rt||(Rt={})),function(t){t.unresolved=function(){return Rt.final.unresolved()},t.error=function(t){return Rt.final.error(t)}}(Tt||(Tt={}));var xt=new ft(B.wrap(!0)),qt=new ft(B.wrap(!1)),zt=Symbol("skipped"),Bt=B.wrap(zt);function Gt(t,n,i,r){if(void 0!==t){var e=t?xt:qt;if(!function(t,n){return t===n||t instanceof ft&&t.j instanceof B&&t.j.value===n}(t,i)){if("function"==typeof t){var u=t;t=new dt((function(){return u(n)})).derive(at)}return St(t)?void 0!==r?t.mapState((function(t){return t===r?B.wrap(t):t})):t:e}}}function Nt(t){var n=B.unwrap(t);return n!==m&&!(n instanceof z)}Object.defineProperties(ut.prototype,{get:{value:function(){var t=this.getState();if(t instanceof z)throw t.error;if(t!==m)return t;if(bt>0)throw m;throw G(Error("Could not get value, derivable is unresolved"),this)}},getOr:{value:function(t){var n=this.getState();if(n instanceof z)throw n.error;return n===m?Ot(t):n}},value:{get:gt},resolved:{get:function(){return this.getState()!==m}},settable:{value:!1},final:{get:function(){return this.getMaybeFinalState()instanceof B}},errored:{get:function(){return this.getState()instanceof z}},error:{get:function(){var t=this.getState();return t instanceof z?t.error:void 0}},connected$:{get:function(){return this.g||(this.g=new ft(this.connected))}},derive:{value:function(n){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];return new dt(n,t([this],i,!0))}},map:{value:function(t,n){var i=function(n){return n===m||n instanceof z?n:t.call(this,n)};return n&&pt(this)?new mt(this,i,(function(t){return t===m||t instanceof z?t:n.call(this,t,this.q.value)})):new yt(this,i)}},mapState:{value:function(t,n){return n&&pt(this)?new mt(this,t,(function(t){return n.call(this,t,this.q.getState())})):new yt(this,t)}},flatMap:{value:function(t){return this.map(t).derive((function(t){return t.getState()}))}},pluck:{value:function(t){var n=this,i=V.plucker.get;return St(t)?this.derive(i,t):this.map((function(r){return i.call(n,r,t)}))}},fallbackTo:{value:function(t){var n=this;return St(t)?At((function(){return n.getOr(t)})):this.mapState((function(n){return n===m?Ot(t):n}))}},take:{value:function(t){var n=this,i=t.from,r=t.when,e=t.until,u=t.once,o=t.stopOnError,s=t.skipFirst,c=Gt(i,this,!0,!0),f=Gt(r,this,!0),h=Gt(e,this,!1,!0),a=s?new ft(m):void 0;if(!(c||f||h||u||o||a))return this;var v=(h||f)&&new ft(m);function l(t){return v&&v.set(t),t}return new dt((function(){if(c&&!c.get())return m;if(h&&h.get())return l(B.wrap(v.j));if(f&&!f.getOr(!1))return v.j;var t=n.getMaybeFinalState();if(a&&!Bt.equals(a.j)){if(!Nt(t))return l(t);if(a.j===m||q(t,a.j))return a.set(t),l(m);a.set(Bt)}return l(u&&Nt(t)||o&&t instanceof z?B.wrap(t):t)}))}},and:{value:function(t){return St(t)?this.derive((function(n){return n&&t.get()})):this.map((function(n){return n&&t}))}},or:{value:function(t){return St(t)?this.derive((function(n){return n||t.get()})):this.map((function(n){return n||t}))}},not:{value:function(){return this.map((function(t){return!t}))}},is:{value:function(t){return St(t)?this.derive(q,t):this.map((function(n){return q(n,t)}))}}}),[ft,ht,mt,wt].forEach((function(t){return Object.defineProperties(t.prototype,{value:{get:gt,set:jt},swap:{value:Vt},pluck:{value:Dt}})})),[ft,mt].forEach((function(t){return Object.defineProperties(t.prototype,{unset:{value:Ft},setError:{value:It},setFinal:{value:Mt}})})),Object.defineProperties(wt.prototype,{settable:{value:!0}}),ut.prototype.react=function(t,n){var i=this;return Z((function(){return Ut.create(i,t,n)}))},ut.prototype.toPromise=function(t){var n=this;return new Promise((function(i,e){return n.react(i,r(r({},t),{once:!0,onError:function(t,n){n(),e(t)}}))}))};var Pt,Ut=function(){function t(t,n,i,r){this.P=t,this.U=n,this.L=i,this.ended=r,this.$=!1,this.id=K(),this.H=0,this.creationStack=P(this),this.J=a}return t.prototype.K=function(){it(this.P,this),this.$=!0,this.u()},t.prototype.u=function(){var t=this;if(this.$){var n=function(n){return function(){n===m||q(t.J,n)||(t.J=n,n instanceof z?t.U(n.error):t.W(n))}},i=this.P[l]();i instanceof B?this.X(n(i.value)):n(i)()}},t.prototype.W=function(t){var n=this;this.H++;try{if(this.H>100)throw Error("Too deeply nested synchronous cyclical reactions disallowed. Use setImmediate.");this.L(t,(function(){return n.X()}))}catch(t){this.U(G(t,this))}finally{this.H--}},t.prototype.X=function(t){this.$&&(this.$=!1,rt(this.P,this),t&&t(),this.ended&&this.ended())},t.prototype[b]=function(t){t.indexOf(this)<0&&t.push(this)},t.create=function(n,i,r,e){var u=new t(r?n.take(r):n,(function(t){if(!r||!r.onError)throw o(),t;r.onError(t,o)}),i,e);function o(){u.X()}return u.K(),o},t}(),Lt=Object.freeze({__proto__:null,symbols:p,Atom:ft,BaseDerivable:ut,BaseDerivation:lt,Derivation:dt,Lens:wt,resolveFallback:Ot,safeUnwrap:vt,Reactor:Ut,isRecordingObservations:X,addObserver:it,allDependenciesAreFinal:Y,independentTracking:Z,markFinal:tt,maybeDisconnectInNextTick:et,recordObservation:nt,removeObserver:rt,startRecordingObservations:Q,stopRecordingObservations:W,processChangedState:S,augmentStack:G,isError:D}),$t={clone:M,equals:q,isPlainObject:function(t){if("object"!=typeof t||null==t)return!1;var n=Object.getPrototypeOf(t);return n===Object.prototype||null===n||t.constructor===Object},resolveFallback:Ot};(Pt="undefined"!=typeof window?window:global)[y]?(Pt[y]++,console.warn(Pt[y]+" instances of Sherlock detected. This could cause unexpected results.")):Pt[y]=1;export{z as ErrorWrapper,B as FinalWrapper,ht as PullDataSource,Lt as _internal,Rt as atom,A as atomic,R as atomically,V as config,Tt as constant,At as derive,O as inTransaction,St as isDerivable,_t as isDerivableAtom,kt as isSettableDerivable,Ct as lens,vt as safeUnwrap,E as transact,T as transaction,m as unresolved,at as unwrap,$t as utils};
//# sourceMappingURL=sherlock.esm.min.js.map

@@ -15,3 +15,3 @@ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).Sherlock={})}(this,(function(t){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var n=function(t,i){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])})(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+i+" is not a constructor or null");function r(){this.constructor=t}n(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var n,i=1,r=arguments.length;i<r;i++)for(var e in n=arguments[i])Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e]);return t}).apply(this,arguments)};function e(){for(var t=0,n=0,i=arguments.length;n<i;n++)t+=arguments[n].length;var r=Array(t),e=0;for(n=0;n<i;n++)for(var o=arguments[n],u=0,s=o.length;u<s;u++,e++)r[e]=o[u];return r}var o,u=Symbol("autoCacheMode"),s=Symbol("connect"),c=Symbol("dependencies"),f=Symbol("dependencyVersions"),h=Symbol("derivableAtom"),a=Symbol("disconnect"),l=Symbol("emptyCache"),v=Symbol("finalize"),b=Symbol("internalGetState"),d=Symbol("mark"),w=Symbol("observers"),y=Symbol("rollback"),p=Symbol("sherlockInstances"),O=Symbol("unresolved"),j=Object.freeze({__proto__:null,autoCacheMode:u,connect:s,dependencies:c,dependencyVersions:f,derivableAtom:h,disconnect:a,emptyCache:l,finalize:v,internalGetState:b,mark:d,observers:w,rollback:y,sherlockInstances:p,unresolved:O});function m(){return!!o}function g(t){o?o.t[t.id]=t:t[v]()}function _(t,n,i){o&&C(o,t,n,i)}function S(t){if(o)k(t,o.i);else{var n=[];k(t,n),E(n)}}function k(t,n){for(var i=0,r=t[w];i<r.length;i++)r[i][d](n)}function E(t){for(var n=0,i=t;n<i.length;n++)i[n].o()}function R(t){var n;o={u:[],h:{},l:{},t:{},i:[],v:o};try{n=t()}catch(t){throw function(){var t=o;if(!t)throw Error();o=t.v,t.u.forEach((function(n){return n[y](t.h[n.id],t.l[n.id])}))}(),t}return function(){var t,n=o;if(!n)throw Error();(o=n.v)?(n.u.forEach((function(t){return C(o,t,n.h[t.id],n.l[t.id])})),(t=o.i).push.apply(t,n.i),Object.assign(o.t,n.t)):(Object.values(n.t).forEach((function(t){return t[v]()})),E(n.i))}(),n}function T(t){return m()?t():R(t)}function A(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return T((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&A(i.value)}}function C(t,n,i,r){var e=n.id;e in t.h||(t.u.push(n),t.h[e]=i,t.l[e]=r)}var x=Object.getOwnPropertyDescriptors||function(t){for(var n={},i=0,r=D(t);i<r.length;i++){var e=r[i];n[e]=Object.getOwnPropertyDescriptor(t,e)}return n},D="undefined"!=typeof Reflect?Reflect.ownKeys:function(t){return e(Object.getOwnPropertyNames(t),Object.getOwnPropertySymbols(t))};function F(t){return Array.isArray(t)?function(t){try{return Object.defineProperties(new t.constructor,x(t))}catch(t){throw Object.assign(Error("could not clone Array: "+(t&&t.message)),{jse_cause:t})}}(t):Object.create(Object.getPrototypeOf(t),x(t))}var I={equals:function(t,n){return(i=t)&&"function"==typeof i.equals&&!!t.equals(n);var i},plucker:{get:function(t,n){return M(t)?t.get(n):t[n]},set:function(t,n,i){if(M(n)){if("function"==typeof n.set)return n.set(i,t);throw Error("object is readonly")}var r=F(n);return r[i]=t,r}},debugMode:!1};function M(t){return t&&"function"==typeof t.get}function V(t,n){return Object.is(t,n)||I.equals(t,n)}var q=function(){function t(t){this.error=t}return t.prototype.equals=function(n){return this===n||n instanceof t&&V(this.error,n.error)},t}(),z=function(){function t(t){this.value=t}return t.wrap=function(n){return n instanceof t?n:new t(n)},t.unwrap=function(n){return n instanceof t?n.value:n},t.map=function(n,i){return n instanceof t?t.wrap(i(n.value)):i(n)},t.prototype.equals=function(n){return this===n||n instanceof t&&V(this.value,n.value)},t}();function B(t,n){var i=n.creationStack;return i?Object.defineProperty(F(t),"stack",{value:t.stack+"\n"+i}):t}function G(t,n){if(t instanceof z){var i=G(t.value,n);if(i!==t.value)return z.wrap(i)}return n.creationStack&&t instanceof q?new q(B(t.error,n)):t}function N(t){if(I.debugMode){var n=Error().stack;return t.constructor.name+" created:\n"+(n&&n.substr(n.indexOf("\n")+1))}}var P,U,L,$,H=0;function J(){return H++}function K(t){for(var n=P;n;){if(n.p===t)throw B(Error("cyclic dependency between derivables detected"),t);n=n.O}P={p:t,j:0,O:P,t:{}}}function Q(){var t=P;if(!t)throw Error("No active recording!");P=t.O;for(var n=t.j,i=t.p,r=t.t,e=i[c],o=i[f],u=n,s=e.length;u<s;u++)it(e[u],i);e.length=n;for(var h=0,a=e;h<a.length;h++){var l=a[h];o[l.id]=l.version}Object.values(r).forEach(g)}function W(){return!!P}function X(){if(!P)return!1;for(var t=P.j,n=P.t,i=P.p[c],r=0;r<t;r++)if(!(i[r].id in n))return!1;return!0}function Y(t){var n=P;P=void 0;try{return t()}finally{P=n}}function Z(t){P?P.t[t.id]=t:g(t)}function tt(t,n){if(P&&!t.finalized){n&&(P.t[t.id]=t);var i=P.p,r=i[c];if(r[P.j]===t)P.j++;else{var e=r.indexOf(t);e<0?(nt(t,i),P.j===r.length?r.push(t):(r.push(r[P.j]),r[P.j]=t),P.j++):e>P.j&&(r[e]=r[P.j],r[P.j]=t,P.j++)}}}function nt(t,n){var i=t[w];i.push(n),1!==i.length||t.connected||t[s]()}function it(t,n){var i=t[w],r=i.indexOf(n);if(r<0)throw Error("Inconsistent state!");i.splice(r,1),0===i.length&&t.connected&&(t[u]?rt(t):t[a]())}function rt(t){U?U.push(t):(U=[t],setTimeout((function(){var t=U;U=void 0,t.forEach((function(t){return t.connected&&0===t[w].length&&t[a]()}))}),0))}var et=function(){function t(){this.id=J(),this.creationStack=N(this),this[L]=[],this[$]=!1,this.connected=!1,this.m=void 0,this.finalized=!1}return t.prototype.autoCache=function(){return this[u]=!0,this},t.prototype.getMaybeFinalState=function(){return this.connected||(this[u]?(this[s](),rt(this)):W()&&this[s]()),this[b]()},t.prototype.getState=function(){return z.unwrap(this.getMaybeFinalState())},t.prototype[(L=w,$=u,s)]=function(){this.finalized||ot(this,!0)},t.prototype[a]=function(){ot(this,!1)},t.prototype[v]=function(){this.finalized=!0,this.connected&&this[a]()},t}();function ot(t,n){t.connected=n,t.m&&Y((function(){return t.m.set(n)}))}var ut,st,ct=function(t){function n(n){var i=t.call(this)||this;return i.version=0,i.g=G(n,i),i._()&&i[v](),i}return i(n,t),Object.defineProperty(n.prototype,"settable",{get:function(){return!this._()},enumerable:!1,configurable:!0}),n.prototype._=function(){return this.g instanceof z},n.prototype[b]=function(){return tt(this,this._()),this.g},n.prototype.set=function(t){var n=this.g;if(!V(t,n)){if(this._())throw B(Error("cannot set a final derivable"),this);this.g=G(t,this),_(this,n,this.version++),S(this),this._()&&Z(this)}},n.prototype[y]=function(t,n){this.g=t,this.version=n,k(this,[])},n}(et),ft=function(t){function n(){var n=null!==t&&t.apply(this,arguments)||this;return n.S=l,n.version=0,n}return i(n,t),n.prototype._=function(){return this.S instanceof z},n.prototype[b]=function(){return this.connected?(tt(this,this._()),this.S):this._()?this.S:this.k()},n.prototype.set=function(t){if(!this.acceptNewValue)throw B(Error("DataSource is not settable"),this);this.acceptNewValue(t)},n.prototype.checkForChanges=function(){var t=this;if(this.connected){var n=Y((function(){return t.k()})),i=this.S;V(n,i)||(this.S=n,_(this,i,this.version++),S(this))}},n.prototype.k=function(){try{return this.calculateCurrentValue()}catch(t){return new q(B(t,this))}},n.prototype[y]=function(t,n){this.version++,k(this,[])},n.prototype[s]=function(){t.prototype[s].call(this),this.connected&&this.checkForChanges()},n.prototype[a]=function(){t.prototype[a].call(this),this.finalized||(this.S=l)},Object.defineProperty(n.prototype,"settable",{get:function(){return!!this.acceptNewValue},enumerable:!1,configurable:!0}),n}(et);function ht(t){return t instanceof et?t.get():t}function at(t){return t instanceof et?t.value:t}var lt=function(t){function n(){var n=null!==t&&t.apply(this,arguments)||this;return n.R=!1,n.S=l,n.T=0,n}return i(n,t),Object.defineProperty(n.prototype,"version",{get:function(){return this.A(),this.T},enumerable:!1,configurable:!0}),n.prototype._=function(){return this.S instanceof z},n.prototype[b]=function(){if(this.connected)return this.A(),tt(this,this._()),this.S;if(this._())return this.S;var t=this.C();return t instanceof z&&(this.S=t,_(this,void 0,this.T++),Z(this)),t},n.prototype.A=function(){this.connected&&!this.R&&(this.S!==l&&(this.R=this._()||this.D()),this.R||this.F())},n.prototype.F=function(){var t=this.C();V(t,this.S)||(this.S=t,_(this,void 0,this.T++),this._()&&Z(this)),this.R=!0},n.prototype[d]=function(t){this.R&&(this.R=!1,k(this,t))},n.prototype[y]=function(t,n){this.S=l,this.T=n,this[d]([])},n.prototype[a]=function(){t.prototype[a].call(this),this.R=!1,this.finalized||(this.S=l)},n}(et),vt=0,bt=function(t){function n(n,i){var r=t.call(this)||this;return r.I=n,r.M=i,r[ut]=[],r[st]={},r}return i(n,t),n.prototype.F=function(){K(this);try{t.prototype.F.call(this)}finally{Q()}},n.prototype.C=function(){++vt;try{var t=this.M?this.I.apply(this,this.M.map(ht)):this.I();return X()?z.wrap(t):t}catch(t){return t===O?O:new q(B(t,this))}finally{--vt}},n.prototype.D=function(){var t=this;return this[c].every((function(n){return t[f][n.id]===n.version}))},n.prototype[(ut=c,st=f,a)]=function(){for(var n=0,i=this[c];n<i.length;n++)it(i[n],this);this[c].length=0,t.prototype[a].call(this)},n.prototype[v]=function(){t.prototype[v].call(this),this.I=void 0,this.M=void 0},n}(lt),dt=function(t){function n(n,i){var r=n.get,e=n.set,o=t.call(this,r,i)||this;return o.V=e,o}return i(n,t),n.prototype.set=function(t){if(this.finalized)throw B(Error("cannot set a final derivable"),this);this.M?this.V.apply(this,e([t],this.M.map(at))):this.V(t)},function(t,n,i,r){var e,o=arguments.length,u=o<3?n:null===r?r=Object.getOwnPropertyDescriptor(n,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(t,n,i,r);else for(var s=t.length-1;s>=0;s--)(e=t[s])&&(u=(o<3?e(u):o>3?e(n,i,u):e(n,i))||u);o>3&&u&&Object.defineProperty(n,i,u)}([A()],n.prototype,"set",null),n}(bt),wt=function(t){function n(n,i){var r=t.call(this)||this;return r.q=n,r.B=i,r.G=0,r}return i(n,t),n.prototype.F=function(){this.G=this.q.version,t.prototype.F.call(this)},n.prototype.C=function(){var t=this;try{return Y((function(){var n=t.q.getMaybeFinalState();return z.map(n,(function(n){return t.B(n)}))}))}catch(t){return new q(B(t,this))}},n.prototype.D=function(){return this.G===this.q.version},n.prototype[s]=function(){t.prototype[s].call(this),this.connected&&nt(this.q,this)},n.prototype[a]=function(){it(this.q,this),t.prototype[a].call(this)},n.prototype[v]=function(){t.prototype[v].call(this),this.q=void 0,this.B=void 0},n}(lt),yt=function(t){function n(n,i,r){var e=t.call(this,n,i)||this;return e.N=r,e}return i(n,t),n.prototype.set=function(t){var n=this;if(this.finalized)throw B(Error("cannot set a final derivable"),this);this.q.set(z.map(t,(function(t){return n.N(t)})))},Object.defineProperty(n.prototype,"settable",{get:function(){return this.q.settable},enumerable:!1,configurable:!0}),n.prototype[v]=function(){t.prototype[v].call(this),this.N=void 0},n}(wt);function pt(t){return t.settable}function Ot(t){return"function"==typeof t?t():ht(t)}function jt(){var t=this.getState();return t===O||t instanceof q?void 0:t}function mt(t){return this.set(t)}function gt(t){return t instanceof et}var _t=z.wrap(O);function St(t){return new ct(t)}function kt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new bt(t,n.length?n:void 0)}function Et(t){return St.final(t)}function Rt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new dt(t,n.length?n:void 0)}function Tt(t){var n=this,i=I.plucker,r=i.get,e=i.set,o=this;return gt(t)?Rt({get:function(){return r.call(this,o.get(),t.get())},set:function(n){o.set(e.call(this,n,o.value,t.get()))}}):o.map((function(i){return r.call(n,i,t)}),(function(i){return e.call(n,i,o.value,t)}))}function At(){this.set(O)}function Ct(t){this.set(new q(t))}function xt(t){this.set(z.wrap(t))}function Dt(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];this.set(t.apply(void 0,e([this.value],n.map(at))))}!function(t){function n(t){return new ct(z.wrap(t))}t.unresolved=function(){return new ct(O)},t.error=function(t){return new ct(new q(t))},t.final=n,function(t){t.unresolved=function(){return new ct(_t)},t.error=function(t){return new ct(z.wrap(new q(t)))}}(n=t.final||(t.final={}))}(St||(St={})),function(t){t.unresolved=function(){return St.final.unresolved()},t.error=function(t){return St.final.error(t)}}(Et||(Et={}));var Ft=new ct(z.wrap(!0)),It=new ct(z.wrap(!1)),Mt=Symbol("skipped"),Vt=z.wrap(Mt);function qt(t,n,i,r){if(void 0!==t){var e=t?Ft:It;if(!function(t,n){return t===n||t instanceof ct&&t.g instanceof z&&t.g.value===n}(t,i)){if("function"==typeof t){var o=t;t=new bt((function(){return o(n)})).derive(ht)}return gt(t)?void 0!==r?t.mapState((function(t){return t===r?z.wrap(t):t})):t:e}}}function zt(t){var n=z.unwrap(t);return n!==O&&!(n instanceof q)}Object.defineProperties(et.prototype,{get:{value:function(){var t=this.getState();if(t instanceof q)throw t.error;if(t!==O)return t;if(vt>0)throw O;throw B(Error("Could not get value, derivable is unresolved"),this)}},getOr:{value:function(t){var n=this.getState();if(n instanceof q)throw n.error;return n===O?Ot(t):n}},value:{get:jt},resolved:{get:function(){return this.getState()!==O}},settable:{value:!1},final:{get:function(){return this.getMaybeFinalState()instanceof z}},errored:{get:function(){return this.getState()instanceof q}},error:{get:function(){var t=this.getState();return t instanceof q?t.error:void 0}},connected$:{get:function(){return this.m||(this.m=new ct(this.connected))}},derive:{value:function(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new bt(t,e([this],n))}},map:{value:function(t,n){var i=function(n){return n===O||n instanceof q?n:t.call(this,n)};return n&&pt(this)?new yt(this,i,(function(t){return t===O||t instanceof q?t:n.call(this,t,this.q.value)})):new wt(this,i)}},mapState:{value:function(t,n){return n&&pt(this)?new yt(this,t,(function(t){return n.call(this,t,this.q.getState())})):new wt(this,t)}},flatMap:{value:function(t){return this.map(t).derive((function(t){return t.getState()}))}},pluck:{value:function(t){var n=this,i=I.plucker.get;return gt(t)?this.derive(i,t):this.map((function(r){return i.call(n,r,t)}))}},fallbackTo:{value:function(t){var n=this;return gt(t)?kt((function(){return n.getOr(t)})):this.mapState((function(n){return n===O?Ot(t):n}))}},take:{value:function(t){var n=this,i=t.from,r=t.when,e=t.until,o=t.once,u=t.stopOnError,s=t.skipFirst,c=qt(i,this,!0,!0),f=qt(r,this,!0),h=qt(e,this,!1,!0),a=s?new ct(O):void 0;if(!(c||f||h||o||u||a))return this;var l=(h||f)&&new ct(O);function v(t){return l&&l.set(t),t}return new bt((function(){if(c&&!c.get())return O;if(h&&h.get())return v(z.wrap(l.g));if(f&&!f.getOr(!1))return l.g;var t=n.getMaybeFinalState();if(a&&!Vt.equals(a.g)){if(!zt(t))return v(t);if(a.g===O||V(t,a.g))return a.set(t),v(O);a.set(Vt)}return v(o&&zt(t)||u&&t instanceof q?z.wrap(t):t)}))}},and:{value:function(t){return gt(t)?this.derive((function(n){return n&&t.get()})):this.map((function(n){return n&&t}))}},or:{value:function(t){return gt(t)?this.derive((function(n){return n||t.get()})):this.map((function(n){return n||t}))}},not:{value:function(){return this.map((function(t){return!t}))}},is:{value:function(t){return gt(t)?this.derive(V,t):this.map((function(n){return V(n,t)}))}}}),[ct,ft,yt,dt].forEach((function(t){return Object.defineProperties(t.prototype,{value:{get:jt,set:mt},swap:{value:Dt},pluck:{value:Tt}})})),[ct,yt].forEach((function(t){return Object.defineProperties(t.prototype,{unset:{value:At},setError:{value:Ct},setFinal:{value:xt}})})),Object.defineProperties(dt.prototype,{settable:{value:!0}}),et.prototype.react=function(t,n){var i=this;return Y((function(){return Gt.create(i,t,n)}))},et.prototype.toPromise=function(t){var n=this;return new Promise((function(i,e){return n.react(i,r(r({},t),{once:!0,onError:function(t,n){n(),e(t)}}))}))};var Bt,Gt=function(){function t(t,n,i,r){this.P=t,this.U=n,this.L=i,this.ended=r,this.$=!1,this.id=J(),this.H=0,this.creationStack=N(this),this.J=l}return t.prototype.K=function(){nt(this.P,this),this.$=!0,this.o()},t.prototype.o=function(){var t=this;if(this.$){var n=function(n){return function(){n===O||V(t.J,n)||(t.J=n,n instanceof q?t.U(n.error):t.W(n))}},i=this.P[b]();i instanceof z?this.X(n(i.value)):n(i)()}},t.prototype.W=function(t){var n=this;this.H++;try{if(this.H>100)throw Error("Too deeply nested synchronous cyclical reactions disallowed. Use setImmediate.");this.L(t,(function(){return n.X()}))}catch(t){this.U(B(t,this))}finally{this.H--}},t.prototype.X=function(t){this.$&&(this.$=!1,it(this.P,this),t&&t(),this.ended&&this.ended())},t.prototype[d]=function(t){t.indexOf(this)<0&&t.push(this)},t.create=function(n,i,r,e){var o=new t(r?n.take(r):n,(function(t){if(!r||!r.onError)throw u(),t;r.onError(t,u)}),i,e);function u(){o.X()}return o.K(),u},t}(),Nt=Object.freeze({__proto__:null,symbols:j,Atom:ct,BaseDerivable:et,BaseDerivation:lt,Derivation:bt,Lens:dt,resolveFallback:Ot,safeUnwrap:at,Reactor:Gt,isRecordingObservations:W,addObserver:nt,allDependenciesAreFinal:X,independentTracking:Y,markFinal:Z,maybeDisconnectInNextTick:rt,recordObservation:tt,removeObserver:it,startRecordingObservations:K,stopRecordingObservations:Q,processChangedState:S,augmentStack:B}),Pt={clone:F,equals:V,isPlainObject:function(t){if("object"!=typeof t||null==t)return!1;var n=Object.getPrototypeOf(t);return n===Object.prototype||null===n||t.constructor===Object},resolveFallback:Ot};(Bt="undefined"!=typeof window?window:global)[p]?(Bt[p]++,console.warn(Bt[p]+" instances of Sherlock detected. This could cause unexpected results.")):Bt[p]=1,t.ErrorWrapper=q,t.FinalWrapper=z,t.PullDataSource=ft,t._internal=Nt,t.atom=St,t.atomic=A,t.atomically=T,t.config=I,t.constant=Et,t.derive=kt,t.inTransaction=m,t.isDerivable=gt,t.isDerivableAtom=function t(n){return n instanceof ct&&n.settable||n instanceof yt&&t(n.q)},t.isSettableDerivable=function(t){return gt(t)&&t.settable},t.lens=Rt,t.safeUnwrap=at,t.transact=R,t.transaction=function t(n){return n?function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];var r=this;return R((function(){return n.apply(r,t)}))}:function(n,i,r){r.value=r.value&&t(r.value)}},t.unresolved=O,t.unwrap=ht,t.utils=Pt,Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */var n=function(t,i){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])},n(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+i+" is not a constructor or null");function r(){this.constructor=t}n(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}var r=function(){return r=Object.assign||function(t){for(var n,i=1,r=arguments.length;i<r;i++)for(var e in n=arguments[i])Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e]);return t},r.apply(this,arguments)};function e(t,n,i){if(i||2===arguments.length)for(var r,e=0,o=n.length;e<o;e++)!r&&e in n||(r||(r=Array.prototype.slice.call(n,0,e)),r[e]=n[e]);return t.concat(r||Array.prototype.slice.call(n))}var o,u=Symbol("autoCacheMode"),s=Symbol("connect"),c=Symbol("dependencies"),f=Symbol("dependencyVersions"),h=Symbol("derivableAtom"),a=Symbol("disconnect"),l=Symbol("emptyCache"),v=Symbol("finalize"),b=Symbol("internalGetState"),d=Symbol("mark"),y=Symbol("observers"),w=Symbol("rollback"),p=Symbol("sherlockInstances"),O=Symbol("unresolved"),j=Object.freeze({__proto__:null,autoCacheMode:u,connect:s,dependencies:c,dependencyVersions:f,derivableAtom:h,disconnect:a,emptyCache:l,finalize:v,internalGetState:b,mark:d,observers:y,rollback:w,sherlockInstances:p,unresolved:O});function m(){return!!o}function g(t){o?o.t[t.id]=t:t[v]()}function _(t,n,i){o&&C(o,t,n,i)}function S(t){if(o)k(t,o.i);else{var n=[];k(t,n),E(n)}}function k(t,n){for(var i=0,r=t[y];i<r.length;i++)r[i][d](n)}function E(t){for(var n=0,i=t;n<i.length;n++)i[n].o()}function R(t){var n;o={u:[],h:{},l:{},t:{},i:[],v:o};try{n=t()}catch(t){throw function(){var t=o;if(!t)throw Error();o=t.v,t.u.forEach((function(n){return n[w](t.h[n.id],t.l[n.id])}))}(),t}return function(){var t,n=o;if(!n)throw Error();(o=n.v)?(n.u.forEach((function(t){return C(o,t,n.h[t.id],n.l[t.id])})),(t=o.i).push.apply(t,n.i),Object.assign(o.t,n.t)):(Object.values(n.t).forEach((function(t){return t[v]()})),E(n.i))}(),n}function A(t){return m()?t():R(t)}function T(t){return t?function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var r=this;return A((function(){return t.apply(r,n)}))}:function(t,n,i){i.value=i.value&&T(i.value)}}function C(t,n,i,r){var e=n.id;e in t.h||(t.u.push(n),t.h[e]=i,t.l[e]=r)}function x(t){if(!t||"object"!=typeof t)return!1;var n=t;return"string"==typeof n.message&&"string"==typeof n.name&&(void 0===n.stack||"string"==typeof n.stack)}var D=Object.getOwnPropertyDescriptors||function(t){for(var n={},i=0,r=F(t);i<r.length;i++){var e=r[i];n[e]=Object.getOwnPropertyDescriptor(t,e)}return n},F="undefined"!=typeof Reflect?Reflect.ownKeys:function(t){return e(e([],Object.getOwnPropertyNames(t),!0),Object.getOwnPropertySymbols(t),!0)};function I(t){return Array.isArray(t)?function(t){try{return Object.defineProperties(new t.constructor,D(t))}catch(t){throw Object.assign(Error("could not clone Array: "+(x(t)&&t.message)),{jse_cause:t})}}(t):Object.create(Object.getPrototypeOf(t),D(t))}var M={equals:function(t,n){return(i=t)&&"function"==typeof i.equals&&!!t.equals(n);var i},plucker:{get:function(t,n){return V(t)?t.get(n):t[n]},set:function(t,n,i){if(V(n)){if("function"==typeof n.set)return n.set(i,t);throw Error("object is readonly")}var r=I(n);return r[i]=t,r}},debugMode:!1};function V(t){return t&&"function"==typeof t.get}function q(t,n){return Object.is(t,n)||M.equals(t,n)}var z=function(){function t(t){this.error=t}return t.prototype.equals=function(n){return this===n||n instanceof t&&q(this.error,n.error)},t}(),B=function(){function t(t){this.value=t}return t.wrap=function(n){return n instanceof t?n:new t(n)},t.unwrap=function(n){return n instanceof t?n.value:n},t.map=function(n,i){return n instanceof t?t.wrap(i(n.value)):i(n)},t.prototype.equals=function(n){return this===n||n instanceof t&&q(this.value,n.value)},t}();function G(t,n){var i=n.creationStack;return i?Object.defineProperty(I(t),"stack",{value:t.stack+"\n"+i}):t}function N(t,n){if(t instanceof B){var i=N(t.value,n);if(i!==t.value)return B.wrap(i)}return n.creationStack&&t instanceof z?new z(G(t.error,n)):t}function P(t){if(M.debugMode){var n=Error().stack;return t.constructor.name+" created:\n"+(n&&n.substr(n.indexOf("\n")+1))}}var U,L,$,H,J=0;function K(){return J++}function Q(t){for(var n=U;n;){if(n.p===t)throw G(Error("cyclic dependency between derivables detected"),t);n=n.O}U={p:t,j:0,O:U,t:{}}}function W(){var t=U;if(!t)throw Error("No active recording!");U=t.O;for(var n=t.j,i=t.p,r=t.t,e=i[c],o=i[f],u=n,s=e.length;u<s;u++)rt(e[u],i);e.length=n;for(var h=0,a=e;h<a.length;h++){var l=a[h];o[l.id]=l.version}Object.values(r).forEach(g)}function X(){return!!U}function Y(){if(!U)return!1;for(var t=U.j,n=U.t,i=U.p[c],r=0;r<t;r++)if(!(i[r].id in n))return!1;return!0}function Z(t){var n=U;U=void 0;try{return t()}finally{U=n}}function tt(t){U?U.t[t.id]=t:g(t)}function nt(t,n){if(U&&!t.finalized){n&&(U.t[t.id]=t);var i=U.p,r=i[c];if(r[U.j]===t)U.j++;else{var e=r.indexOf(t);e<0?(it(t,i),U.j===r.length?r.push(t):(r.push(r[U.j]),r[U.j]=t),U.j++):e>U.j&&(r[e]=r[U.j],r[U.j]=t,U.j++)}}}function it(t,n){var i=t[y];i.push(n),1!==i.length||t.connected||t[s]()}function rt(t,n){var i=t[y],r=i.indexOf(n);if(r<0)throw Error("Inconsistent state!");i.splice(r,1),0===i.length&&t.connected&&(t[u]?et(t):t[a]())}function et(t){L?L.push(t):(L=[t],setTimeout((function(){var t=L;L=void 0,t.forEach((function(t){return t.connected&&0===t[y].length&&t[a]()}))}),0))}var ot=function(){function t(){this.id=K(),this.creationStack=P(this),this[$]=[],this[H]=!1,this.connected=!1,this.m=void 0,this.finalized=!1}return t.prototype.autoCache=function(){return this[u]=!0,this},t.prototype.getMaybeFinalState=function(){return this.connected||(this[u]?(this[s](),et(this)):X()&&this[s]()),this[b]()},t.prototype.getState=function(){return B.unwrap(this.getMaybeFinalState())},t.prototype[($=y,H=u,s)]=function(){this.finalized||ut(this,!0)},t.prototype[a]=function(){ut(this,!1)},t.prototype[v]=function(){this.finalized=!0,this.connected&&this[a]()},t}();function ut(t,n){t.connected=n,t.m&&Z((function(){return t.m.set(n)}))}var st,ct,ft=function(t){function n(n){var i=t.call(this)||this;return i.version=0,i.g=N(n,i),i._()&&i[v](),i}return i(n,t),Object.defineProperty(n.prototype,"settable",{get:function(){return!this._()},enumerable:!1,configurable:!0}),n.prototype._=function(){return this.g instanceof B},n.prototype[b]=function(){return nt(this,this._()),this.g},n.prototype.set=function(t){var n=this.g;if(!q(t,n)){if(this._())throw G(Error("cannot set a final derivable"),this);this.g=N(t,this),_(this,n,this.version++),S(this),this._()&&tt(this)}},n.prototype[w]=function(t,n){this.g=t,this.version=n,k(this,[])},n}(ot),ht=function(t){function n(){var n=null!==t&&t.apply(this,arguments)||this;return n.S=l,n.version=0,n}return i(n,t),n.prototype._=function(){return this.S instanceof B},n.prototype[b]=function(){return this.connected?(nt(this,this._()),this.S):this._()?this.S:this.k()},n.prototype.set=function(t){if(!this.acceptNewValue)throw G(Error("DataSource is not settable"),this);this.acceptNewValue(t)},n.prototype.checkForChanges=function(){var t=this;if(this.connected){var n=Z((function(){return t.k()})),i=this.S;q(n,i)||(this.S=n,_(this,i,this.version++),S(this))}},n.prototype.k=function(){try{return this.calculateCurrentValue()}catch(t){return new z(G(t,this))}},n.prototype[w]=function(t,n){this.version++,k(this,[])},n.prototype[s]=function(){t.prototype[s].call(this),this.connected&&this.checkForChanges()},n.prototype[a]=function(){t.prototype[a].call(this),this.finalized||(this.S=l)},Object.defineProperty(n.prototype,"settable",{get:function(){return!!this.acceptNewValue},enumerable:!1,configurable:!0}),n}(ot);function at(t){return t instanceof ot?t.get():t}function lt(t){return t instanceof ot?t.value:t}var vt=function(t){function n(){var n=null!==t&&t.apply(this,arguments)||this;return n.R=!1,n.S=l,n.A=0,n}return i(n,t),Object.defineProperty(n.prototype,"version",{get:function(){return this.T(),this.A},enumerable:!1,configurable:!0}),n.prototype._=function(){return this.S instanceof B},n.prototype[b]=function(){if(this.connected)return this.T(),nt(this,this._()),this.S;if(this._())return this.S;var t=this.C();return t instanceof B&&(this.S=t,_(this,void 0,this.A++),tt(this)),t},n.prototype.T=function(){this.connected&&!this.R&&(this.S!==l&&(this.R=this._()||this.D()),this.R||this.F())},n.prototype.F=function(){var t=this.C();q(t,this.S)||(this.S=t,_(this,void 0,this.A++),this._()&&tt(this)),this.R=!0},n.prototype[d]=function(t){this.R&&(this.R=!1,k(this,t))},n.prototype[w]=function(t,n){this.S=l,this.A=n,this[d]([])},n.prototype[a]=function(){t.prototype[a].call(this),this.R=!1,this.finalized||(this.S=l)},n}(ot),bt=0,dt=function(t){function n(n,i){var r=t.call(this)||this;return r.I=n,r.M=i,r[st]=[],r[ct]={},r}return i(n,t),n.prototype.F=function(){Q(this);try{t.prototype.F.call(this)}finally{W()}},n.prototype.C=function(){++bt;try{var t=this.M?this.I.apply(this,this.M.map(at)):this.I();return Y()?B.wrap(t):t}catch(t){return t===O?O:new z(G(t,this))}finally{--bt}},n.prototype.D=function(){var t=this;return this[c].every((function(n){return t[f][n.id]===n.version}))},n.prototype[(st=c,ct=f,a)]=function(){for(var n=0,i=this[c];n<i.length;n++)rt(i[n],this);this[c].length=0,t.prototype[a].call(this)},n.prototype[v]=function(){t.prototype[v].call(this),this.I=void 0,this.M=void 0},n}(vt),yt=function(t){function n(n,i){var r=n.get,e=n.set,o=t.call(this,r,i)||this;return o.V=e,o}return i(n,t),n.prototype.set=function(t){if(this.finalized)throw G(Error("cannot set a final derivable"),this);this.M?this.V.apply(this,e([t],this.M.map(lt),!1)):this.V(t)},function(t,n,i,r){var e,o=arguments.length,u=o<3?n:null===r?r=Object.getOwnPropertyDescriptor(n,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(t,n,i,r);else for(var s=t.length-1;s>=0;s--)(e=t[s])&&(u=(o<3?e(u):o>3?e(n,i,u):e(n,i))||u);o>3&&u&&Object.defineProperty(n,i,u)}([T()],n.prototype,"set",null),n}(dt),wt=function(t){function n(n,i){var r=t.call(this)||this;return r.q=n,r.B=i,r.G=0,r}return i(n,t),n.prototype.F=function(){this.G=this.q.version,t.prototype.F.call(this)},n.prototype.C=function(){var t=this;try{return Z((function(){var n=t.q.getMaybeFinalState();return B.map(n,(function(n){return t.B(n)}))}))}catch(t){return new z(G(t,this))}},n.prototype.D=function(){return this.G===this.q.version},n.prototype[s]=function(){t.prototype[s].call(this),this.connected&&it(this.q,this)},n.prototype[a]=function(){rt(this.q,this),t.prototype[a].call(this)},n.prototype[v]=function(){t.prototype[v].call(this),this.q=void 0,this.B=void 0},n}(vt),pt=function(t){function n(n,i,r){var e=t.call(this,n,i)||this;return e.N=r,e}return i(n,t),n.prototype.set=function(t){var n=this;if(this.finalized)throw G(Error("cannot set a final derivable"),this);this.q.set(B.map(t,(function(t){return n.N(t)})))},Object.defineProperty(n.prototype,"settable",{get:function(){return this.q.settable},enumerable:!1,configurable:!0}),n.prototype[v]=function(){t.prototype[v].call(this),this.N=void 0},n}(wt);function Ot(t){return t.settable}function jt(t){return"function"==typeof t?t():at(t)}function mt(){var t=this.getState();return t===O||t instanceof z?void 0:t}function gt(t){return this.set(t)}function _t(t){return t instanceof ot}var St=B.wrap(O);function kt(t){return new ft(t)}function Et(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new dt(t,n.length?n:void 0)}function Rt(t){return kt.final(t)}function At(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new yt(t,n.length?n:void 0)}function Tt(t){var n=this,i=M.plucker,r=i.get,e=i.set,o=this;return _t(t)?At({get:function(){return r.call(this,o.get(),t.get())},set:function(n){o.set(e.call(this,n,o.value,t.get()))}}):o.map((function(i){return r.call(n,i,t)}),(function(i){return e.call(n,i,o.value,t)}))}function Ct(){this.set(O)}function xt(t){this.set(new z(t))}function Dt(t){this.set(B.wrap(t))}function Ft(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];this.set(t.apply(void 0,e([this.value],n.map(lt),!1)))}!function(t){function n(t){return new ft(B.wrap(t))}t.unresolved=function(){return new ft(O)},t.error=function(t){return new ft(new z(t))},t.final=n,function(t){t.unresolved=function(){return new ft(St)},t.error=function(t){return new ft(B.wrap(new z(t)))}}(n=t.final||(t.final={}))}(kt||(kt={})),function(t){t.unresolved=function(){return kt.final.unresolved()},t.error=function(t){return kt.final.error(t)}}(Rt||(Rt={}));var It=new ft(B.wrap(!0)),Mt=new ft(B.wrap(!1)),Vt=Symbol("skipped"),qt=B.wrap(Vt);function zt(t,n,i,r){if(void 0!==t){var e=t?It:Mt;if(!function(t,n){return t===n||t instanceof ft&&t.g instanceof B&&t.g.value===n}(t,i)){if("function"==typeof t){var o=t;t=new dt((function(){return o(n)})).derive(at)}return _t(t)?void 0!==r?t.mapState((function(t){return t===r?B.wrap(t):t})):t:e}}}function Bt(t){var n=B.unwrap(t);return n!==O&&!(n instanceof z)}Object.defineProperties(ot.prototype,{get:{value:function(){var t=this.getState();if(t instanceof z)throw t.error;if(t!==O)return t;if(bt>0)throw O;throw G(Error("Could not get value, derivable is unresolved"),this)}},getOr:{value:function(t){var n=this.getState();if(n instanceof z)throw n.error;return n===O?jt(t):n}},value:{get:mt},resolved:{get:function(){return this.getState()!==O}},settable:{value:!1},final:{get:function(){return this.getMaybeFinalState()instanceof B}},errored:{get:function(){return this.getState()instanceof z}},error:{get:function(){var t=this.getState();return t instanceof z?t.error:void 0}},connected$:{get:function(){return this.m||(this.m=new ft(this.connected))}},derive:{value:function(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new dt(t,e([this],n,!0))}},map:{value:function(t,n){var i=function(n){return n===O||n instanceof z?n:t.call(this,n)};return n&&Ot(this)?new pt(this,i,(function(t){return t===O||t instanceof z?t:n.call(this,t,this.q.value)})):new wt(this,i)}},mapState:{value:function(t,n){return n&&Ot(this)?new pt(this,t,(function(t){return n.call(this,t,this.q.getState())})):new wt(this,t)}},flatMap:{value:function(t){return this.map(t).derive((function(t){return t.getState()}))}},pluck:{value:function(t){var n=this,i=M.plucker.get;return _t(t)?this.derive(i,t):this.map((function(r){return i.call(n,r,t)}))}},fallbackTo:{value:function(t){var n=this;return _t(t)?Et((function(){return n.getOr(t)})):this.mapState((function(n){return n===O?jt(t):n}))}},take:{value:function(t){var n=this,i=t.from,r=t.when,e=t.until,o=t.once,u=t.stopOnError,s=t.skipFirst,c=zt(i,this,!0,!0),f=zt(r,this,!0),h=zt(e,this,!1,!0),a=s?new ft(O):void 0;if(!(c||f||h||o||u||a))return this;var l=(h||f)&&new ft(O);function v(t){return l&&l.set(t),t}return new dt((function(){if(c&&!c.get())return O;if(h&&h.get())return v(B.wrap(l.g));if(f&&!f.getOr(!1))return l.g;var t=n.getMaybeFinalState();if(a&&!qt.equals(a.g)){if(!Bt(t))return v(t);if(a.g===O||q(t,a.g))return a.set(t),v(O);a.set(qt)}return v(o&&Bt(t)||u&&t instanceof z?B.wrap(t):t)}))}},and:{value:function(t){return _t(t)?this.derive((function(n){return n&&t.get()})):this.map((function(n){return n&&t}))}},or:{value:function(t){return _t(t)?this.derive((function(n){return n||t.get()})):this.map((function(n){return n||t}))}},not:{value:function(){return this.map((function(t){return!t}))}},is:{value:function(t){return _t(t)?this.derive(q,t):this.map((function(n){return q(n,t)}))}}}),[ft,ht,pt,yt].forEach((function(t){return Object.defineProperties(t.prototype,{value:{get:mt,set:gt},swap:{value:Ft},pluck:{value:Tt}})})),[ft,pt].forEach((function(t){return Object.defineProperties(t.prototype,{unset:{value:Ct},setError:{value:xt},setFinal:{value:Dt}})})),Object.defineProperties(yt.prototype,{settable:{value:!0}}),ot.prototype.react=function(t,n){var i=this;return Z((function(){return Nt.create(i,t,n)}))},ot.prototype.toPromise=function(t){var n=this;return new Promise((function(i,e){return n.react(i,r(r({},t),{once:!0,onError:function(t,n){n(),e(t)}}))}))};var Gt,Nt=function(){function t(t,n,i,r){this.P=t,this.U=n,this.L=i,this.ended=r,this.$=!1,this.id=K(),this.H=0,this.creationStack=P(this),this.J=l}return t.prototype.K=function(){it(this.P,this),this.$=!0,this.o()},t.prototype.o=function(){var t=this;if(this.$){var n=function(n){return function(){n===O||q(t.J,n)||(t.J=n,n instanceof z?t.U(n.error):t.W(n))}},i=this.P[b]();i instanceof B?this.X(n(i.value)):n(i)()}},t.prototype.W=function(t){var n=this;this.H++;try{if(this.H>100)throw Error("Too deeply nested synchronous cyclical reactions disallowed. Use setImmediate.");this.L(t,(function(){return n.X()}))}catch(t){this.U(G(t,this))}finally{this.H--}},t.prototype.X=function(t){this.$&&(this.$=!1,rt(this.P,this),t&&t(),this.ended&&this.ended())},t.prototype[d]=function(t){t.indexOf(this)<0&&t.push(this)},t.create=function(n,i,r,e){var o=new t(r?n.take(r):n,(function(t){if(!r||!r.onError)throw u(),t;r.onError(t,u)}),i,e);function u(){o.X()}return o.K(),u},t}(),Pt=Object.freeze({__proto__:null,symbols:j,Atom:ft,BaseDerivable:ot,BaseDerivation:vt,Derivation:dt,Lens:yt,resolveFallback:jt,safeUnwrap:lt,Reactor:Nt,isRecordingObservations:X,addObserver:it,allDependenciesAreFinal:Y,independentTracking:Z,markFinal:tt,maybeDisconnectInNextTick:et,recordObservation:nt,removeObserver:rt,startRecordingObservations:Q,stopRecordingObservations:W,processChangedState:S,augmentStack:G,isError:x}),Ut={clone:I,equals:q,isPlainObject:function(t){if("object"!=typeof t||null==t)return!1;var n=Object.getPrototypeOf(t);return n===Object.prototype||null===n||t.constructor===Object},resolveFallback:jt};(Gt="undefined"!=typeof window?window:global)[p]?(Gt[p]++,console.warn(Gt[p]+" instances of Sherlock detected. This could cause unexpected results.")):Gt[p]=1,t.ErrorWrapper=z,t.FinalWrapper=B,t.PullDataSource=ht,t._internal=Pt,t.atom=kt,t.atomic=T,t.atomically=A,t.config=M,t.constant=Rt,t.derive=Et,t.inTransaction=m,t.isDerivable=_t,t.isDerivableAtom=function t(n){return n instanceof ft&&n.settable||n instanceof pt&&t(n.q)},t.isSettableDerivable=function(t){return _t(t)&&t.settable},t.lens=At,t.safeUnwrap=lt,t.transact=R,t.transaction=function t(n){return n?function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];var r=this;return R((function(){return n.apply(r,t)}))}:function(n,i,r){r.value=r.value&&t(r.value)}},t.unresolved=O,t.unwrap=at,t.utils=Ut,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=sherlock.umd.min.js.map

@@ -5,4 +5,4 @@ import { MaybeFinalState } from '../interfaces';

}
export declare function augmentStack(err: Error, obj: ObjectWithCreationStack): any;
export declare function augmentStack(err: Error, obj: ObjectWithCreationStack): Error;
export declare function augmentState<V>(state: MaybeFinalState<V>, obj: ObjectWithCreationStack): MaybeFinalState<V>;
export declare function prepareCreationStack(obj: object): string | undefined;
export * from './augment-stack';
export * from './clone';
export * from './config';
export * from './is-error';
export * from './equals';

@@ -5,0 +6,0 @@ export * from './error-wrapper';

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc