UNPKG

1.23 kBJavaScriptView Raw
1!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,o=(i=new WeakMap,function(e,t){var n=function(e,t){do{var n=t,r=n[0],i=n.slice(1),o=e.get(r);if(!o)return;if(!i.length)return o[1];e=o[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],o=r.slice(1),u=e.get(i);if(u||(u=[new WeakMap],e.set(i,u)),!o.length)return void(u[1]=n);e=u[0],t=o}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 o=n.useAtom(e,i),u=o[0],f=o[1];return[u,r.useCallback((function(e){return f(t.produce(e))}),[f])]},e.withImmer=function(e){return o((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})}));