@xstate/react
Advanced tools
Comparing version 4.0.0-beta.8 to 4.0.0-beta.9
import * as React from 'react'; | ||
import { ActorRefFrom, AnyStateMachine, SnapshotFrom, InterpreterOptions, AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, StateMachine, AnyActorLogic } from 'xstate'; | ||
type ToMachinesWithProvidedImplementations<TMachine extends AnyStateMachine> = TMachine extends StateMachine<infer TContext, infer TEvent, infer TAction, infer TActorMap, infer TResolvedTypesMeta> ? StateMachine<TContext, TEvent, TAction, TActorMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never; | ||
export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, interpreterOptions?: InterpreterOptions<TLogic>): { | ||
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; | ||
export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, interpreterOptions?: ActorOptions<TLogic>): { | ||
useSelector: <T>(selector: (snapshot: SnapshotFrom<TLogic>) => T, compare?: (a: T, b: T) => boolean) => T; | ||
@@ -9,3 +9,3 @@ useActorRef: () => ActorRefFrom<TLogic>; | ||
children: React.ReactNode; | ||
options?: InterpreterOptions<TLogic>; | ||
options?: ActorOptions<TLogic>; | ||
} & (TLogic extends AnyStateMachine ? AreAllImplementationsAssumedToBeProvided<TLogic['__TResolvedTypesMeta']> extends true ? { | ||
@@ -12,0 +12,0 @@ logic?: TLogic; |
@@ -1,2 +0,2 @@ | ||
import { ActorRefFrom, AnyActorLogic, InterpreterOptions, SnapshotFrom } from 'xstate'; | ||
export declare function useActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: InterpreterOptions<TLogic>): [SnapshotFrom<TLogic>, ActorRefFrom<TLogic>['send'], ActorRefFrom<TLogic>]; | ||
import { ActorRefFrom, AnyActorLogic, ActorOptions, SnapshotFrom } from 'xstate'; | ||
export declare function useActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: ActorOptions<TLogic>): [SnapshotFrom<TLogic>, ActorRefFrom<TLogic>['send'], ActorRefFrom<TLogic>]; |
@@ -1,11 +0,11 @@ | ||
import { AnyActorLogic, AnyInterpreter, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineImplementations, ActorRefFrom, InterpreterOptions, Observer, StateFrom, SnapshotFrom } from 'xstate'; | ||
export declare function useIdleInterpreter(machine: AnyActorLogic, options: Partial<InterpreterOptions<AnyActorLogic>>): AnyInterpreter; | ||
import { AnyActorLogic, AnyActor, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineImplementations, ActorRefFrom, ActorOptions, Observer, StateFrom, SnapshotFrom, TODO } from 'xstate'; | ||
export declare function useIdleInterpreter(machine: AnyActorLogic, options: Partial<ActorOptions<AnyActorLogic>>): AnyActor; | ||
type RestParams<TLogic extends AnyActorLogic> = TLogic extends AnyStateMachine ? AreAllImplementationsAssumedToBeProvided<TLogic['__TResolvedTypesMeta']> extends false ? [ | ||
options: InterpreterOptions<TLogic> & InternalMachineImplementations<TLogic['__TContext'], TLogic['__TEvent'], TLogic['__TResolvedTypesMeta'], true>, | ||
options: ActorOptions<TLogic> & InternalMachineImplementations<TLogic['__TContext'], TLogic['__TEvent'], TODO, TODO, TODO, TLogic['__TResolvedTypesMeta'], true>, | ||
observerOrListener?: Observer<StateFrom<TLogic>> | ((value: StateFrom<TLogic>) => void) | ||
] : [ | ||
options?: InterpreterOptions<TLogic> & InternalMachineImplementations<TLogic['__TContext'], TLogic['__TEvent'], TLogic['__TResolvedTypesMeta']>, | ||
options?: ActorOptions<TLogic> & InternalMachineImplementations<TLogic['__TContext'], TLogic['__TEvent'], TODO, TODO, TODO, TLogic['__TResolvedTypesMeta']>, | ||
observerOrListener?: Observer<StateFrom<TLogic>> | ((value: StateFrom<TLogic>) => void) | ||
] : [ | ||
options?: InterpreterOptions<TLogic>, | ||
options?: ActorOptions<TLogic>, | ||
observerOrListener?: Observer<SnapshotFrom<TLogic>> | ((value: SnapshotFrom<TLogic>) => void) | ||
@@ -12,0 +12,0 @@ ]; |
@@ -1,2 +0,2 @@ | ||
import { ActorRefFrom, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InterpreterOptions, MissingImplementationsError, StateFrom } from 'xstate'; | ||
import { ActorRefFrom, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, ActorOptions, MissingImplementationsError, StateFrom } from 'xstate'; | ||
/** | ||
@@ -6,3 +6,3 @@ * | ||
*/ | ||
export declare function useMachine<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?: InterpreterOptions<TMachine>): [ | ||
export declare function useMachine<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?: ActorOptions<TMachine>): [ | ||
StateFrom<TMachine>, | ||
@@ -9,0 +9,0 @@ ActorRefFrom<TMachine>['send'], |
@@ -8,3 +8,2 @@ 'use strict'; | ||
var xstate = require('xstate'); | ||
var useConstant = require('./useConstant-2ee82f84.cjs.js'); | ||
var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect'); | ||
@@ -37,5 +36,15 @@ require('xstate/actors'); | ||
function useConstant(fn) { | ||
const ref = React__namespace.useRef(); | ||
if (!ref.current) { | ||
ref.current = { | ||
v: fn() | ||
}; | ||
} | ||
return ref.current.v; | ||
} | ||
function useIdleInterpreter(machine, options) { | ||
const actorRef = useConstant.useConstant(() => { | ||
return xstate.interpret(machine, options); | ||
const actorRef = useConstant(() => { | ||
return xstate.createActor(machine, options); | ||
}); | ||
@@ -64,3 +73,3 @@ | ||
actorRef.stop(); | ||
actorRef.status = xstate.InterpreterStatus.NotStarted; | ||
actorRef.status = xstate.ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -88,3 +97,3 @@ }; | ||
actorRef.stop(); | ||
actorRef.status = xstate.InterpreterStatus.NotStarted; | ||
actorRef.status = xstate.ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -91,0 +100,0 @@ }; |
@@ -8,3 +8,2 @@ 'use strict'; | ||
var xstate = require('xstate'); | ||
var useConstant = require('./useConstant-ae6dceac.development.cjs.js'); | ||
var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect'); | ||
@@ -37,2 +36,12 @@ var actors = require('xstate/actors'); | ||
function useConstant(fn) { | ||
const ref = React__namespace.useRef(); | ||
if (!ref.current) { | ||
ref.current = { | ||
v: fn() | ||
}; | ||
} | ||
return ref.current.v; | ||
} | ||
function useIdleInterpreter(machine, options) { | ||
@@ -45,4 +54,4 @@ { | ||
} | ||
const actorRef = useConstant.useConstant(() => { | ||
return xstate.interpret(machine, options); | ||
const actorRef = useConstant(() => { | ||
return xstate.createActor(machine, options); | ||
}); | ||
@@ -71,3 +80,3 @@ | ||
actorRef.stop(); | ||
actorRef.status = xstate.InterpreterStatus.NotStarted; | ||
actorRef.status = xstate.ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -98,3 +107,3 @@ }; | ||
actorRef.stop(); | ||
actorRef.status = xstate.InterpreterStatus.NotStarted; | ||
actorRef.status = xstate.ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -101,0 +110,0 @@ }; |
import * as React from 'react'; | ||
import { useEffect, useState, useCallback } from 'react'; | ||
import { useSyncExternalStore } from 'use-sync-external-store/shim'; | ||
import { toObserver, InterpreterStatus, interpret } from 'xstate'; | ||
import { u as useConstant } from './useConstant-bac83df4.development.esm.js'; | ||
import { toObserver, ActorStatus, createActor } from 'xstate'; | ||
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'; | ||
@@ -10,2 +9,12 @@ import { isActorRef } from 'xstate/actors'; | ||
function useConstant(fn) { | ||
const ref = React.useRef(); | ||
if (!ref.current) { | ||
ref.current = { | ||
v: fn() | ||
}; | ||
} | ||
return ref.current.v; | ||
} | ||
function useIdleInterpreter(machine, options) { | ||
@@ -19,3 +28,3 @@ { | ||
const actorRef = useConstant(() => { | ||
return interpret(machine, options); | ||
return createActor(machine, options); | ||
}); | ||
@@ -44,3 +53,3 @@ | ||
actorRef.stop(); | ||
actorRef.status = InterpreterStatus.NotStarted; | ||
actorRef.status = ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -71,3 +80,3 @@ }; | ||
actorRef.stop(); | ||
actorRef.status = InterpreterStatus.NotStarted; | ||
actorRef.status = ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -74,0 +83,0 @@ }; |
import * as React from 'react'; | ||
import { useEffect, useCallback } from 'react'; | ||
import { useSyncExternalStore } from 'use-sync-external-store/shim'; | ||
import { toObserver, InterpreterStatus, interpret } from 'xstate'; | ||
import { u as useConstant } from './useConstant-c7ec0fdd.esm.js'; | ||
import { toObserver, ActorStatus, createActor } from 'xstate'; | ||
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'; | ||
@@ -10,5 +9,15 @@ import 'xstate/actors'; | ||
function useConstant(fn) { | ||
const ref = React.useRef(); | ||
if (!ref.current) { | ||
ref.current = { | ||
v: fn() | ||
}; | ||
} | ||
return ref.current.v; | ||
} | ||
function useIdleInterpreter(machine, options) { | ||
const actorRef = useConstant(() => { | ||
return interpret(machine, options); | ||
return createActor(machine, options); | ||
}); | ||
@@ -37,3 +46,3 @@ | ||
actorRef.stop(); | ||
actorRef.status = InterpreterStatus.NotStarted; | ||
actorRef.status = ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -61,3 +70,3 @@ }; | ||
actorRef.stop(); | ||
actorRef.status = InterpreterStatus.NotStarted; | ||
actorRef.status = ActorStatus.NotStarted; | ||
actorRef._initState(); | ||
@@ -64,0 +73,0 @@ }; |
{ | ||
"name": "@xstate/react", | ||
"version": "4.0.0-beta.8", | ||
"version": "4.0.0-beta.9", | ||
"description": "XState tools for React", | ||
@@ -21,16 +21,2 @@ "keywords": [ | ||
"exports": { | ||
"./fsm": { | ||
"types": { | ||
"import": "./fsm/dist/xstate-react-fsm.cjs.mjs", | ||
"default": "./fsm/dist/xstate-react-fsm.cjs.js" | ||
}, | ||
"development": { | ||
"module": "./fsm/dist/xstate-react-fsm.development.esm.js", | ||
"import": "./fsm/dist/xstate-react-fsm.development.cjs.mjs", | ||
"default": "./fsm/dist/xstate-react-fsm.development.cjs.js" | ||
}, | ||
"module": "./fsm/dist/xstate-react-fsm.esm.js", | ||
"import": "./fsm/dist/xstate-react-fsm.cjs.mjs", | ||
"default": "./fsm/dist/xstate-react-fsm.cjs.js" | ||
}, | ||
".": { | ||
@@ -61,4 +47,3 @@ "types": { | ||
"files": [ | ||
"dist", | ||
"fsm" | ||
"dist" | ||
], | ||
@@ -74,10 +59,6 @@ "repository": { | ||
"peerDependencies": { | ||
"@xstate/fsm": "^3.0.0-beta.3", | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0", | ||
"xstate": "^5.0.0-beta.18" | ||
"xstate": "^5.0.0-beta.28" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@xstate/fsm": { | ||
"optional": true | ||
}, | ||
"xstate": { | ||
@@ -97,3 +78,2 @@ "optional": true | ||
"@types/use-sync-external-store": "^0.0.3", | ||
"@xstate/fsm": "3.0.0-beta.3", | ||
"jsdom": "^14.0.0", | ||
@@ -103,10 +83,4 @@ "jsdom-global": "^3.0.2", | ||
"react-dom": "^18.0.0", | ||
"xstate": "5.0.0-beta.18" | ||
}, | ||
"preconstruct": { | ||
"entrypoints": [ | ||
"./index.ts", | ||
"./fsm.ts" | ||
] | ||
"xstate": "5.0.0-beta.28" | ||
} | ||
} |
@@ -24,10 +24,2 @@ # @xstate/react | ||
or | ||
```html | ||
<script src="https://unpkg.com/@xstate/react/dist/xstate-react-fsm.umd.min.js"></script> | ||
``` | ||
By using the global variable `XStateReactFSM` | ||
2. Import the `useMachine` hook: | ||
@@ -34,0 +26,0 @@ |
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
4
10
31612
20
747
55