UNPKG

xstate

Version:

Finite State Machines and Statecharts for the Modern Web.

3 lines (2 loc) 1.52 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XStateGuards={})}(this,(function(e){"use strict";const t=e=>"#"===e[0];function n(e,n,{stateValue:r}){if("string"==typeof r&&t(r)){const t=e.machine.getStateNodeById(r);return e._nodes.some((e=>e===t))}return e.matches(r)}function r(e,{context:t,event:n},{guards:r}){return!i(r[0],t,n,e)}function o(e,{context:t,event:n},{guards:r}){return r.every((r=>i(r,t,n,e)))}function u(e,{context:t,event:n},{guards:r}){return r.some((r=>i(r,t,n,e)))}function i(e,t,n,r){const{machine:o}=r,u="function"==typeof e,c=u?e:o.implementations.guards["string"==typeof e?e:e.type];if(!u&&!c)throw new Error(`Guard '${"string"==typeof e?e:e.type}' is not implemented.'.`);if("function"!=typeof c)return i(c,t,n,r);const f={context:t,event:n},s=u||"string"==typeof e?void 0:"params"in e?"function"==typeof e.params?e.params({context:t,event:n}):e.params:void 0;if(!("check"in c))return c(f,s);return c.check(r,f,c)}e.and=function(e){function t(e,t){return!1}return t.check=o,t.guards=e,t},e.evaluateGuard=i,e.not=function(e){function t(e,t){return!1}return t.check=r,t.guards=[e],t},e.or=function(e){function t(e,t){return!1}return t.check=u,t.guards=e,t},e.stateIn=function(e){function t(e,t){return!1}return t.check=n,t.stateValue=e,t},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=xstate-guards.umd.min.js.map