@stackflow/react
Advanced tools
Comparing version 0.5.2-alpha.7 to 0.6.0
@@ -1,2 +0,2 @@ | ||
var Ot=Object.create;var O=Object.defineProperty,bt=Object.defineProperties,Nt=Object.getOwnPropertyDescriptor,It=Object.getOwnPropertyDescriptors,Bt=Object.getOwnPropertyNames,K=Object.getOwnPropertySymbols,Mt=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable;var Q=(t,e,o)=>e in t?O(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,v=(t,e)=>{for(var o in e||(e={}))X.call(e,o)&&Q(t,o,e[o]);if(K)for(var o of K(e))Vt.call(e,o)&&Q(t,o,e[o]);return t},h=(t,e)=>bt(t,It(e));var Ut=(t,e)=>{for(var o in e)O(t,o,{get:e[o],enumerable:!0})},Y=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Bt(e))!X.call(t,s)&&s!==o&&O(t,s,{get:()=>e[s],enumerable:!(i=Nt(e,s))||i.enumerable});return t};var P=(t,e,o)=>(o=t!=null?Ot(Mt(t)):{},Y(e||!t||!t.__esModule?O(o,"default",{value:t,enumerable:!0}):o,t)),Ft=t=>Y(O({},"__esModule",{value:!0}),t);var $t={};Ut($t,{stackflow:()=>zt,useActions:()=>j,useActivity:()=>Ht,useActivityParams:()=>qt,useStack:()=>Gt});module.exports=Ft($t);var tt=require("react");var Z=require("react"),T=(0,Z.createContext)(null);var Ht=()=>(0,tt.useContext)(T);var et=require("react");function qt(){return(0,et.useContext)(T).params}var rt=require("react");var ot=require("react"),N=(0,ot.createContext)(null);var Gt=()=>(0,rt.useContext)(N);var E=P(require("react"));var it=require("react"),I=(0,it.createContext)({});var nt=P(require("react"));var at=({children:t,value:e})=>nt.default.createElement(I.Provider,{value:e},t);var st=P(require("react"));function B(){return st.default.useContext(I)}var S=require("@stackflow/core"),l=P(require("react")),Ct=P(require("react-fast-compare"));var mt=P(require("react"));var M=require("react"),ct=P(require("react-fast-compare"));function V(t){let e=(0,M.useRef)(t),o=e.current,i=(0,ct.default)(o,t);return(0,M.useEffect)(()=>{i||(e.current=t)}),i?o:t}var pt=({children:t,value:e})=>mt.default.createElement(T.Provider,{value:V(e)},t);var ft=require("@stackflow/core");function b(){return(0,ft.id)()}var ut=require("react"),U=(0,ut.createContext)(null);var vt=P(require("react"));var lt=({children:t,value:e})=>vt.default.createElement(U.Provider,{value:e},t);var dt=require("react");function k(){return(0,dt.useContext)(U)}var xt=require("react"),F=(0,xt.createContext)(null);var Pt=require("react"),H=(0,Pt.createContext)(null);var Lt=1e3,Wt=Lt/60,At=({transitionDuration:t,initialActivity:e,activities:o,children:i})=>{let s=k(),m=B(),n=(0,l.useMemo)(()=>{let p=new Date().getTime()-t,C=s.reduce((L,W)=>{var z,$;return($=(z=W.initialPushedEvent)==null?void 0:z.call(W))!=null?$:L},null),x=e?(0,S.makeEvent)("Pushed",{activityId:b(),activityName:e({context:m}),params:{},eventDate:p,skipEnterActiveState:!1}):null;C&&x&&console.warn(`Stackflow - Some plugin overrides an "initialActivity" option. The "initialActivity" option you set to "${x.activityName}" in the "stackflow" is ignored.`);let y=C!=null?C:x;y||console.warn("Stackflow - There is no initial activity. If you want to set the initial activity, add the `initialActivity` option of the `stackflow()` function or add a plugin that sets the initial activity. (e.g. `@stackflow/plugin-history-sync`)");let Dt=Object.keys(o).map(L=>(0,S.makeEvent)("ActivityRegistered",{activityName:L,eventDate:p})),J=[(0,S.makeEvent)("Initialized",{transitionDuration:t,eventDate:p}),...Dt];return y&&J.push(y),J},[]),c=(0,l.useMemo)(()=>(0,S.aggregate)(n,new Date().getTime()),[]),[r,a]=(0,l.useState)(()=>c),f=(0,l.useRef)(n),u=(0,l.useRef)(c),d=(0,l.useCallback)(()=>u.current,[u]),A=(0,l.useCallback)((p,C)=>{let x=(0,S.makeEvent)(p,C),y=[...f.current,x];f.current=y,a((0,S.aggregate)(y,new Date().getTime()))},[f,a]);return(0,l.useEffect)(()=>{let p=setInterval(()=>{let C=f.current,x=(0,S.aggregate)(C,new Date().getTime());(0,Ct.default)(r,x)||(a(x),u.current=x),x.globalTransitionState==="idle"&&clearInterval(p)},Wt);return()=>{clearInterval(p)}},[f,r,a]),l.default.createElement(H.Provider,{value:r},l.default.createElement(F.Provider,{value:(0,l.useMemo)(()=>({getStack:d,dispatchEvent:A}),[d,A])},i))};var g=P(require("react"));var kt=t=>JSON.parse(JSON.stringify(t)),q=()=>{let t=k(),e=B(),{dispatchEvent:o,getStack:i}=g.default.useContext(F),s=(0,g.useCallback)((r,a)=>{let f=!1,u=kt(a),d=()=>{f=!0},A=p=>{u=kt(p)};return t.forEach(p=>{var C,x,y;switch(r){case"PUSHED":(C=p.onBeforePush)==null||C.call(p,{actionParams:u,actions:{dispatchEvent:o,getStack:i,preventDefault:d,overrideActionParams:A}});break;case"REPLACED":(x=p.onBeforeReplace)==null||x.call(p,{actionParams:u,actions:{dispatchEvent:o,getStack:i,preventDefault:d,overrideActionParams:A}});break;case"POPPED":(y=p.onBeforePop)==null||y.call(p,{actionParams:u,actions:{dispatchEvent:o,getStack:i,preventDefault:d,overrideActionParams:A}});break;default:break}}),{isPrevented:f,params:u}},[t,o,i,e]),m=(0,g.useCallback)(({activityId:r,activityName:a,params:f,skipEnterActiveState:u})=>{let{isPrevented:d,params:A}=s("PUSHED",{activityId:r,activityName:a,params:f,skipEnterActiveState:u});d||o("Pushed",v({},A))},[o]),n=(0,g.useCallback)(({activityId:r,activityName:a,params:f,skipEnterActiveState:u})=>{let{isPrevented:d,params:A}=s("REPLACED",{activityId:r,activityName:a,params:f,skipEnterActiveState:u});d||o("Replaced",v({},A))},[o]),c=(0,g.useCallback)(r=>{let a=r!=null?r:{},{isPrevented:f,params:u}=s("POPPED",a);f||o("Popped",v({},u))},[o]);return(0,g.useMemo)(()=>({dispatchEvent:o,getStack:i,push:m,replace:n,pop:c}),[o,i,m,n,c])};var yt=P(require("react"));var w=()=>yt.default.useContext(H);var St=require("@stackflow/core"),R=require("react");var _t=()=>{let t=k(),e=w(),o=q(),i=(0,R.useCallback)(n=>{t.forEach(c=>{var r;(r=c.onInit)==null||r.call(c,n)})},[]),s=(0,R.useCallback)(({actions:n,effect:c})=>{switch(c._TAG){case"PUSHED":{t.forEach(r=>{var a;return(a=r.onPushed)==null?void 0:a.call(r,{actions:n,effect:c})});break}case"POPPED":{t.forEach(r=>{var a;return(a=r.onPopped)==null?void 0:a.call(r,{actions:n,effect:c})});break}case"REPLACED":{t.forEach(r=>{var a;return(a=r.onReplaced)==null?void 0:a.call(r,{actions:n,effect:c})});break}case"%SOMETHING_CHANGED%":{t.forEach(r=>{var a;return(a=r.onChanged)==null?void 0:a.call(r,{actions:n,effect:c})});break}default:break}},[]);(0,R.useEffect)(()=>{i==null||i({actions:{dispatchEvent:o.dispatchEvent,getStack:o.getStack}})},[]);let m=(0,R.useRef)(e);return(0,R.useEffect)(()=>{let n=m.current;(n?(0,St.produceEffects)(n,e):[]).forEach(r=>{s({actions:{dispatchEvent:o.dispatchEvent,getStack:o.getStack},effect:r})}),m.current=v({},e)},[e]),null},gt=_t;var D=P(require("react"));var G=P(require("react"));var Et=P(require("react"));var ht=({children:t,value:e})=>Et.default.createElement(N.Provider,{value:V(e)},t);var jt=({activities:t,plugin:e})=>{let o=w(),i=k();return e.render({stack:h(v({},o),{render(s){let m=v(v({},o),s);return{activities:m.activities.map(n=>h(v({},n),{key:n.id,render(c){let r=t[n.name],a=G.default.createElement(r,{params:n.params});return i.forEach(f=>{var u,d;a=(d=(u=f.wrapActivity)==null?void 0:u.call(f,{activity:h(v({},n),{render:()=>a})}))!=null?d:a}),G.default.createElement(ht,{value:m},G.default.createElement(pt,{key:n.id,value:v(v({},n),c)},a))}}))}}})})},Rt=jt;var Jt=({activities:t})=>{let e=w(),o=k(),i=o.filter(m=>!!m.render);(0,D.useEffect)(()=>{i.length===0&&console.warn(`Stackflow - There is no rendering plugin, so "<Stack />" doesn't render anything. If you want to render some UI, use "@stackflow/plugin-renderer-basic" or add another rendering plugin.`)},[i]);let s=D.default.createElement(D.default.Fragment,null,i.map(m=>D.default.createElement(Rt,{activities:t,key:m.key,plugin:m})));return o.forEach(m=>{var n,c;s=(c=(n=m.wrapStack)==null?void 0:n.call(m,{stack:h(v({},e),{render(){return s}})}))!=null?c:s}),s},Tt=Jt;var wt=require("react");function _(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}function j(){let t=q();return(0,wt.useMemo)(()=>({push(e,o,i){t.push({activityId:b(),activityName:e,params:o,skipEnterActiveState:_(i).skipActiveState})},replace(e,o,i){t.replace({activityId:b(),activityName:e,params:o,skipEnterActiveState:_(i).skipActiveState})},pop(e){t.pop({skipExitActiveState:_(e).skipActiveState})}}),[t.push,t.replace,t.pop])}function zt(t){let e=Object.entries(t.activities).reduce((o,[i,s])=>h(v({},o),{[i]:E.default.memo(s)}),{});return{Stack(o){var s;let i=(0,E.useMemo)(()=>{var m;return((m=t.plugins)!=null?m:[]).reduce((n,c)=>[...n,...Array.isArray(c)?c:[c]],[]).map(n=>n({context:o.context}))},[]);return E.default.createElement(at,{value:(s=o.context)!=null?s:{}},E.default.createElement(lt,{value:i},E.default.createElement(At,{activities:e,initialActivity:t.initialActivity,transitionDuration:t.transitionDuration},E.default.createElement(Tt,{activities:e}),E.default.createElement(gt,null))))},useFlow:j}} | ||
var Ot=Object.create;var b=Object.defineProperty,Nt=Object.defineProperties,It=Object.getOwnPropertyDescriptor,Bt=Object.getOwnPropertyDescriptors,Mt=Object.getOwnPropertyNames,Q=Object.getOwnPropertySymbols,Vt=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable;var X=(t,e,o)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,v=(t,e)=>{for(var o in e||(e={}))Y.call(e,o)&&X(t,o,e[o]);if(Q)for(var o of Q(e))Ft.call(e,o)&&X(t,o,e[o]);return t},h=(t,e)=>Nt(t,Bt(e));var Ut=(t,e)=>{for(var o in e)b(t,o,{get:e[o],enumerable:!0})},Z=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Mt(e))!Y.call(t,a)&&a!==o&&b(t,a,{get:()=>e[a],enumerable:!(i=It(e,a))||i.enumerable});return t};var d=(t,e,o)=>(o=t!=null?Ot(Vt(t)):{},Z(e||!t||!t.__esModule?b(o,"default",{value:t,enumerable:!0}):o,t)),Ht=t=>Z(b({},"__esModule",{value:!0}),t);var Qt={};Ut(Qt,{stackflow:()=>Kt,useActions:()=>J,useActivity:()=>qt,useActivityParams:()=>Gt,useStack:()=>Lt});module.exports=Ht(Qt);var et=require("react");var tt=require("react"),T=(0,tt.createContext)(null);var qt=()=>(0,et.useContext)(T);var ot=require("react");function Gt(){return(0,ot.useContext)(T).params}var it=require("react");var rt=require("react"),N=(0,rt.createContext)(null);var Lt=()=>(0,it.useContext)(N);var E=d(require("react"));var nt=require("react"),I=(0,nt.createContext)({});var at=d(require("react"));var st=({children:t,value:e})=>at.default.createElement(I.Provider,{value:e},t);var ct=d(require("react"));function B(){return ct.default.useContext(I)}var S=require("@stackflow/core"),l=d(require("react")),At=d(require("react-fast-compare"));var pt=d(require("react"));var M=require("react"),mt=d(require("react-fast-compare"));function V(t){let e=(0,M.useRef)(t),o=e.current,i=(0,mt.default)(o,t);return(0,M.useEffect)(()=>{i||(e.current=t)}),i?o:t}var ft=({children:t,value:e})=>pt.default.createElement(T.Provider,{value:V(e)},t);var ut=require("@stackflow/core");function O(){return(0,ut.id)()}var vt=require("react"),F=(0,vt.createContext)(null);var lt=d(require("react"));var dt=({children:t,value:e})=>lt.default.createElement(F.Provider,{value:e},t);var xt=require("react");function k(){return(0,xt.useContext)(F)}var Pt=require("react"),U=(0,Pt.createContext)(null);var Ct=require("react"),H=(0,Ct.createContext)(null);var Wt=1e3,_t=Wt/60,kt=({transitionDuration:t,initialActivity:e,activities:o,children:i})=>{let a=k(),c=B(),n=(0,l.useMemo)(()=>{let p=new Date().getTime()-t,C=a.reduce((W,_)=>{var $,K;return(K=($=_.initialPushedEvent)==null?void 0:$.call(_))!=null?K:W},null),P=e?(0,S.makeEvent)("Pushed",{activityId:O(),activityName:e({context:c}),params:{},eventDate:p,skipEnterActiveState:!1}):null;C&&P&&console.warn(`Stackflow - Some plugin overrides an "initialActivity" option. The "initialActivity" option you set to "${P.activityName}" in the "stackflow" is ignored.`);let y=C!=null?C:P;y||console.warn("Stackflow - There is no initial activity. If you want to set the initial activity, add the `initialActivity` option of the `stackflow()` function or add a plugin that sets the initial activity. (e.g. `@stackflow/plugin-history-sync`)");let bt=Object.keys(o).map(W=>(0,S.makeEvent)("ActivityRegistered",{activityName:W,eventDate:p})),z=[(0,S.makeEvent)("Initialized",{transitionDuration:t,eventDate:p}),...bt];return y&&z.push(y),z},[]),m=(0,l.useMemo)(()=>(0,S.aggregate)(n,new Date().getTime()),[]),[r,s]=(0,l.useState)(()=>m),f=(0,l.useRef)(n),u=(0,l.useRef)(m),x=(0,l.useCallback)(()=>u.current,[u]),A=(0,l.useCallback)((p,C)=>{let P=(0,S.makeEvent)(p,C),y=[...f.current,P];f.current=y,s((0,S.aggregate)(y,new Date().getTime()))},[f,s]);return(0,l.useEffect)(()=>{let p=setInterval(()=>{let C=f.current,P=(0,S.aggregate)(C,new Date().getTime());(0,At.default)(r,P)||(s(P),u.current=P),P.globalTransitionState==="idle"&&clearInterval(p)},_t);return()=>{clearInterval(p)}},[f,r,s]),l.default.createElement(H.Provider,{value:r},l.default.createElement(U.Provider,{value:(0,l.useMemo)(()=>({getStack:x,dispatchEvent:A}),[x,A])},i))};var g=d(require("react"));var yt=t=>JSON.parse(JSON.stringify(t)),q=()=>{let t=k(),e=B(),{dispatchEvent:o,getStack:i}=g.default.useContext(U),a=(0,g.useCallback)((r,s)=>{let f=!1,u=yt(s),x=()=>{f=!0},A=p=>{u=yt(p)};return t.forEach(p=>{var C,P,y;switch(r){case"PUSHED":(C=p.onBeforePush)==null||C.call(p,{actionParams:u,actions:{dispatchEvent:o,getStack:i,preventDefault:x,overrideActionParams:A}});break;case"REPLACED":(P=p.onBeforeReplace)==null||P.call(p,{actionParams:u,actions:{dispatchEvent:o,getStack:i,preventDefault:x,overrideActionParams:A}});break;case"POPPED":(y=p.onBeforePop)==null||y.call(p,{actionParams:u,actions:{dispatchEvent:o,getStack:i,preventDefault:x,overrideActionParams:A}});break;default:break}}),{isPrevented:f,params:u}},[t,o,i,e]),c=(0,g.useCallback)(({activityId:r,activityName:s,params:f,skipEnterActiveState:u})=>{let{isPrevented:x,params:A}=a("PUSHED",{activityId:r,activityName:s,params:f,skipEnterActiveState:u});x||o("Pushed",v({},A))},[o]),n=(0,g.useCallback)(({activityId:r,activityName:s,params:f,skipEnterActiveState:u})=>{let{isPrevented:x,params:A}=a("REPLACED",{activityId:r,activityName:s,params:f,skipEnterActiveState:u});x||o("Replaced",v({},A))},[o]),m=(0,g.useCallback)(r=>{let s=r!=null?r:{},{isPrevented:f,params:u}=a("POPPED",s);f||o("Popped",v({},u))},[o]);return(0,g.useMemo)(()=>({dispatchEvent:o,getStack:i,push:c,replace:n,pop:m}),[o,i,c,n,m])};var St=d(require("react"));var w=()=>St.default.useContext(H);var gt=require("@stackflow/core"),R=require("react");var jt=()=>{let t=k(),e=w(),o=q(),i=(0,R.useCallback)(n=>{t.forEach(m=>{var r;(r=m.onInit)==null||r.call(m,n)})},[]),a=(0,R.useCallback)(({actions:n,effect:m})=>{switch(m._TAG){case"PUSHED":{t.forEach(r=>{var s;return(s=r.onPushed)==null?void 0:s.call(r,{actions:n,effect:m})});break}case"POPPED":{t.forEach(r=>{var s;return(s=r.onPopped)==null?void 0:s.call(r,{actions:n,effect:m})});break}case"REPLACED":{t.forEach(r=>{var s;return(s=r.onReplaced)==null?void 0:s.call(r,{actions:n,effect:m})});break}case"%SOMETHING_CHANGED%":{t.forEach(r=>{var s;return(s=r.onChanged)==null?void 0:s.call(r,{actions:n,effect:m})});break}default:break}},[]);(0,R.useEffect)(()=>{i==null||i({actions:{dispatchEvent:o.dispatchEvent,getStack:o.getStack}})},[]);let c=(0,R.useRef)(e);return(0,R.useEffect)(()=>{let n=c.current;(n?(0,gt.produceEffects)(n,e):[]).forEach(r=>{a({actions:{dispatchEvent:o.dispatchEvent,getStack:o.getStack},effect:r})}),c.current=v({},e)},[e]),null},Et=jt;var D=d(require("react"));var G=d(require("react"));var ht=d(require("react"));var Rt=({children:t,value:e})=>ht.default.createElement(N.Provider,{value:V(e)},t);var Jt=({activities:t,plugin:e})=>{let o=w(),i=k();return e.render({stack:h(v({},o),{render(a){let c=v(v({},o),a);return{activities:c.activities.map(n=>h(v({},n),{key:n.id,render(m){let r=t[n.name],s=G.default.createElement(r,{params:n.params});return i.forEach(f=>{var u,x;s=(x=(u=f.wrapActivity)==null?void 0:u.call(f,{activity:h(v({},n),{render:()=>s})}))!=null?x:s}),G.default.createElement(Rt,{value:c},G.default.createElement(ft,{key:n.id,value:v(v({},n),m)},s))}}))}}})})},Tt=Jt;var zt=({activities:t})=>{let e=w(),o=k(),i=o.filter(c=>!!c.render);(0,D.useEffect)(()=>{i.length===0&&console.warn(`Stackflow - There is no rendering plugin, so "<Stack />" doesn't render anything. If you want to render some UI, use "@stackflow/plugin-renderer-basic" or add another rendering plugin.`)},[i]);let a=D.default.createElement(D.default.Fragment,null,i.map(c=>D.default.createElement(Tt,{activities:t,key:c.key,plugin:c})));return o.forEach(c=>{var n,m;a=(m=(n=c.wrapStack)==null?void 0:n.call(c,{stack:h(v({},e),{render(){return a}})}))!=null?m:a}),a},wt=zt;var L=d(require("react"));function j(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}var Dt,$t=(Dt=L.default.useTransition)!=null?Dt:()=>[!1,t=>t()];function J(){let t=q(),[e,o]=$t();return(0,L.useMemo)(()=>({pending:e,push(i,a,c){e||o(()=>{t.push({activityId:O(),activityName:i,params:a,skipEnterActiveState:j(c).skipActiveState})})},replace(i,a,c){e||o(()=>{t.replace({activityId:O(),activityName:i,params:a,skipEnterActiveState:j(c).skipActiveState})})},pop(i){e||o(()=>{t.pop({skipExitActiveState:j(i).skipActiveState})})}}),[t.push,t.replace,t.pop,e,o])}function Kt(t){let e=Object.entries(t.activities).reduce((o,[i,a])=>h(v({},o),{[i]:E.default.memo(a)}),{});return{Stack(o){var a;let i=(0,E.useMemo)(()=>{var c;return((c=t.plugins)!=null?c:[]).reduce((n,m)=>[...n,...Array.isArray(m)?m:[m]],[]).map(n=>n({context:o.context}))},[]);return E.default.createElement(st,{value:(a=o.context)!=null?a:{}},E.default.createElement(dt,{value:i},E.default.createElement(kt,{activities:e,initialActivity:t.initialActivity,transitionDuration:t.transitionDuration},E.default.createElement(wt,{activities:e}),E.default.createElement(Et,null))))},useFlow:J}} | ||
//# sourceMappingURL=index.js.map |
@@ -5,2 +5,6 @@ import { ActivityComponentType } from "./activity"; | ||
/** | ||
* Is transition pending | ||
*/ | ||
pending: boolean; | ||
/** | ||
* Push new activity | ||
@@ -7,0 +11,0 @@ */ |
{ | ||
"name": "@stackflow/react", | ||
"version": "0.5.2-alpha.7+62ac69c", | ||
"version": "0.6.0", | ||
"license": "MIT", | ||
@@ -37,3 +37,4 @@ "exports": { | ||
"peerDependencies": { | ||
"@stackflow/core": "^0.1.0", | ||
"@stackflow/core": "0", | ||
"@types/react": ">=16.8.0", | ||
"react": ">=16.8.0" | ||
@@ -50,3 +51,3 @@ }, | ||
}, | ||
"gitHead": "62ac69ccc251283cdb193a08c23ab2709fafec13" | ||
"gitHead": "eea1cc8ddc1488ada45121a834cfc0a397ba5355" | ||
} |
@@ -1,2 +0,2 @@ | ||
import { useMemo } from "react"; | ||
import React, { useMemo } from "react"; | ||
@@ -23,2 +23,7 @@ import { ActivityComponentType, makeActivityId } from "./activity"; | ||
/** | ||
* Is transition pending | ||
*/ | ||
pending: boolean; | ||
/** | ||
* Push new activity | ||
@@ -51,2 +56,5 @@ */ | ||
const useTransition: () => [boolean, React.TransitionStartFunction] = | ||
React.useTransition ?? (() => [false, (cb: () => void) => cb()]); | ||
export function useActions< | ||
@@ -56,29 +64,52 @@ T extends BaseActivities, | ||
const coreActions = useCoreActions(); | ||
const [pending, startTransition] = useTransition(); | ||
return useMemo( | ||
() => ({ | ||
pending, | ||
push(activityName, params, options) { | ||
coreActions.push({ | ||
activityId: makeActivityId(), | ||
activityName, | ||
params, | ||
skipEnterActiveState: parseActionOptions(options).skipActiveState, | ||
if (pending) { | ||
return; | ||
} | ||
startTransition(() => { | ||
coreActions.push({ | ||
activityId: makeActivityId(), | ||
activityName, | ||
params, | ||
skipEnterActiveState: parseActionOptions(options).skipActiveState, | ||
}); | ||
}); | ||
}, | ||
replace(activityName, params, options) { | ||
coreActions.replace({ | ||
activityId: makeActivityId(), | ||
activityName, | ||
params, | ||
skipEnterActiveState: parseActionOptions(options).skipActiveState, | ||
if (pending) { | ||
return; | ||
} | ||
startTransition(() => { | ||
coreActions.replace({ | ||
activityId: makeActivityId(), | ||
activityName, | ||
params, | ||
skipEnterActiveState: parseActionOptions(options).skipActiveState, | ||
}); | ||
}); | ||
}, | ||
pop(options) { | ||
coreActions.pop({ | ||
skipExitActiveState: parseActionOptions(options).skipActiveState, | ||
if (pending) { | ||
return; | ||
} | ||
startTransition(() => { | ||
coreActions.pop({ | ||
skipExitActiveState: parseActionOptions(options).skipActiveState, | ||
}); | ||
}); | ||
}, | ||
}), | ||
[coreActions.push, coreActions.replace, coreActions.pop], | ||
[ | ||
coreActions.push, | ||
coreActions.replace, | ||
coreActions.pop, | ||
pending, | ||
startTransition, | ||
], | ||
); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
122115
1211
0
4