@zag-js/core
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -308,14 +308,2 @@ "use strict"; | ||
this.status = "Running" /* Running */; | ||
const event = toEvent("machine.init" /* Init */); | ||
const initTarget = isObject(init) ? init.value : init; | ||
const initContext = isObject(init) ? init.context : void 0; | ||
if (initContext) { | ||
this.setContext(initContext); | ||
} | ||
const transition = { | ||
target: initTarget != null ? initTarget : this.config.initial | ||
}; | ||
const next = this.getNextStateInfo(transition, event); | ||
this.initialState = next; | ||
this.performStateChangeEffects(this.state.value, next, event); | ||
this.removeStateListener = (0, import_store3.subscribe)(this.state, () => { | ||
@@ -341,2 +329,14 @@ this.stateListeners.forEach((listener) => { | ||
this.executeActions(this.config.entry, toEvent("machine.start" /* Start */)); | ||
const event = toEvent("machine.init" /* Init */); | ||
const target = isObject(init) ? init.value : init; | ||
const context = isObject(init) ? init.context : void 0; | ||
if (context) { | ||
this.setContext(context); | ||
} | ||
const transition = { | ||
target: target != null ? target : this.config.initial | ||
}; | ||
const next = this.getNextStateInfo(transition, event); | ||
this.initialState = next; | ||
this.performStateChangeEffects(this.state.value, next, event); | ||
return this; | ||
@@ -357,3 +357,3 @@ }); | ||
this.executeActions(this.config.exit, toEvent("machine.stop" /* Stop */)); | ||
this.setState(null); | ||
this.setState(""); | ||
this.setEvent("machine.stop" /* Stop */); | ||
@@ -465,2 +465,4 @@ this.stopStateListeners(); | ||
__publicField(this, "setContext", (context) => { | ||
if (!context) | ||
return; | ||
for (const key in context) { | ||
@@ -624,2 +626,4 @@ this.state.context[key] = context[key]; | ||
const currentState = this.state.value; | ||
if (currentState === "") | ||
return; | ||
const stateNode = current ? this.getStateNode(current) : void 0; | ||
@@ -756,2 +760,5 @@ this.stopActivities(currentState); | ||
} | ||
getState() { | ||
return (0, import_json.klona)(this.stateSnapshot); | ||
} | ||
get contextSnapshot() { | ||
@@ -758,0 +765,0 @@ return this.stateSnapshot.context; |
@@ -29,2 +29,3 @@ import { Dict, MachineStatus, MachineType, StateMachine as S, Writable } from "./types"; | ||
private get stateSnapshot(); | ||
getState(): S.State<TContext, TState, TEvent>; | ||
private get contextSnapshot(); | ||
@@ -57,3 +58,3 @@ start: (init?: S.StateInit<TContext, TState>) => this; | ||
*/ | ||
setContext: (context: Partial<Writable<TContext>>) => void; | ||
setContext: (context: Partial<Writable<TContext>> | undefined) => void; | ||
withContext: (context: Partial<Writable<TContext>>) => Machine<TContext, TState, TEvent>; | ||
@@ -60,0 +61,0 @@ setActions: (actions: Partial<S.MachineOptions<TContext, TState, TEvent>>["actions"]) => void; |
{ | ||
"name": "@zag-js/core", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "A minimal implementation of xstate fsm for UI machines", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
91713
2095