abon
Version:
Flexible state management for React 🚀
3 lines (2 loc) • 41.2 kB
JavaScript
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var r=t(require("lodash/isEqual")),e=t(require("react")),n=require("use-cleared-memo"),i=require("use-safe-force-update"),o=t(require("lodash/merge")),u=t(require("lodash/set")),s=t(require("lodash/get")),c=t(require("lodash/uniqBy"));function a(t,r,e,n,i,o,u){try{var s=t[o](u),c=s.value}catch(t){return void e(t)}s.done?r(c):Promise.resolve(c).then(n,i)}function f(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var o=t.apply(r,e);function u(t){a(o,n,i,u,s,"next",t)}function s(t){a(o,n,i,u,s,"throw",t)}u(void 0)}))}}function h(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function l(t,r,e){return r&&h(t.prototype,r),e&&h(t,e),t}function p(){return(p=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function y(t,r){t.prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r}function d(t){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function v(t,r){return(v=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function b(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function g(t,r,e){return(g=b()?Reflect.construct:function(t,r,e){var n=[null];n.push.apply(n,r);var i=new(Function.bind.apply(t,n));return e&&v(i,e.prototype),i}).apply(null,arguments)}function m(t){var r="function"==typeof Map?new Map:void 0;return(m=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return g(t,arguments,d(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),v(e,t)})(t)}function w(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function A(t,r,i,o,u){void 0===u&&(u=[]);var s=e.useRef(t);return n.useClearedMemo((function(){var t=r();return s.current!==t&&(s.current=t,i()),o((function(t){s.current=t,i()}))}),(function(t){return t()}),u),s}function _(t){if("function"!=typeof t)throw new Error('The listener must be a function, got "'+String(t)+'".')}function x(t,r){return _(t),"function"==typeof(e=r(t))?e:Array.isArray(e)?function(){return Array.from(e).forEach((function(t){return"function"==typeof t&&t()}))}:function(){};var e}function k(t,r,e){var n;_(t);var i=E((function(){"function"==typeof n&&n(),n=r(t)}),e);return function(){"function"==typeof i&&(i(),i=void 0),"function"==typeof n&&(n(),n=void 0)}}function S(t,r,e){var n;_(t);var i=E((function(){"function"==typeof n&&n(),n=x(t,r)}),e);return function(){"function"==typeof i&&(i(),i=void 0),"function"==typeof n&&(n(),n=void 0)}}function E(t,r){return _(t),t(),x(t,r)}function M(t,r,e){var n;_(t);var i=E((function(){"function"==typeof n&&n(),n=x(t,r),t()}),e);return function(){"function"==typeof i&&(i(),i=void 0),"function"==typeof n&&(n(),n=void 0)}}var C,j=Symbol("INITIAL"),O=function(t){function r(){return t.apply(this,arguments)||this}y(r,t);var e=r.prototype;return e.subscribe=function(t){var r=this;return this.add(t),function(){return r.unsubscribe(t)}},e.unsubscribe=function(t){this.delete(t)},e.notify=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return Array.from(this.values()).forEach((function(t){return t.apply(void 0,r)})),this},r.get=function(t){return t[R]},r.define=function(t){return Object.defineProperty(t,R,{value:new r,configurable:!1,writable:!1,enumerable:!1}),t},r}(m(Set)),R="__notifier",I=function(){function t(){O.define(this)}var r=t.prototype;return r.subscribe=function(t){return _(t),O.get(this).subscribe(t)},r.handle=function(t){return _(t),t(this.current),this.subscribe(t)},r.use=function(){var t=this,r=i.useSafeForceUpdate();return A(this.current,(function(){return t.current}),r,(function(r){return t.subscribe(r)}),[this,r]),this},r.useSubscription=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.subscribe(t)}),(function(t){return t()}),[this].concat(r))},r.useHandler=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.handle(t)}),(function(t){return t()}),[this].concat(r))},t}(),K=function(t){function i(r){var e;return(e=t.call(this)||this).current=r,e}y(i,t);var o=i.prototype;return o.set=function(t){return r(this.current,t)||(this.current=t,O.get(this).notify(t)),this},o.notify=function(){O.get(this).notify(this.current)},i.use=function(t,r){return void 0===r&&(r=[]),i.useRef(t,r).use()},i.useRef=function(t,r){return void 0===r&&(r=[]),e.useMemo((function(){return new i("function"==typeof t?t():void 0)}),r)},i.from=function(t,r,e){var n=new i(t()),o=x((function(){n.set(t())}),r);return e&&(e instanceof Set?e.add(o):e(o)),n},i.useFrom=function(t,r,e){void 0===e&&(e=[]);var o=i.use(r);return n.useClearedMemo((function(){return t(o.set.bind(o))}),(function(t){return t()}),[this].concat(e)),o},i}(I),L=function(t){function o(r){var e;return void 0===r&&(r=[]),e=t.call.apply(t,[this].concat(Array.from(r)))||this,O.define(w(e)),e}y(o,t);var u=o.prototype;return u.set=function(t){return t&&Array.isArray(t)||(t=[]),r(this.current,t)||(this.current=t,O.get(this).notify(t)),this},u.delete=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this.set(this.filter((function(t){return!r.includes(t)})))},u.push=function(){for(var r,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return(r=t.prototype.push).call.apply(r,[this].concat(n)),this.notify(),this.length},u.unshift=function(){for(var r,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return(r=t.prototype.unshift).call.apply(r,[this].concat(n)),this.notify(),this.length},u.pop=function(){if(this.length>0){var r=t.prototype.pop.call(this);return this.notify(),r}},u.shift=function(){if(this.length>0){var r=t.prototype.shift.call(this);return this.notify(),r}},u.reverse=function(){return this.set(this.current.reverse()),this},u.splice=function(t,r){var e=this.current,n=e.splice(t,r);return this.set(e),n},u.fill=function(t,r,e){return this.set(this.current.fill(t,r,e)),this},u.map=function(t){return this.current.map(t)},u.sort=function(t){return this.set(this.current.sort(t))},u.filter=function(t){return this.current.filter(t)},u.subscribe=function(t){return _(t),O.get(this).subscribe(t)},u.handle=function(t){return _(t),t(this.current),this.subscribe(t)},u.use=function(){var t=this,r=i.useSafeForceUpdate();return A(this.current,(function(){return t.current}),r,(function(r){return t.subscribe(r)}),[this,r]),this},u.useSubscription=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.subscribe(t)}),(function(t){return t()}),[this].concat(r))},u.notify=function(){O.get(this).notify(this.current)},o.use=function(t,r){return void 0===r&&(r=[]),o.useRef(t,r).use()},o.useRef=function(t,r){return void 0===r&&(r=[]),e.useMemo((function(){return new o("function"==typeof t?t():void 0)}),r)},l(o,[{key:"current",get:function(){return Array.from(this)},set:function(r){var e;t.prototype.splice.call(this,0),(e=t.prototype.push).call.apply(e,[this].concat(r))}},{key:"readonly",get:function(){return this}}]),o}(m(Array)),F=(function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",u=n.toStringTag||"@@toStringTag";function s(t,r,e,n){var i=Object.create((r&&r.prototype instanceof f?r:f).prototype),o=new _(n||[]);return i._invoke=function(t,r,e){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(e.method=i,e.arg=o;;){var u=e.delegate;if(u){var s=m(u,e);if(s){if(s===a)continue;return s}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var f=c(t,r,e);if("normal"===f.type){if(n=e.done?"completed":"suspendedYield",f.arg===a)continue;return{value:f.arg,done:e.done}}"throw"===f.type&&(n="completed",e.method="throw",e.arg=f.arg)}}}(t,e,o),i}function c(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var a={};function f(){}function h(){}function l(){}var p={};p[i]=function(){return this};var y=Object.getPrototypeOf,d=y&&y(y(x([])));d&&d!==r&&e.call(d,i)&&(p=d);var v=l.prototype=f.prototype=Object.create(p);function b(t){["next","throw","return"].forEach((function(r){t[r]=function(t){return this._invoke(r,t)}}))}function g(t,r){var n;this._invoke=function(i,o){function u(){return new r((function(n,u){!function n(i,o,u,s){var a=c(t[i],t,o);if("throw"!==a.type){var f=a.arg,h=f.value;return h&&"object"==typeof h&&e.call(h,"__await")?r.resolve(h.__await).then((function(t){n("next",t,u,s)}),(function(t){n("throw",t,u,s)})):r.resolve(h).then((function(t){f.value=t,u(f)}),(function(t){return n("throw",t,u,s)}))}s(a.arg)}(i,o,n,u)}))}return n=n?n.then(u,u):u()}}function m(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,m(t,r),"throw"===r.method))return a;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return a}var n=c(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,a;var i=n.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,a):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,a)}function w(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function A(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function x(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return h.prototype=v.constructor=l,l.constructor=h,l[u]=h.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===h||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,u in t||(t[u]="GeneratorFunction")),t.prototype=Object.create(v),t},t.awrap=function(t){return{__await:t}},b(g.prototype),g.prototype[o]=function(){return this},t.AsyncIterator=g,t.async=function(r,e,n,i,o){void 0===o&&(o=Promise);var u=new g(s(r,e,n,i),o);return t.isGeneratorFunction(e)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},b(v),v[u]="Generator",v[i]=function(){return this},v.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=x,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(A),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return u.type="throw",u.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=e.call(o,"catchLoc"),c=e.call(o,"finallyLoc");if(s&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&e.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=r,o?(this.method="next",this.next=o.finallyLoc,a):this.complete(u)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),a},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),A(e),a}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var i=n.arg;A(e)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:x(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),a}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}}(C={exports:{}}),C.exports),P=function(){function t(t){this.current=t,O.define(this),Object.defineProperty(this,"__promiseNotifier",{value:new O,configurable:!1,writable:!1,enumerable:!1})}var o=t.prototype;return o.set=function(){var t=f(F.mark((function t(e,n){var i,o,u=this;return F.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||!e.then){t.next=4;break}return i=Symbol(),this.__dispatchId=i,t.abrupt("return",e.then((function(t){if(u.__dispatchId===i)if(delete u.__dispatchId,u.__previousDispatchId=i,r(u.current,t))u.__promiseNotifier.notify(void 0);else if(u.current=t,O.get(u).notify(t),u.__promiseNotifier.notify(void 0),"function"==typeof n)return Promise.resolve(n()).then((function(){return u}));return u})));case 4:return delete this.__dispatchId,r(this.current,o=e)||(this.current=o,O.get(this).notify(o)),this.__promiseNotifier.notify(void 0),t.abrupt("return",this);case 9:case"end":return t.stop()}}),t,this)})));return function(r,e){return t.apply(this,arguments)}}(),o.dispatch=function(){var t=f(F.mark((function t(r,e){var n,i,o;return F.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return(i=Boolean(this.__dispatchId))?n=this.__dispatchId:(n=Symbol(),this.__dispatchId=n),t.next=4,r;case 4:if(o=t.sent,this.__dispatchId!==n&&(this.__dispatchId||this.__previousDispatchId!==n)){t.next=10;break}if(i||(delete this.__dispatchId,this.__previousDispatchId=n,this.__promiseNotifier.notify(void 0)),"function"!=typeof e){t.next=10;break}return t.next=10,e(o);case 10:return t.abrupt("return",this);case 11:case"end":return t.stop()}}),t,this)})));return function(r,e){return t.apply(this,arguments)}}(),o.subscribe=function(t){return _(t),O.get(this).subscribe(t)},o.handle=function(t){return _(t),t(this.current),this.subscribe(t)},o.use=function(){var t=this,r=i.useSafeForceUpdate();return A(this.current,(function(){return t.current}),r,(function(r){return t.subscribe(r)}),[this,r]),this},o.useSubscription=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.subscribe(t)}),(function(t){return t()}),[this].concat(r))},o.useHandler=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.handle(t)}),(function(t){return t()}),[this].concat(r))},o.notify=function(){O.get(this).notify(this.current)},t.use=function(t,r){return void 0===r&&(r=[]),this.useRef(t,r).use()},t.useRef=function(r,n){return void 0===n&&(n=[]),e.useMemo((function(){return new t("function"==typeof r?r():void 0)}),n)},l(t,[{key:"promise",get:function(){var t=this;return new Promise((function(r){if(!t.__dispatchId)return r(t.current);var e=t.__promiseNotifier.subscribe((function(){e(),r(t.current)}))}))}}]),t}(),N=function(t){function e(e,n){var i;return(i=t.call(this)||this).current=e(),i.__unsubscriber=x((function(t){void 0===t&&(t=e()),r(i.current,t)||(i.current=t,O.get(w(i)).notify(t))}),n),i}return y(e,t),e.prototype.unsubscribe=function(){"function"==typeof this.__unsubscriber&&(this.__unsubscriber(),delete this.__unsubscriber)},e}(I),V=function(t){function e(r,e){var n;return(n=t.call(this)||this).current=r(),n.getter=r,n.subscriber=e,n}y(e,t);var n=e.prototype;return n.set=function(t){void 0===t&&(t=this.getter()),r(this.current,t)||(this.current=t,O.get(this).notify(t))},n.setGetter=function(t){this.getter=t,this.set(t())},n.setSubscriber=function(t){this.subscriber=t,this.hydrateSubscriber()},n.hydrateSubscriber=function(){this.unsubscribe(),this.__unsubscriber=x(this.set.bind(this),this.subscriber)},n.unsubscribe=function(){"function"==typeof this.__unsubscriber&&(this.__unsubscriber(),delete this.__unsubscriber)},e}(I),H=function(t){function e(){return t.apply(this,arguments)||this}y(e,t);var n=e.prototype;return n.getNotifier=function(r){var e=this.key(r);if(t.prototype.has.call(this,e))return{notifier:t.prototype.get.call(this,e),key:e};var n=new O;return t.prototype.set.call(this,e,n),{notifier:n,key:r}},n.subscribe=function(r,e){var n=this,i=this.getNotifier(r),o=i.notifier,u=i.key;return o.add(e),function(){o.delete(e),o&&!o.size&&t.prototype.delete.call(n,u)}},n.key=function(t){return Array.from(this.keys()).find((function(e){return e.length===t.length&&r(t,e)}))||t},n.has=function(r){return t.prototype.has.call(this,this.key(r))},n.get=function(r){return t.prototype.get.call(this,this.key(r))},n.getRelated=function(e){var n=this;if(!e.length)return this;for(var i=new Map,o=0;o<e.length;o++){var u=this.key(e.slice(0,o));t.prototype.has.call(this,u)&&i.set(u,t.prototype.get.call(this,u))}var s=this.key(e);return t.prototype.has.call(this,s)&&i.set(s,t.prototype.get.call(this,s)),Array.from(this.keys()).forEach((function(o){o.length>e.length&&r(o.slice(0,e.length),e)&&i.set(o,t.prototype.get.call(n,o))})),i},n.clear=function(){Array.from(this.values()).forEach((function(t){t.clear()})),t.prototype.clear.call(this)},n.notify=function(t){var r=this.get(t);if(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];r.notify.apply(r,n)}return this},e.get=function(t){return t[U]},e.define=function(t){return Object.defineProperty(t,U,{value:new e,configurable:!1,writable:!1,enumerable:!1}),t},e}(m(Map)),U="__notifier",q=function(){function t(){H.define(this)}var r=t.prototype;return r.get=function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];var i=t.parseKeyArgs(e);return i.length?t.get(this.current,i):this.current},r.subscribe=function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];var i=t.parseKeyValueArgs(e),o=i.keys,u=i.value;return _(u),H.get(this).subscribe(o,u)},r.handle=function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];var i=t.parseKeyValueArgs(e),o=i.keys,u=i.value;return _(u),u(this.get(o)),H.get(this).subscribe(o,u)},r.use=function(){for(var r=this,e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var u=t.parseKeyArgs(n),s=i.useSafeForceUpdate();if(u.length){var c=A(this.get(u),(function(){return r.get(u)}),s,(function(t){return r.subscribe(u,t)}),[this,s,H.get(this).key(u)]);return c.current}return A(this.current,(function(){return r.current}),s,(function(t){return r.subscribe(t)}),[this,s]),this},r.useSubscription=function(){for(var r=this,e=[],i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];Array.isArray(o[o.length-1])&&(e=o.pop());var s=t.parseKeyValueArgs(o),c=s.keys,a=s.value;return n.useClearedMemo((function(){return r.subscribe(c,a)}),(function(t){return t()}),[this,a,H.get(this).key(c)].concat(e)),this},r.useHandler=function(){for(var r=this,e=[],i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];Array.isArray(o[o.length-1])&&(e=o.pop());var s=t.parseKeyValueArgs(o),c=s.keys,a=s.value;return n.useClearedMemo((function(){return r.handle(c,a)}),(function(t){return t()}),[this,a,H.get(this).key(c)].concat(e)),this},t.parseKeyValueArgs=function(t){if(1===t.length)return{keys:[],value:t[0]};if(2===t.length&&Array.isArray(t[0]))return{keys:t[0],value:t[1]};var r=t.pop();return{keys:t,value:r}},t.parseKeyArgs=function(t){return 1===t.length&&Array.isArray(t[0])?t[0]:t},t.get=function(t,r,e){return s(t,r,e)},t}(),D=function(t){function n(r){var e;return(e=t.call(this)||this).current=r||{},e}y(n,t);var i=n.prototype;return i.set=function(){for(var t=this,e=arguments.length,i=new Array(e),u=0;u<e;u++)i[u]=arguments[u];var s,c=n.parseKeyValueArgs(i),a=c.keys,f=c.value;if(a.length){s=o({},this.current);var h=n.get(s,a);if(n.set(this.current,a,f),r(h,f))return}else if(s=this.current,this.current=f,r(s,this.current))return;var l=H.get(this).getRelated(a);return Array.from(l.entries()).forEach((function(e){var i=e[0],o=e[1];if(i.length){if(i.length===a.length&&r(i,a))return void o.notify(f)}else o.notify.apply(o,[t.current].concat(t.rootSubscriptionArgs));var u=n.get(s,i),c=n.get(t.current,i);r(u,c)||o.notify(c)})),this},i.notify=function(t){var r=this,e=H.get(this);if(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];t.length?i.length||i.unshift(this.get(t)):(i.length||i.unshift(this.get(t)),1===i.length&&i.push.apply(i,this.rootSubscriptionArgs)),e.notify.apply(e,[t].concat(i))}else Array.from(e.keys()).forEach((function(t){t.length?e.notify(t,r.get(t)):e.notify.apply(e,[t,r.current].concat(r.rootSubscriptionArgs))}));return this},n.set=function(t,r,e){return u(t,r,e)},n.use=function(t,r){return void 0===r&&(r=[]),this.useRef(t,r).use()},n.useRef=function(t,r){return void 0===r&&(r=[]),e.useMemo((function(){return new n("function"==typeof t?t():void 0)}),r)},l(n,[{key:"rootSubscriptionArgs",get:function(){return[]}}]),n}(q),G=function(){function t(){O.define(this)}var r=t.prototype;return r.subscribe=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];if(3===r.length){var n=r[0],i=r[1],o=r[2];return _(o),O.get(this).subscribe((function(t,r){return t===n&&r===i&&o()}))}if(2===r.length){var u=r[0],s=r[1];return _(s),O.get(this).subscribe((function(t,r){return t===u&&s(r)}))}var c=r[0];return _(c),O.get(this).subscribe(c)},r.use=function(){for(var t=this,r=arguments.length,e=new Array(r),i=0;i<r;i++)e[i]=arguments[i];var o=e[e.length-1],u=Array.isArray(o);n.useClearedMemo((function(){return t.subscribe.apply(t,u?e.slice(0,e.length-1):e)}),(function(t){return t()}),u?[this].concat(o):[this])},t}(),T=function(t){function r(){return t.apply(this,arguments)||this}return y(r,t),r.prototype.notify=function(t,r){var e=this;Array.isArray(r)?r.forEach((function(r){O.get(e).notify(t,r)})):O.get(this).notify(t,r)},r.use=function(t){return void 0===t&&(t=[]),e.useMemo((function(){return new r}),t)},r}(G),B=function(t){function n(){return t.apply(this,arguments)||this}y(n,t);var i=n.prototype;return i.set=function(t){return r(this.value.current,t)||(this.current=t,O.get(this).notify(t)),this},i.nest=function(){return new n(void 0,this)},i.notify=function(){O.get(this).notify(this.current)},n.use=function(t,r){return void 0===r&&(r=[]),this.useRef(t,r).use()},n.useRef=function(t,r){return void 0===r&&(r=[]),e.useMemo((function(){return new n("function"==typeof t?t():void 0)}),r)},l(n,[{key:"current",get:function(){var t=this.value.current;return void 0===t&&this.parent?this.parent.current:t},set:function(t){this.value.current=t}}]),n}(function(){function t(t,r){this.value=new K(t),this.parent=r,O.define(this)}var r=t.prototype;return r.subscribe=function(t){var r=this;return _(t),x((function(){return t(r.current)}),(function(t){return[O.get(r.value).subscribe(t),r.parent?O.get(r.parent).subscribe(t):void 0]}))},r.handle=function(t){return _(t),t(this.current),this.subscribe(t)},r.use=function(){var t=this,r=i.useSafeForceUpdate();return A(this.current,(function(){return t.current}),r,(function(r){return t.subscribe(r)}),[this,r]),this},r.useSubscription=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.subscribe(t)}),(function(t){return t()}),[this].concat(r))},r.useHandler=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.handle(t)}),(function(t){return t()}),[this].concat(r))},r.nest=function(){return new B(void 0,this)},l(t,[{key:"current",get:function(){var t=this.value.current;return void 0===t&&this.parent?this.parent.current:t}}]),t}()),W=function(t){function r(r){var e;return e=t.call(this,r)||this,O.define(w(e)),e}y(r,t);var o=r.prototype;return o.add=function(r,e){return!O.get(this)||e?t.prototype.add.call(this,r):(this.has(r)||(t.prototype.add.call(this,r),this.notify()),this)},o.delete=function(r,e){if(e)return t.prototype.delete.call(this,r);if(this.has(r)){var n=t.prototype.delete.call(this,r);return this.notify(),n}return!1},o.set=function(r,e){var n=this,i=!1,o=new Set(r||void 0);return Array.from(this.values()).forEach((function(r){o.has(r)||(t.prototype.delete.call(n,r),i=!0)})),Array.from(o.values()).forEach((function(r){t.prototype.has.call(n,r)||(t.prototype.add.call(n,r),i=!0)})),i&&!e&&this.notify(),i},o.modify=function(r,e,n){var i=this,o=!1;return r&&Array.from(r).forEach((function(r){i.has(r)||(t.prototype.add.call(i,r),o=!0)})),e&&Array.from(e).forEach((function(r){i.has(r)&&(t.prototype.delete.call(i,r),o=!0)})),o&&!n&&this.notify(),o},o.subscribe=function(t){return O.get(this).subscribe(t)},o.handle=function(t){return _(t),t(this),this.subscribe(t)},o.clear=function(r){t.prototype.clear.call(this),r||O.get(this).notify(this)},o.use=function(){var t=this,r=i.useSafeForceUpdate();return n.useClearedMemo((function(){return t.subscribe(r)}),(function(t){return t()}),[this,r]),this},o.useSubscription=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.subscribe(t)}),(function(t){return t()}),[this].concat(r))},o.useHandler=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.handle(t)}),(function(t){return t()}),[this].concat(r))},o.notify=function(){O.get(this).notify(this)},r.use=function(t,e){return void 0===e&&(e=[]),r.useRef(t,e).use()},r.useRef=function(t,n){return void 0===n&&(n=[]),e.useMemo((function(){return new r("function"==typeof t?t():void 0)}),n)},l(r,[{key:"readonly",get:function(){return this}}]),r}(m(Set)),Y=function(t){function n(){return t.apply(this,arguments)||this}y(n,t);var i=n.prototype;return i.set=function(t){return r(this.value.current,t)||(this.current=t,O.get(this).notify(t)),this},i.notify=function(){O.get(this).notify(this.current)},n.use=function(t){return void 0===t&&(t=[]),this.useRef(t).use()},n.useRef=function(t){return void 0===t&&(t=[]),e.useMemo((function(){return new n}),t)},l(n,[{key:"current",get:function(){var t=this.value.current;return void 0===t&&this.childValue.current?this.childValue.current:t},set:function(t){this.value.current=t}}]),n}(function(){function t(){var t=this;O.define(this),this.value=new K,this.children=new W,this.childValue=new K;var r,e=function(){var r=Array.from(t.children).find((function(t){return void 0!==t.current}));t.childValue.set(r?r.current:void 0)};this.children.subscribe((function(){"function"==typeof r&&r(),e(),r=x(e,(function(r){return Array.from(t.children).map((function(t){return t.subscribe(r)}))}))})),e()}var r=t.prototype;return r.subscribe=function(t){var r=this;return _(t),x((function(){return t(r.current)}),(function(t){return[O.get(r.value).subscribe(t),O.get(r.childValue).subscribe(t)]}))},r.handle=function(t){return _(t),t(this.current),this.subscribe(t)},r.addChild=function(t){return void 0===t&&(t=new K),this.children.add(t),t},r.removeChild=function(t){this.children.delete(t)},r.use=function(){var t=this,r=i.useSafeForceUpdate();return A(this.current,(function(){return t.current}),r,(function(r){return t.subscribe(r)}),[this,r]),this},r.useSubscription=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.subscribe(t)}),(function(t){return t()}),[this].concat(r))},r.useHandler=function(t,r){var e=this;void 0===r&&(r=[]),n.useClearedMemo((function(){return e.handle(t)}),(function(t){return t()}),[this].concat(r))},l(t,[{key:"current",get:function(){var t=this.value.current;return void 0===t&&this.childValue.current?this.childValue.current:t}}]),t}()),z=function(t,n){function i(r,e){var n;return(n=t.call(this,i.record(e||[],r))||this).idKey=r,n.ids=new L(i.ids(e||[],r)).readonly,n}y(i,t);var o=i.prototype;return o.set=function(){for(var e=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var s=D.parseKeyValueArgs(o),a=s.keys,f=s.value;if(a.length)return this.ids.current.includes(a[0])?(t.prototype.set.call(this,a,f),this):this;if(Array.isArray(f)){var h=f,l=h.findIndex((function(t){return!t||null==t[e.idKey]}));if(l>=0){var y="An invalid item was passed at index "+l+": \n\t["+h.map((function(t){return t&&null!=t[e.idKey]?String(t[e.idKey]):"null"})).join(", ")+"]";throw new Error(y)}var d=(h=c(h,(function(t){return t[e.idKey]}))).map((function(t){return t[e.idKey]})),v=i.record(h,this.idKey),b=!r(d,this.ids.current),g=b&&!r(v,this.current);this.internalIds.current=d,t.prototype.set.call(this,v),g&&this.notify([]),b&&this.internalIds.notify()}else{var m=f||{};Object.keys(m).forEach((function(t){e.ids.includes(t)||(m===f&&(m=p({},f)),delete m[t])})),t.prototype.set.call(this,m)}return this},o.delete=function(){for(var t=this,r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];var i=e.filter((function(t){return null!=t})).map((function(r){return"object"==typeof r?r[t.idKey]:r}));return this.set(this.filter((function(r){return!r||!i.includes(r[t.idKey])})))},o.push=function(){for(var t,r=this,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var o=this.array.findIndex((function(t){return!t||null==t[r.idKey]}));if(o>=0){var u="An invalid item exists at at index "+o+" (mismatch between ids and defined items). Was AbonItems.current or AbonItems.ids mutated incorrectly?\n\titems: ["+this.array.map((function(t){return t&&null!=t[r.idKey]?String(t[r.idKey]):"null"})).join(", ")+"]\n\tcurrent: {"+Object.keys(this.current).map((function(t){return" "+t+": {...} "})).join(",")+"}\n\tids: ["+this.ids.current.join(", ")+"]";throw new Error(u)}var s=(n=c(n,(function(t){return t[r.idKey]}))).map((function(t){return t[r.idKey]}));return this.set((t=this.ids.filter((function(t){return!s.includes(t)})).map((function(t){return r.current[t]}))).concat.apply(t,n)),this.length},o.unshift=function(){for(var t,r=this,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var o=this.array.findIndex((function(t){return!t||null==t[r.idKey]}));if(o>=0){var u="An invalid item exists at at index "+o+" (mismatch between ids and defined items). Was AbonItems.current or AbonItems.ids mutated incorrectly?\n\titems: ["+this.array.map((function(t){return t&&null!=t[r.idKey]?String(t[r.idKey]):"null"})).join(", ")+"]\n\tcurrent: {"+Object.keys(this.current).map((function(t){return" "+t+": {...} "})).join(",")+"}\n\tids: ["+this.ids.current.join(", ")+"]";throw new Error(u)}var s=(n=c(n,(function(t){return t[r.idKey]}))).map((function(t){return t[r.idKey]}));return this.set((t=n).concat.apply(t,this.ids.filter((function(t){return!s.includes(t)})).map((function(t){return r.current[t]})))),this.length},o.find=function(){var t;return(t=this.array).find.apply(t,arguments)},o.includes=function(t){return this.ids.includes(t&&"object"==typeof t?t[this.idKey]:t)},o.findIndex=function(t){return this.array.findIndex(t)},o.indexOf=function(t,r){return this.ids.indexOf(t&&"object"==typeof t?t[this.idKey]:t,r)},o.lastIndexOf=function(t,r){return this.array.lastIndexOf(t&&"object"==typeof t?t[this.idKey]:t,r)},o.every=function(t){return this.array.every(t)},o.some=function(t){return this.array.some(t)},o.forEach=function(t){this.array.forEach(t)},o.map=function(t){return this.array.map(t)},o.filter=function(t){return this.array.filter(t)},o.pop=function(){var t=this.ids[this.ids.current.length-1];if(null!=t){var r=this.get(t);return this.delete(t),r}},o.reverse=function(){return this.set(this.array.reverse()),this},o.values=function(){return this.array.values()},o[n]=function(){return this.array[Symbol.iterator]()},o.subscribe=function(){for(var r,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return(r=t.prototype.subscribe).call.apply(r,[this].concat(n))},o.get=function(){for(var r,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return(r=t.prototype.get).call.apply(r,[this].concat(n))},i.record=function(t,r){var e={};return t.forEach((function(t){e[t[r]]=t})),e},i.ids=function(t,r){return t.map((function(t){return t?t[r]:t}))},i.use=function(){return this.useRef.apply(this,arguments).use()},i.useRef=function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];var u;return"function"!=typeof n[0]&&n[0]?e.useMemo((function(){return new i(n[0],"function"==typeof n[1]?n[1]():void 0)}),(n[3]||[]).concat(n[0])):(u=t.useRef).call.apply(u,[this].concat(n))},l(i,[{key:"array",get:function(){var t=this;return this.ids.map((function(r){return t.current[r]}))}},{key:"length",get:function(){return this.ids.length}},{key:"rootSubscriptionArgs",get:function(){return[this.array,this.ids.current]}},{key:"internalIds",get:function(){return this.ids}},{key:"readonly",get:function(){return this}}]),i}(D,Symbol.iterator),J=function(t){function o(r){var e;return e=t.call(this,r)||this,H.define(w(e)),e}y(o,t);var u=o.prototype;return u.set=function(){for(var e=this,n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];if(2===i.length){var u=i[0],s=i[1];this.has(u)&&r(s,this.get(u))?t.prototype.set.call(this,u,s):(t.prototype.set.call(this,u,s),this.notify([u]))}else if(Array.isArray(i[0])){var c=new Map(i[0]),a=[],f=!1;Array.from(this.keys()).forEach((function(r){c.has(r)||(t.prototype.delete.call(e,r),f=!0)})),Array.from(c.keys()).forEach((function(n){e.has(n)&&r(c.get(n),e.get(n))||(t.prototype.set.call(e,n,c.get(n)),a.push(n))})),(a.length||f)&&this.notify(a)}else{var h=i[0];h||(h={});var l=[],p=!1;Array.from(this.keys()).forEach((function(r){void 0===h[r]&&(t.prototype.delete.call(e,r),p=!0)})),Object.keys(h).forEach((function(n){e.has(n)&&r(h[n],e.get(n))||(t.prototype.set.call(e,n,h[n]),l.push(n))})),(l.length||p)&&this.notify(l)}return this},u.patch=function(){var e=this;if(Array.isArray(arguments.length<=0?void 0:arguments[0])){var n=new Map(arguments.length<=0?void 0:arguments[0]),i=[];Array.from(n.keys()).forEach((function(o){e.has(o)&&r(n.get(o),e.get(o))||(t.prototype.set.call(e,o,n.get(o)),i.push(o))})),i.length&&this.notify(i)}else{var o=arguments.length<=0?void 0:arguments[0],u=[];Object.keys(o).forEach((function(n){e.has(n)&&r(o[n],e.get(n))||(t.prototype.set.call(e,n,o[n]),u.push(n))})),u.length&&this.notify(u)}return this},u.delete=function(r){return!!this.has(r)&&(t.prototype.delete.call(this,r),this.notify([r]),!0)},u.subscribe=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];var n=r.pop();return _(n),H.get(this).subscribe(r,n)},u.handle=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];var n=r.pop();return _(n),n(this),H.get(this).subscribe(r,n)},u.use=function(t){var r=this,e=i.useSafeForceUpdate();return A(null!=t?this.get(t):this,(function(){return null!=t?r.get(t):r}),e,(function(e){return null!=t?r.subscribe(t,e):r.subscribe(e)}),[this,t,e]),null!=t?this.get(t):this},u.useSubscription=function(){for(var t,r,e=this,i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];var s=o.pop();Array.isArray(s)?(t=s,r=o.pop()):(t=[],r=s),n.useClearedMemo((function(){return e.subscribe.apply(e,o.concat(r))}),(function(t){return t()}),[this,o[0]].concat(t))},u.useHandler=function(){for(var t,r,e=this,i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];var s=o.pop();Array.isArray(s)?(t=s,r=o.pop()):(t=[],r=s),n.useClearedMemo((function(){return e.handle.apply(e,o.concat(r))}),(function(t){return t()}),[this,o[0]].concat(t))},u.notify=function(t){var r=this,e=H.get(this);e.notify([],this),Array.from(this.keys()).forEach((function(n){t&&!t.includes(n)||e.notify([n],r.get(n))}))},u.clear=function(){t.prototype.clear.call(this),this.notify()},u.silentlySet=function(r,e){return t.prototype.set.call(this,r,e)},u.silentlyDelete=function(r){return t.prototype.delete.call(this,r)},o.use=function(t,r){return void 0===r&&(r=[]),this.useRef(t,r).use()},o.useRef=function(t,r){return void 0===r&&(r=[]),e.useMemo((function(){return new o("function"==typeof t?t():void 0)}),r)},l(o,[{key:"record",get:function(){var t={};return Array.from(this.entries()).forEach((function(r){t[r[0]]=r[1]})),t}},{key:"readonly",get:function(){return this}}]),o}(m(Map)),Q=function(t){function r(r){var e;return(e=t.call(this)||this).current=r,e}y(r,t);var i=r.prototype;return i.set=function(t){return this.current!==t&&(this.current=t,O.get(this).notify(t)),this},i.notify=function(){O.get(this).notify(this.current)},r.use=function(t,e){return void 0===e&&(e=[]),r.useRef(t,e).use()},r.useRef=function(t,n){return void 0===n&&(n=[]),e.useMemo((function(){return new r("function"==typeof t?t():void 0)}),n)},r.from=function(t,e,n){var i=new r(t()),o=x((function(){i.set(t())}),e);return n&&(n instanceof Set?n.add(o):n(o)),i},r.useFrom=function(t,e,i){void 0===i&&(i=[]);var o=r.use(e);return n.useClearedMemo((function(){return t(o.set.bind(o))}),(function(t){return t()}),[this].concat(i)),o},r}(I);exports.Abon=K,exports.AbonArray=L,exports.AbonAsync=P,exports.AbonComposed=N,exports.AbonComposedDynamic=V,exports.AbonDeep=D,exports.AbonEvent=T,exports.AbonInheritedDown=B,exports.AbonInheritedUp=Y,exports.AbonItems=z,exports.AbonMap=J,exports.AbonSet=W,exports.AbonStrict=Q,exports.Notifier=O,exports.ReadonlyAbon=I,exports.ReadonlyAbonDeep=q,exports.ReadonlyAbonEvent=G,exports.composedHandler=E,exports.composedSubscription=x,exports.default=K,exports.hydratedComposedHandler=M,exports.hydratedComposedSubscription=S,exports.hydratedSubscription=k,exports.resolve=function(t){var r,e;r="function"==typeof t.subscribe?t.subscribe.bind(t):t;var n=j,i=r((function(t){"function"==typeof i&&i(),n=t,e&&e(t)}));return{then:function(t,r){var i=j;t&&(n!==j?i=t(n):e=function(r){return t(r)});var o=new Promise((function(r){i!==j?r(i):n!==j?r(t?t(n):n):e=function(e){r(t?t(e):e)}}));return r&&(o=o.catch(r)),o}}},exports.useComposedHandler=function(t,r,e){void 0===e&&(e=[]),n.useClearedMemo((function(){return E(t,r)}),(function(t){return t()}),e)},exports.useComposedSubscription=function(t,r,e){void 0===e&&(e=[]),n.useClearedMemo((function(){return x(t,r)}),(function(t){return t()}),e)},exports.useComposedValue=function(t,o,u){void 0===u&&(u=[]);var s=i.useSafeForceUpdate(),c=e.useRef();return n.useClearedMemo((function(){return E((function(){var e=t();r(c.current,e)||(c.current=e,s())}),o)}),(function(t){return t()}),u),c.current},exports.useComposedValueAsync=function(t,o,u){void 0===u&&(u=[]);var s=i.useSafeForceUpdate(),c=e.useRef(),a=e.useRef();return n.useClearedMemo((function(){var e=a.current=Symbol();return t().then((function(t){a.current!==e||r(c,t)||(c.current=t,s())})),x((function(){var e=a.current=Symbol();t().then((function(t){a.current!==e||r(c,t)||(c.current=t,s())}))}),o)}),(function(t){return t()}),u),c.current},exports.useHydratedComposedHandler=function(t,r,e,i){void 0===i&&(i=[]),n.useClearedMemo((function(){return M(t,r,e)}),(function(t){return t()}),i)},exports.useHydratedComposedSubscription=function(t,r,e,i){void 0===i&&(i=[]),n.useClearedMemo((function(){return S(t,r,e)}),(function(t){return t()}),i)},exports.useHydratedComposedValue=function(t,o,u,s){void 0===s&&(s=[]);var c=i.useSafeForceUpdate(),a=e.useRef();return n.useClearedMemo((function(){return M((function(){var e=t();r(a.current,e)||(a.current=e,c())}),o,u)}),(function(t){return t()}),s),a.current},exports.useHydratedSubscription=function(t,r,e,i){void 0===i&&(i=[]),n.useClearedMemo((function(){return k(t,r,e)}),(function(t){return t()}),i)};
//# sourceMappingURL=abon.cjs.production.min.js.map