@zag-js/core
Advanced tools
Comparing version 0.0.0-dev-20220714091855 to 0.0.0-dev-20220823143115
@@ -91,3 +91,3 @@ "use strict"; | ||
return []; | ||
return isArray(value) ? value : [value]; | ||
return isArray(value) ? value.slice() : [value]; | ||
} | ||
@@ -99,9 +99,13 @@ function isGuardHelper(value) { | ||
let prev = Reflect.get((0, import_store.snapshot)(obj), key); | ||
return (0, import_store.subscribe)(obj, () => { | ||
const snap = (0, import_store.snapshot)(obj); | ||
if (!Object.is(prev, snap[key])) { | ||
fn(snap[key]); | ||
prev = Reflect.get(snap, key); | ||
} | ||
}, sync); | ||
return (0, import_store.subscribe)( | ||
obj, | ||
() => { | ||
const snap = (0, import_store.snapshot)(obj); | ||
if (!Object.is(prev, snap[key])) { | ||
fn(snap[key]); | ||
prev = Reflect.get(snap, key); | ||
} | ||
}, | ||
sync | ||
); | ||
} | ||
@@ -233,3 +237,6 @@ | ||
const valueOrFn = delaysMap == null ? void 0 : delaysMap[delay]; | ||
invariant(valueOrFn == null, `[@zag-js/core > determine-delay] Cannot determine delay for \`${delay}\`. It doesn't exist in \`options.delays\``); | ||
invariant( | ||
valueOrFn == null, | ||
`[@zag-js/core > determine-delay] Cannot determine delay for \`${delay}\`. It doesn't exist in \`options.delays\`` | ||
); | ||
return isFunction(valueOrFn) ? valueOrFn(context, event) : valueOrFn; | ||
@@ -309,19 +316,32 @@ } | ||
this.status = "Running" /* Running */; | ||
this.removeStateListener = (0, import_store3.subscribe)(this.state, () => { | ||
this.stateListeners.forEach((listener) => { | ||
listener(this.stateSnapshot); | ||
}); | ||
}, this.sync); | ||
this.removeEventListener = subscribeKey(this.state, "event", (event2) => { | ||
this.executeActions(this.config.onEvent, event2); | ||
this.eventListeners.forEach((listener) => { | ||
listener(event2); | ||
}); | ||
}, this.sync); | ||
this.removeContextListener = (0, import_store3.subscribe)(this.state.context, () => { | ||
this.log("Context:", this.contextSnapshot); | ||
this.contextListeners.forEach((listener) => { | ||
listener(this.contextSnapshot); | ||
}); | ||
}, this.sync || this.options.debug); | ||
this.removeStateListener = (0, import_store3.subscribe)( | ||
this.state, | ||
() => { | ||
this.stateListeners.forEach((listener) => { | ||
listener(this.stateSnapshot); | ||
}); | ||
}, | ||
this.sync | ||
); | ||
this.removeEventListener = subscribeKey( | ||
this.state, | ||
"event", | ||
(event2) => { | ||
this.executeActions(this.config.onEvent, event2); | ||
this.eventListeners.forEach((listener) => { | ||
listener(event2); | ||
}); | ||
}, | ||
this.sync | ||
); | ||
this.removeContextListener = (0, import_store3.subscribe)( | ||
this.state.context, | ||
() => { | ||
this.log("Context:", this.contextSnapshot); | ||
this.contextListeners.forEach((listener) => { | ||
listener(this.contextSnapshot); | ||
}); | ||
}, | ||
this.sync || this.options.debug | ||
); | ||
this.setupContextWatchers(); | ||
@@ -346,5 +366,7 @@ this.executeActivities(toEvent("machine.start" /* Start */), toArray(this.config.activities), "machine.start" /* Start */); | ||
for (const [key, fn] of Object.entries(this.config.watch ?? {})) { | ||
this.contextWatchers.add(subscribeKey(this.state.context, key, () => { | ||
this.executeActions(fn, this.state.event); | ||
})); | ||
this.contextWatchers.add( | ||
subscribeKey(this.state.context, key, () => { | ||
this.executeActions(fn, this.state.event); | ||
}) | ||
); | ||
} | ||
@@ -587,3 +609,6 @@ }; | ||
const fn = isString(action) ? (_a = this.actionMap) == null ? void 0 : _a[action] : action; | ||
warn(isString(action) && !fn, `[@zag-js/core > execute-actions] No implementation found for action: \`${action}\``); | ||
warn( | ||
isString(action) && !fn, | ||
`[@zag-js/core > execute-actions] No implementation found for action: \`${action}\`` | ||
); | ||
fn == null ? void 0 : fn(this.state.context, event, this.meta); | ||
@@ -590,0 +615,0 @@ } |
{ | ||
"name": "@zag-js/core", | ||
"version": "0.0.0-dev-20220714091855", | ||
"version": "0.0.0-dev-20220823143115", | ||
"description": "A minimal implementation of xstate fsm for UI machines", | ||
@@ -31,7 +31,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/store": "0.0.0-dev-20220714091855", | ||
"@zag-js/store": "0.1.1", | ||
"klona": "2.0.5" | ||
}, | ||
"devDependencies": { | ||
"@zag-js/utils": "0.0.0-dev-20220714091855" | ||
"@zag-js/utils": "0.1.3" | ||
}, | ||
@@ -38,0 +38,0 @@ "scripts": { |
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
82644
2043
+ Added@zag-js/store@0.1.1(transitive)
- Removed@zag-js/store@0.0.0-dev-20220714091855(transitive)
Updated@zag-js/store@0.1.1