@zag-js/core
Advanced tools
Comparing version 0.0.0-dev-20220604123738 to 0.0.0-dev-20220604174031
@@ -35,2 +35,6 @@ var __defProp = Object.defineProperty; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
@@ -277,16 +281,27 @@ // src/index.ts | ||
constructor(config, options) { | ||
this.status = "Not Started" /* NotStarted */; | ||
this.type = "machine" /* Machine */; | ||
this.activityEvents = /* @__PURE__ */ new Map(); | ||
this.delayedEvents = /* @__PURE__ */ new Map(); | ||
this.stateListeners = /* @__PURE__ */ new Set(); | ||
this.contextListeners = /* @__PURE__ */ new Set(); | ||
this.eventListeners = /* @__PURE__ */ new Set(); | ||
this.doneListeners = /* @__PURE__ */ new Set(); | ||
this.contextWatchers = /* @__PURE__ */ new Set(); | ||
this.removeStateListener = noop; | ||
this.removeEventListener = noop; | ||
this.removeContextListener = noop; | ||
this.children = /* @__PURE__ */ new Map(); | ||
this.start = (init) => { | ||
__publicField(this, "status", "Not Started" /* NotStarted */); | ||
__publicField(this, "state"); | ||
__publicField(this, "initialState"); | ||
__publicField(this, "id"); | ||
__publicField(this, "type", "machine" /* Machine */); | ||
__publicField(this, "activityEvents", /* @__PURE__ */ new Map()); | ||
__publicField(this, "delayedEvents", /* @__PURE__ */ new Map()); | ||
__publicField(this, "stateListeners", /* @__PURE__ */ new Set()); | ||
__publicField(this, "contextListeners", /* @__PURE__ */ new Set()); | ||
__publicField(this, "eventListeners", /* @__PURE__ */ new Set()); | ||
__publicField(this, "doneListeners", /* @__PURE__ */ new Set()); | ||
__publicField(this, "contextWatchers", /* @__PURE__ */ new Set()); | ||
__publicField(this, "removeStateListener", noop); | ||
__publicField(this, "removeEventListener", noop); | ||
__publicField(this, "removeContextListener", noop); | ||
__publicField(this, "parent"); | ||
__publicField(this, "children", /* @__PURE__ */ new Map()); | ||
__publicField(this, "guardMap"); | ||
__publicField(this, "actionMap"); | ||
__publicField(this, "delayMap"); | ||
__publicField(this, "activityMap"); | ||
__publicField(this, "sync"); | ||
__publicField(this, "options"); | ||
__publicField(this, "config"); | ||
__publicField(this, "start", (init) => { | ||
if (this.status === "Running" /* Running */) { | ||
@@ -329,4 +344,4 @@ return this; | ||
return this; | ||
}; | ||
this.setupContextWatchers = () => { | ||
}); | ||
__publicField(this, "setupContextWatchers", () => { | ||
var _a; | ||
@@ -338,4 +353,4 @@ for (const [key, fn] of Object.entries((_a = this.config.watch) != null ? _a : {})) { | ||
} | ||
}; | ||
this.stop = () => { | ||
}); | ||
__publicField(this, "stop", () => { | ||
if (this.status === "Stopped" /* Stopped */) | ||
@@ -355,20 +370,20 @@ return; | ||
return this; | ||
}; | ||
this.stopEventListeners = () => { | ||
}); | ||
__publicField(this, "stopEventListeners", () => { | ||
this.eventListeners.clear(); | ||
this.removeEventListener(); | ||
}; | ||
this.stopContextListeners = () => { | ||
}); | ||
__publicField(this, "stopContextListeners", () => { | ||
this.contextListeners.clear(); | ||
this.removeContextListener(); | ||
}; | ||
this.stopStateListeners = () => { | ||
}); | ||
__publicField(this, "stopStateListeners", () => { | ||
this.removeStateListener(); | ||
this.stateListeners.clear(); | ||
}; | ||
this.stopContextWatchers = () => { | ||
}); | ||
__publicField(this, "stopContextWatchers", () => { | ||
this.contextWatchers.forEach((fn) => fn()); | ||
this.contextWatchers.clear(); | ||
}; | ||
this.stopDelayedEvents = () => { | ||
}); | ||
__publicField(this, "stopDelayedEvents", () => { | ||
this.delayedEvents.forEach((state) => { | ||
@@ -378,4 +393,4 @@ state.forEach((stop) => stop()); | ||
this.delayedEvents.clear(); | ||
}; | ||
this.stopActivities = (state) => { | ||
}); | ||
__publicField(this, "stopActivities", (state) => { | ||
var _a, _b; | ||
@@ -393,4 +408,4 @@ if (state) { | ||
} | ||
}; | ||
this.sendChild = (evt, to) => { | ||
}); | ||
__publicField(this, "sendChild", (evt, to) => { | ||
const event = toEvent(evt); | ||
@@ -403,4 +418,4 @@ const id = runIfFn(to, this.contextSnapshot); | ||
child.send(event); | ||
}; | ||
this.stopChild = (id) => { | ||
}); | ||
__publicField(this, "stopChild", (id) => { | ||
if (!this.children.has(id)) { | ||
@@ -411,14 +426,14 @@ invariant(`[@zag-js/core > stop-child] Cannot stop unknown child ${id}`); | ||
this.children.delete(id); | ||
}; | ||
this.removeChild = (id) => { | ||
}); | ||
__publicField(this, "removeChild", (id) => { | ||
this.children.delete(id); | ||
}; | ||
this.stopChildren = () => { | ||
}); | ||
__publicField(this, "stopChildren", () => { | ||
this.children.forEach((child) => child.stop()); | ||
this.children.clear(); | ||
}; | ||
this.setParent = (parent) => { | ||
}); | ||
__publicField(this, "setParent", (parent) => { | ||
this.parent = parent; | ||
}; | ||
this.spawn = (src, id) => { | ||
}); | ||
__publicField(this, "spawn", (src, id) => { | ||
const actor = runIfFn(src); | ||
@@ -434,4 +449,4 @@ if (id) | ||
return cast((0, import_vanilla3.ref)(actor)); | ||
}; | ||
this.addActivityCleanup = (state, cleanup) => { | ||
}); | ||
__publicField(this, "addActivityCleanup", (state, cleanup) => { | ||
var _a; | ||
@@ -445,4 +460,4 @@ if (!state) | ||
} | ||
}; | ||
this.setState = (target) => { | ||
}); | ||
__publicField(this, "setState", (target) => { | ||
this.state.previousValue = this.state.value; | ||
@@ -456,16 +471,16 @@ this.state.value = target; | ||
} | ||
}; | ||
this.setContext = (context) => { | ||
}); | ||
__publicField(this, "setContext", (context) => { | ||
for (const key in context) { | ||
this.state.context[key] = context[key]; | ||
} | ||
}; | ||
this.withContext = (context) => { | ||
}); | ||
__publicField(this, "withContext", (context) => { | ||
const newContext = __spreadValues(__spreadValues({}, this.config.context), context); | ||
return new Machine(__spreadProps(__spreadValues({}, this.config), { context: newContext }), this.options); | ||
}; | ||
this.setActions = (actions) => { | ||
}); | ||
__publicField(this, "setActions", (actions) => { | ||
this.actionMap = __spreadValues(__spreadValues({}, this.actionMap), actions); | ||
}; | ||
this.getStateNode = (state) => { | ||
}); | ||
__publicField(this, "getStateNode", (state) => { | ||
var _a; | ||
@@ -475,4 +490,4 @@ if (!state) | ||
return (_a = this.config.states) == null ? void 0 : _a[state]; | ||
}; | ||
this.getNextStateInfo = (transitions, event) => { | ||
}); | ||
__publicField(this, "getNextStateInfo", (transitions, event) => { | ||
var _a; | ||
@@ -494,4 +509,4 @@ const transition = this.determineTransition(transitions, event); | ||
return info; | ||
}; | ||
this.getActionFromDelayedTransition = (transition) => { | ||
}); | ||
__publicField(this, "getActionFromDelayedTransition", (transition) => { | ||
const event = toEvent("machine.after" /* After */); | ||
@@ -512,4 +527,4 @@ const determineDelay = determineDelayFn(transition.delay, this.delayMap); | ||
}; | ||
}; | ||
this.getDelayedEventActions = (state) => { | ||
}); | ||
__publicField(this, "getDelayedEventActions", (state) => { | ||
const stateNode = this.getStateNode(state); | ||
@@ -547,4 +562,4 @@ const event = toEvent("machine.after" /* After */); | ||
return { entries, exits }; | ||
}; | ||
this.executeActions = (actions, event) => { | ||
}); | ||
__publicField(this, "executeActions", (actions, event) => { | ||
var _a; | ||
@@ -557,4 +572,4 @@ const _actions = determineActionsFn(actions, this.guardMap)(this.contextSnapshot, event, this.guardMeta); | ||
} | ||
}; | ||
this.executeActivities = (event, activities, state) => { | ||
}); | ||
__publicField(this, "executeActivities", (event, activities, state) => { | ||
var _a; | ||
@@ -572,4 +587,4 @@ for (const activity of activities) { | ||
} | ||
}; | ||
this.createEveryActivities = (every, callbackfn) => { | ||
}); | ||
__publicField(this, "createEveryActivities", (every, callbackfn) => { | ||
if (!every) | ||
@@ -616,7 +631,7 @@ return; | ||
} | ||
}; | ||
this.setEvent = (event) => { | ||
}); | ||
__publicField(this, "setEvent", (event) => { | ||
this.state.event = (0, import_vanilla3.ref)(toEvent(event)); | ||
}; | ||
this.performExitEffects = (current, event) => { | ||
}); | ||
__publicField(this, "performExitEffects", (current, event) => { | ||
const currentState = this.state.value; | ||
@@ -633,4 +648,4 @@ const stateNode = current ? this.getStateNode(current) : void 0; | ||
this.eventListeners.clear(); | ||
}; | ||
this.performEntryEffects = (next, event) => { | ||
}); | ||
__publicField(this, "performEntryEffects", (next, event) => { | ||
const stateNode = this.getStateNode(next); | ||
@@ -659,8 +674,8 @@ const activities = toArray(stateNode == null ? void 0 : stateNode.activities); | ||
} | ||
}; | ||
this.performTransitionEffects = (transitions, event) => { | ||
}); | ||
__publicField(this, "performTransitionEffects", (transitions, event) => { | ||
const transition = this.determineTransition(transitions, event); | ||
this.executeActions(transition == null ? void 0 : transition.actions, event); | ||
}; | ||
this.performStateChangeEffects = (current, next, event) => { | ||
}); | ||
__publicField(this, "performStateChangeEffects", (current, next, event) => { | ||
this.setEvent(event); | ||
@@ -676,8 +691,8 @@ const changed = next.changed || next.reenter; | ||
} | ||
}; | ||
this.determineTransition = (transition, event) => { | ||
}); | ||
__publicField(this, "determineTransition", (transition, event) => { | ||
const fn = determineTransitionFn(transition, this.guardMap); | ||
return fn == null ? void 0 : fn(this.contextSnapshot, event, this.guardMeta); | ||
}; | ||
this.sendParent = (evt) => { | ||
}); | ||
__publicField(this, "sendParent", (evt) => { | ||
var _a; | ||
@@ -689,13 +704,13 @@ if (!this.parent) { | ||
(_a = this.parent) == null ? void 0 : _a.send(event); | ||
}; | ||
this.log = (...args) => { | ||
}); | ||
__publicField(this, "log", (...args) => { | ||
if (isDev() && this.options.debug) { | ||
console.log(...args); | ||
} | ||
}; | ||
this.send = (evt) => { | ||
}); | ||
__publicField(this, "send", (evt) => { | ||
const event = toEvent(evt); | ||
this.transition(this.state.value, event); | ||
}; | ||
this.transition = (state, evt) => { | ||
}); | ||
__publicField(this, "transition", (state, evt) => { | ||
var _a, _b, _c; | ||
@@ -713,4 +728,4 @@ const stateNode = isString(state) ? this.getStateNode(state) : state == null ? void 0 : state.stateNode; | ||
return next.stateNode; | ||
}; | ||
this.subscribe = (listener) => { | ||
}); | ||
__publicField(this, "subscribe", (listener) => { | ||
this.stateListeners.add(listener); | ||
@@ -723,8 +738,8 @@ if (this.status === "Running" /* Running */) { | ||
}; | ||
}; | ||
this.onDone = (listener) => { | ||
}); | ||
__publicField(this, "onDone", (listener) => { | ||
this.doneListeners.add(listener); | ||
return this; | ||
}; | ||
this.onTransition = (listener) => { | ||
}); | ||
__publicField(this, "onTransition", (listener) => { | ||
this.stateListeners.add(listener); | ||
@@ -735,11 +750,11 @@ if (this.status === "Running" /* Running */) { | ||
return this; | ||
}; | ||
this.onChange = (listener) => { | ||
}); | ||
__publicField(this, "onChange", (listener) => { | ||
this.contextListeners.add(listener); | ||
return this; | ||
}; | ||
this.onEvent = (listener) => { | ||
}); | ||
__publicField(this, "onEvent", (listener) => { | ||
this.eventListeners.add(listener); | ||
return this; | ||
}; | ||
}); | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l; | ||
@@ -746,0 +761,0 @@ this.config = (0, import_json.klona)(config); |
{ | ||
"name": "@zag-js/core", | ||
"version": "0.0.0-dev-20220604123738", | ||
"version": "0.0.0-dev-20220604174031", | ||
"description": "A minimal implementation of xstate fsm for UI machines", | ||
@@ -40,3 +40,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/utils": "0.0.0-dev-20220604123738", | ||
"@zag-js/utils": "0.0.0-dev-20220604174031", | ||
"klona": "^2.0.5", | ||
@@ -43,0 +43,0 @@ "valtio": "^1.6.0" |
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
236671
2080
+ Added@zag-js/utils@0.0.0-dev-20220604174031(transitive)
- Removed@zag-js/utils@0.0.0-dev-20220604123738(transitive)