UNPKG

@anew/hooks

Version:

AnewJS React Hooks

2 lines (1 loc) 2.71 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).Redux={},e.react)}(this,(function(e,t){"use strict";function n(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function r(e,t){if(n(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(var u=0;r.length>u;u++)if(!Object.prototype.hasOwnProperty.call(t,r[u])||!n(e[r[u]],t[r[u]]))return!1;return!0}var u=function(e){e()},i=function(){return u},c={notify:function(){}};var s=function(){function e(e){var t=this;this.store=e,this.unsubscribe=null,this.listeners=c,this.handleChangeWrapper=function(){t.onStateChange&&t.onStateChange()}}var t=e.prototype;return t.notifyNestedSubs=function(){this.listeners.notify()},t.isSubscribed=function(){return!!this.unsubscribe},t.trySubscribe=function(){this.unsubscribe||(this.unsubscribe=this.store.subscribe(this.handleChangeWrapper),this.listeners=function(){var e=i(),t=null,n=null;return{clear:function(){t=null,n=null},notify:function(){e((function(){for(var e=t;e;)e.callback(),e=e.next}))},get:function(){for(var e=[],n=t;n;)e.push(n),n=n.next;return e},subscribe:function(e){var r=!0,u=n={callback:e,next:null,prev:n};return u.prev?u.prev.next=u:t=u,function(){r&&null!==t&&(r=!1,u.next?u.next.prev=u.prev:n=u.prev,u.prev?u.prev.next=u.next:t=u.next)}}}}())},t.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.listeners&&this.listeners.clear&&this.listeners.clear(),this.listeners=c)},e}(),o=function(e,t){return e===t},f="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;e.createUseStoreState=function(e){function n(n,r){void 0===r&&(r=o);var u=function(e,n,r){var u,i=t.useReducer((function(e){return e+1}),0)[1],c=t.useMemo((function(){return new s(e)}),[e]),o=t.useRef(),a=t.useRef(),l=t.useRef(),b=t.useRef(),h=e.state;try{u=n!==a.current||h!==l.current||o.current?n(h):b.current}catch(e){throw o.current&&(e.message+="\nThe error may be correlated with this previous error:\n"+o.current.stack+"\n\n"),e}return f((function(){a.current=n,l.current=h,b.current=u,o.current=void 0})),f((function(){function t(){try{var t=a.current(e.state);if(r(t,b.current))return;b.current=t}catch(e){o.current=e}i()}return c.onStateChange=t,c.trySubscribe(),t(),function(){return c.tryUnsubscribe()}}),[e,c]),u}(e,n,r);return t.useDebugValue(u),u}return n.withSallowEqual=function(e){return n(e,r)},n},e.shallowEqual=r,Object.defineProperty(e,"__esModule",{value:!0})}));