UNPKG

jotai

Version:

👻 Next gen state management that will spook you

2 lines (1 loc) • 1.25 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("immer"),require("jotai"),require("react")):"function"==typeof define&&define.amd?define(["exports","immer","jotai","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jotaiImmer={},e.immer,e.jotai,e.React)}(this,(function(e,t,n,r){"use strict";var i,u=(i=new WeakMap,function(e,t){var n=function(e,t){do{var n=t,r=n[0],i=n.slice(1),u=e.get(r);if(!u)return;if(!i.length)return u[1];e=u[0],t=i}while(t.length)}(i,t);if(n)return n;var r=e();return function(e,t,n){do{var r=t,i=r[0],u=r.slice(1),o=e.get(i);if(o||(o=[new WeakMap],e.set(i,o)),!u.length)return void(o[1]=n);e=o[0],t=u}while(t.length)}(i,t,r),r});e.atomWithImmer=function(e){var r=n.atom(e,(function(e,n,i){return n(r,t.produce(e(r),"function"==typeof i?i:function(){return i}))}));return r},e.useImmerAtom=function(e,i){var u=n.useAtom(e,i),o=u[0],f=u[1];return[o,r.useCallback((function(e){return f(t.produce((function(t){return e(t)})))}),[f])]},e.withImmer=function(e){return u((function(){return n.atom((function(t){return t(e)}),(function(n,r,i){return r(e,t.produce(n(e),"function"==typeof i?i:function(){return i}))}))}),[e])},Object.defineProperty(e,"__esModule",{value:!0})}));