UNPKG

@ghostry/finity-reactjs

Version:

Finite state management with exhaustiveness and transition enforcement for TypeScript.

3 lines 14.7 kB
/*! For license information please see index.js.LICENSE.txt */ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,function(){return function(){"use strict";var t={"../../node_modules/react/cjs/react.production.js":function(t,e){var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),o=(Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy")),i=Symbol.iterator,u={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},a=Object.assign,c={};function f(t,e,r){this.props=t,this.context=e,this.refs=c,this.updater=r||u}function l(){}function s(t,e,r){this.props=t,this.context=e,this.refs=c,this.updater=r||u}f.prototype.isReactComponent={},f.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},f.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},l.prototype=f.prototype;var y=s.prototype=new l;y.constructor=s,a(y,f.prototype),y.isPureReactComponent=!0;var p=Array.isArray,b=null;Object.prototype.hasOwnProperty;var d=/\/+/g;function v(t,e){var r,n;return"object"==typeof t&&null!==t&&null!=t.key?(r=""+t.key,n={"=":"=0",":":"=2"},"$"+r.replace(/[=:]/g,function(t){return n[t]})):e.toString(36)}function m(){}"function"==typeof reportError&&reportError;e.useEffect=function(t,e,r){if("function"==typeof r)throw Error("useEffect CRUD overload is not enabled in this build of React.");return b.useEffect(t,e)},e.useMemo=function(t,e){return b.useMemo(t,e)},e.useState=function(t){return b.useState(t)}},"../../node_modules/react/index.js":function(t,e,r){t.exports=r("../../node_modules/react/cjs/react.production.js")}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return!function(){r.r(n),r.d(n,{initialize:function(){return E}});var t=function(t){return{name:t,transitions:function(e){return{name:t,transitions:e}}}};function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r,n,o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i=[],u=!0,a=!1;try{for(o=o.call(t);!(u=(r=o.next()).done)&&(i.push(r.value),!e||i.length!==e);u=!0);}catch(t){a=!0,n=t}finally{try{u||null==o.return||o.return()}finally{if(a)throw n}}return i}}(t,e)||u(t,e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,r){if(t){if("string"==typeof t)return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);if("Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(t,r)}}var a=function t(r,n){var a=this;if(!(this instanceof t))throw TypeError("Cannot call a class as a function");o(this,"state",void 0),o(this,"cases",void 0),o(this,"case",void 0),o(this,"use",void 0),this.state=r,this.cases=n,this.case=function(t,r){var n;return a.cases=((function(t){if(Array.isArray(t))return e(t)})(n=a.cases)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(n)||u(n)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).concat([[t,r]]),a},this.use=function(){var t=a.state(),e=a.cases.find(function(e){var r=i(e,2),n=r[0];return r[1],n.includes(t.kind)});if(e){var r=i(e,2);return(r[0],r[1])(t)}throw Error("[finity] Invalid state switch!")}};function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function f(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){var n;n=r[e],e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n})}return t}function l(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):(function(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r.push.apply(r,n)}return r})(Object(e)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}var s=function(e){var r=function(t){var r,n=function(t){if(Array.isArray(t))return t}(r=e.useState(function(){return t instanceof Function?t():t}))||function(t,e){var r,n,o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i=[],u=!0,a=!1;try{for(o=o.call(t);!(u=(r=o.next()).done)&&(i.push(r.value),2!==i.length);u=!0);}catch(t){a=!0,n=t}finally{try{u||null==o.return||o.return()}finally{if(a)throw n}}return i}}(r,0)||function(t,e){if(t){if("string"==typeof t)return c(t,2);var r=Object.prototype.toString.call(t).slice(8,-1);if("Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return c(t,2)}}(r,0)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),o=n[0],i=n[1];return{value:o,set:function(t){return i(function(e){return t})},update:function(t){return i(function(e){return t(e)})}}},n=function(t,e){var n=r(e);return l(f({},n),{value:function(){return l(f({},n.value()),{transition:function(e){var r=n.value().kind,o=e.kind;if(t.transitions[r].includes(o))n.set(e);else throw Error("[finity] Invalid state transition!")}})}})},o=function(t,e){var r=n(t,e);return function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){var n;n=r[e],e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n})}return t}({},(r.set,r.update,function(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||(o[r]=t[r]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)r=i[n],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}(r,["set","update"])))};return{defineTransitionalState:t,useState:r,useTransitionalState:n,useStrictlyTransitionalState:o,useEffect:function(t){return new a(t,[])}}},y=r("../../node_modules/react/index.js");function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function b(t){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function d(t,e){return(d=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function v(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r,n,o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i=[],u=!0,a=!1;try{for(o=o.call(t);!(u=(r=o.next()).done)&&(i.push(r.value),!e||i.length!==e);u=!0);}catch(t){a=!0,n=t}finally{try{u||null==o.return||o.return()}finally{if(a)throw n}}return i}}(t,e)||function(t,e){if(t){if("string"==typeof t)return p(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);if("Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return p(t,e)}}(t,e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(m=function(){return!!t})()}var h=function(t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");function e(){var t,r,n,o,i;if(!(this instanceof e))throw TypeError("Cannot call a class as a function");return r=e,n=arguments,r=b(r),o=t=function(t,e){var r;if(e&&("object"==((r=e)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof e))return e;if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(this,m()?Reflect.construct(r,n||[],b(this).constructor):r.apply(this,n)),i=function(){y.useEffect(function(){var e=t.state(),r=t.cases.find(function(t){var r=v(t,2),n=r[0];return r[1],n.includes(e.kind)});if(r){var n=v(r,2);(n[0],n[1])(e)}},[t.state()])},"use"in o?Object.defineProperty(o,"use",{value:i,enumerable:!0,configurable:!0,writable:!0}):o.use=i,t}return e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&d(e,t),e}(a);function O(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function S(t,e){return(S=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function g(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r,n,o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i=[],u=!0,a=!1;try{for(o=o.call(t);!(u=(r=o.next()).done)&&(i.push(r.value),!e||i.length!==e);u=!0);}catch(t){a=!0,n=t}finally{try{u||null==o.return||o.return()}finally{if(a)throw n}}return i}}(t,e)||function(t,e){if(t){if("string"==typeof t)return O(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);if("Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return O(t,e)}}(t,e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(w=function(){return!!t})()}var P=function(t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");function e(){var t,r,n,o,i;if(!(this instanceof e))throw TypeError("Cannot call a class as a function");return r=e,n=arguments,r=j(r),o=t=function(t,e){var r;if(e&&("object"==((r=e)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof e))return e;if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(this,w()?Reflect.construct(r,n||[],j(this).constructor):r.apply(this,n)),i=function(){var e=t.state(),r=y.useMemo(function(){return t.cases.find(function(t){var r=g(t,2),n=r[0];return r[1],n.includes(e.kind)})},[e]);if(r){var n=g(r,2);return(n[0],n[1])(e)}throw Error("[finity] Invalid state switch!")},"use"in o?Object.defineProperty(o,"use",{value:i,enumerable:!0,configurable:!0,writable:!0}):o.use=i,t}return e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&S(e,t),e}(a);function A(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var E=function(t){var e,r;return e=function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){var n;n=r[e],e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n})}return t}({},s({useState:function(t){var e,r=(e=y.useState(t),function(t){if(Array.isArray(t))return t}(e)||function(t,e){var r,n,o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i=[],u=!0,a=!1;try{for(o=o.call(t);!(u=(r=o.next()).done)&&(i.push(r.value),i.length!==e);u=!0);}catch(t){a=!0,n=t}finally{try{u||null==o.return||o.return()}finally{if(a)throw n}}return i}}(e,2)||function(t,e){if(t){if("string"==typeof t)return A(t,2);var r=Object.prototype.toString.call(t).slice(8,-1);if("Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return A(t,e)}}(e,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),n=r[0],o=r[1];return[function(){return n},function(t){return o(t),t}]}})),r=r={useEffect:function(t){return new h(t,[])},useRender:function(t){return new P(t,[])}},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):(function(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r.push.apply(r,n)}return r})(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}),e}}(),n}()}); //# sourceMappingURL=index.js.map