UNPKG

malevic

Version:

Malevič.js - minimalistic reactive UI library

2 lines (1 loc) 1.35 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("malevic/dom")):"function"==typeof define&&define.amd?define(["exports","malevic/dom"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).Malevic=t.Malevic||{},t.Malevic.State={}),t.Malevic.DOM)}(this,(function(t,e){"use strict";var r=function(){return r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n=null;t.useState=function(t){if(!n)throw new Error("`useState()` should be called inside a component");return n(t)},t.withState=function(t){return function(o){for(var i=[],a=1;a<arguments.length;a++)i[a-1]=arguments[a];var s,l=e.getContext(),u=!0,f=n;n=function(t){if(!l)return{state:t,setState:null};var e=l.store,n=l.refresh;e.state=e.state||t;return{state:e.state,setState:function(t){if(u)throw new Error("Setting state during unboxing causes infinite loop");e.state=r(r({},e.state),t),n()}}};try{s=t.apply(void 0,function(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}([o],i,!1))}finally{n=f,u=!1}return s}}}));