@xstate/react
Advanced tools
Comparing version 4.0.0-beta.11 to 4.0.0-beta.12
import * as React from 'react'; | ||
import { ActorRefFrom, AnyStateMachine, SnapshotFrom, ActorOptions, AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, StateMachine, AnyActorLogic } from 'xstate'; | ||
type ToMachinesWithProvidedImplementations<TMachine extends AnyStateMachine> = TMachine extends StateMachine<infer TContext, infer TEvent, infer TActor, infer TAction, infer TGuard, infer TDelay, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? StateMachine<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never; | ||
type ToMachinesWithProvidedImplementations<TMachine extends AnyStateMachine> = TMachine extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer TActor, infer TAction, infer TGuard, infer TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never; | ||
export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, interpreterOptions?: ActorOptions<TLogic>): { | ||
@@ -5,0 +5,0 @@ useSelector: <T>(selector: (snapshot: SnapshotFrom<TLogic>) => T, compare?: (a: T, b: T) => boolean) => T; |
import { AnyActorLogic, AnyActor, ActorRefFrom, ActorOptions, Observer, SnapshotFrom } from 'xstate'; | ||
export declare function useIdleActor(logic: AnyActorLogic, options: Partial<ActorOptions<AnyActorLogic>>): AnyActor; | ||
export declare function useIdleActorRef(logic: AnyActorLogic, options: Partial<ActorOptions<AnyActorLogic>>): AnyActor; | ||
export declare function useActorRef<TLogic extends AnyActorLogic>(machine: TLogic, options?: ActorOptions<TLogic>, observerOrListener?: Observer<SnapshotFrom<TLogic>> | ((value: SnapshotFrom<TLogic>) => void)): ActorRefFrom<TLogic>; |
@@ -44,3 +44,3 @@ 'use strict'; | ||
function stopRootWithRehydration(actorRef) { | ||
// persist state here in a custom way allows us to persist inline actors and to preserve actor references | ||
// persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references | ||
// we do it to avoid setState in useEffect when the effect gets "reconnected" | ||
@@ -52,3 +52,3 @@ // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API | ||
persistedSnapshots.push([ref, ref.getSnapshot()]); | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped state | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot | ||
// React reconnects its subscribers (from the useSyncExternalStore) on its own | ||
@@ -62,7 +62,7 @@ // and userland subscibers should basically always do the same anyway | ||
ref._processingStatus = 0; | ||
ref._state = snapshot; | ||
ref._snapshot = snapshot; | ||
}); | ||
} | ||
function useIdleActor(logic, options) { | ||
function useIdleActorRef(logic, options) { | ||
let [[currentConfig, actorRef], setCurrent] = React.useState(() => { | ||
@@ -75,3 +75,3 @@ const actorRef = xstate.createActor(logic, options); | ||
...options, | ||
state: actorRef.getPersistedState({ | ||
snapshot: actorRef.getPersistedSnapshot({ | ||
__unsafeAllowInlineActors: true | ||
@@ -91,3 +91,3 @@ }) | ||
function useActorRef(machine, options = {}, observerOrListener) { | ||
const actorRef = useIdleActor(machine, options); | ||
const actorRef = useIdleActorRef(machine, options); | ||
React.useEffect(() => { | ||
@@ -112,3 +112,3 @@ if (!observerOrListener) { | ||
function useActor(logic, options = {}) { | ||
const actorRef = useIdleActor(logic, options); | ||
const actorRef = useIdleActorRef(logic, options); | ||
const getSnapshot = React.useCallback(() => { | ||
@@ -115,0 +115,0 @@ return actorRef.getSnapshot(); |
@@ -44,3 +44,3 @@ 'use strict'; | ||
function stopRootWithRehydration(actorRef) { | ||
// persist state here in a custom way allows us to persist inline actors and to preserve actor references | ||
// persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references | ||
// we do it to avoid setState in useEffect when the effect gets "reconnected" | ||
@@ -52,3 +52,3 @@ // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API | ||
persistedSnapshots.push([ref, ref.getSnapshot()]); | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped state | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot | ||
// React reconnects its subscribers (from the useSyncExternalStore) on its own | ||
@@ -62,7 +62,7 @@ // and userland subscibers should basically always do the same anyway | ||
ref._processingStatus = 0; | ||
ref._state = snapshot; | ||
ref._snapshot = snapshot; | ||
}); | ||
} | ||
function useIdleActor(logic, options) { | ||
function useIdleActorRef(logic, options) { | ||
let [[currentConfig, actorRef], setCurrent] = React.useState(() => { | ||
@@ -75,3 +75,3 @@ const actorRef = xstate.createActor(logic, options); | ||
...options, | ||
state: actorRef.getPersistedState({ | ||
snapshot: actorRef.getPersistedSnapshot({ | ||
__unsafeAllowInlineActors: true | ||
@@ -91,3 +91,3 @@ }) | ||
function useActorRef(machine, options = {}, observerOrListener) { | ||
const actorRef = useIdleActor(machine, options); | ||
const actorRef = useIdleActorRef(machine, options); | ||
React.useEffect(() => { | ||
@@ -115,3 +115,3 @@ if (!observerOrListener) { | ||
} | ||
const actorRef = useIdleActor(logic, options); | ||
const actorRef = useIdleActorRef(logic, options); | ||
const getSnapshot = React.useCallback(() => { | ||
@@ -118,0 +118,0 @@ return actorRef.getSnapshot(); |
@@ -18,3 +18,3 @@ import * as React from 'react'; | ||
function stopRootWithRehydration(actorRef) { | ||
// persist state here in a custom way allows us to persist inline actors and to preserve actor references | ||
// persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references | ||
// we do it to avoid setState in useEffect when the effect gets "reconnected" | ||
@@ -26,3 +26,3 @@ // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API | ||
persistedSnapshots.push([ref, ref.getSnapshot()]); | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped state | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot | ||
// React reconnects its subscribers (from the useSyncExternalStore) on its own | ||
@@ -36,7 +36,7 @@ // and userland subscibers should basically always do the same anyway | ||
ref._processingStatus = 0; | ||
ref._state = snapshot; | ||
ref._snapshot = snapshot; | ||
}); | ||
} | ||
function useIdleActor(logic, options) { | ||
function useIdleActorRef(logic, options) { | ||
let [[currentConfig, actorRef], setCurrent] = useState(() => { | ||
@@ -49,3 +49,3 @@ const actorRef = createActor(logic, options); | ||
...options, | ||
state: actorRef.getPersistedState({ | ||
snapshot: actorRef.getPersistedSnapshot({ | ||
__unsafeAllowInlineActors: true | ||
@@ -65,3 +65,3 @@ }) | ||
function useActorRef(machine, options = {}, observerOrListener) { | ||
const actorRef = useIdleActor(machine, options); | ||
const actorRef = useIdleActorRef(machine, options); | ||
useEffect(() => { | ||
@@ -89,3 +89,3 @@ if (!observerOrListener) { | ||
} | ||
const actorRef = useIdleActor(logic, options); | ||
const actorRef = useIdleActorRef(logic, options); | ||
const getSnapshot = useCallback(() => { | ||
@@ -92,0 +92,0 @@ return actorRef.getSnapshot(); |
@@ -18,3 +18,3 @@ import * as React from 'react'; | ||
function stopRootWithRehydration(actorRef) { | ||
// persist state here in a custom way allows us to persist inline actors and to preserve actor references | ||
// persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references | ||
// we do it to avoid setState in useEffect when the effect gets "reconnected" | ||
@@ -26,3 +26,3 @@ // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API | ||
persistedSnapshots.push([ref, ref.getSnapshot()]); | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped state | ||
// muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot | ||
// React reconnects its subscribers (from the useSyncExternalStore) on its own | ||
@@ -36,7 +36,7 @@ // and userland subscibers should basically always do the same anyway | ||
ref._processingStatus = 0; | ||
ref._state = snapshot; | ||
ref._snapshot = snapshot; | ||
}); | ||
} | ||
function useIdleActor(logic, options) { | ||
function useIdleActorRef(logic, options) { | ||
let [[currentConfig, actorRef], setCurrent] = useState(() => { | ||
@@ -49,3 +49,3 @@ const actorRef = createActor(logic, options); | ||
...options, | ||
state: actorRef.getPersistedState({ | ||
snapshot: actorRef.getPersistedSnapshot({ | ||
__unsafeAllowInlineActors: true | ||
@@ -65,3 +65,3 @@ }) | ||
function useActorRef(machine, options = {}, observerOrListener) { | ||
const actorRef = useIdleActor(machine, options); | ||
const actorRef = useIdleActorRef(machine, options); | ||
useEffect(() => { | ||
@@ -86,3 +86,3 @@ if (!observerOrListener) { | ||
function useActor(logic, options = {}) { | ||
const actorRef = useIdleActor(logic, options); | ||
const actorRef = useIdleActorRef(logic, options); | ||
const getSnapshot = useCallback(() => { | ||
@@ -89,0 +89,0 @@ return actorRef.getSnapshot(); |
{ | ||
"name": "@xstate/react", | ||
"version": "4.0.0-beta.11", | ||
"version": "4.0.0-beta.12", | ||
"description": "XState tools for React", | ||
@@ -58,3 +58,3 @@ "keywords": [ | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0", | ||
"xstate": "^5.0.0-beta.41" | ||
"xstate": "^5.0.0-beta.54" | ||
}, | ||
@@ -80,4 +80,4 @@ "peerDependenciesMeta": { | ||
"react-dom": "^18.0.0", | ||
"xstate": "5.0.0-beta.41" | ||
"xstate": "5.0.0-beta.54" | ||
} | ||
} |
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
35825
828