@zag-js/core
Advanced tools
Comparing version 0.0.0-dev-20240714222614 to 0.0.0-dev-20240723090825
@@ -157,5 +157,6 @@ export { Ref, proxy, ref, snapshot, subscribe } from '@zag-js/store'; | ||
context: TContext; | ||
value: TState["value"]; | ||
value: TState["value"] | null; | ||
tags?: TState["tags"][]; | ||
}; | ||
type StateInit<TContext, TState extends StateSchema> = TState["value"] | StateInitObject<TContext, TState>; | ||
type StateInit<TContext, TState extends StateSchema> = StateInitObject<TContext, TState>; | ||
type StateListener<TContext extends Dict, TState extends StateSchema, TEvent extends EventObject = EventObject> = (state: State<TContext, TState, TEvent>) => void; | ||
@@ -405,2 +406,3 @@ interface StateInfo<TContext extends Dict, TState extends StateSchema, TEvent extends EventObject> { | ||
get [Symbol.toStringTag](): string; | ||
getHydrationState(): StateMachine.StateInit<TContext, TState>; | ||
} | ||
@@ -407,0 +409,0 @@ type MachineSrc<TContext extends Dict, TState extends StateMachine.StateSchema, TEvent extends StateMachine.EventObject = StateMachine.AnyEventObject> = Machine<TContext, TState, TEvent> | (() => Machine<TContext, TState, TEvent>); |
@@ -76,2 +76,22 @@ "use strict"; | ||
// ../utilities/core/src/split-props.ts | ||
function splitProps(props, keys) { | ||
const rest = {}; | ||
const result = {}; | ||
const keySet = new Set(keys); | ||
for (const key in props) { | ||
if (keySet.has(key)) { | ||
result[key] = props[key]; | ||
} else { | ||
rest[key] = props[key]; | ||
} | ||
} | ||
return [result, rest]; | ||
} | ||
var createSplitProps = (keys) => { | ||
return function split(props) { | ||
return splitProps(props, keys); | ||
}; | ||
}; | ||
// ../utilities/core/src/object.ts | ||
@@ -95,2 +115,5 @@ function compact(obj) { | ||
}; | ||
function omit(obj, keys) { | ||
return createSplitProps(keys)(obj)[1]; | ||
} | ||
@@ -848,2 +871,11 @@ // ../utilities/core/src/warning.ts | ||
} | ||
getHydrationState() { | ||
const state = this.getState(); | ||
const computedKeys = Object.keys(this.config.computed ?? {}); | ||
return { | ||
value: state.value, | ||
context: omit(state.context, computedKeys), | ||
tags: state.tags | ||
}; | ||
} | ||
}; | ||
@@ -850,0 +882,0 @@ var createMachine = (config, options) => new Machine(config, options); |
{ | ||
"name": "@zag-js/core", | ||
"version": "0.0.0-dev-20240714222614", | ||
"version": "0.0.0-dev-20240723090825", | ||
"description": "A minimal implementation of xstate fsm for UI machines", | ||
@@ -30,7 +30,7 @@ "keywords": [ | ||
"klona": "2.0.6", | ||
"@zag-js/store": "0.0.0-dev-20240714222614" | ||
"@zag-js/store": "0.0.0-dev-20240723090825" | ||
}, | ||
"devDependencies": { | ||
"clean-package": "2.2.0", | ||
"@zag-js/utils": "0.0.0-dev-20240714222614" | ||
"@zag-js/utils": "0.0.0-dev-20240723090825" | ||
}, | ||
@@ -37,0 +37,0 @@ "clean-package": "../../clean-package.config.json", |
@@ -13,2 +13,3 @@ import { ref, snapshot, subscribe } from "@zag-js/store" | ||
noop, | ||
omit, | ||
runIfFn, | ||
@@ -801,2 +802,12 @@ uuid, | ||
} | ||
public getHydrationState(): S.StateInit<TContext, TState> { | ||
const state = this.getState() | ||
const computedKeys = Object.keys(this.config.computed ?? {}) | ||
return { | ||
value: state.value, | ||
context: omit(state.context, computedKeys) as any, | ||
tags: state.tags, | ||
} | ||
} | ||
} | ||
@@ -803,0 +814,0 @@ |
@@ -280,6 +280,7 @@ /* ----------------------------------------------------------------------------- | ||
context: TContext | ||
value: TState["value"] | ||
value: TState["value"] | null | ||
tags?: TState["tags"][] | ||
} | ||
export type StateInit<TContext, TState extends StateSchema> = TState["value"] | StateInitObject<TContext, TState> | ||
export type StateInit<TContext, TState extends StateSchema> = StateInitObject<TContext, TState> | ||
@@ -286,0 +287,0 @@ export type StateListener< |
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
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
302268
3611
+ Added@zag-js/store@0.0.0-dev-20240723090825(transitive)
- Removed@zag-js/store@0.0.0-dev-20240714222614(transitive)