Socket
Socket
Sign inDemoInstall

@zag-js/core

Package Overview
Dependencies
Maintainers
1
Versions
891
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/core - npm Package Compare versions

Comparing version 0.0.0-dev-20220508184419 to 0.0.0-dev-20220509202935

64

dist/index.js

@@ -44,9 +44,9 @@ var __defProp = Object.defineProperty;

mergeProps: () => mergeProps,
proxy: () => import_vanilla3.proxy,
ref: () => import_vanilla3.ref,
snapshot: () => import_vanilla3.snapshot,
subscribe: () => import_vanilla3.subscribe
proxy: () => import_vanilla4.proxy,
ref: () => import_vanilla4.ref,
snapshot: () => import_vanilla4.snapshot,
subscribe: () => import_vanilla4.subscribe
});
module.exports = __toCommonJS(src_exports);
var import_vanilla3 = require("valtio/vanilla");
var import_vanilla4 = require("valtio/vanilla");

@@ -99,2 +99,3 @@ // ../utilities/core/dist/index.mjs

// src/utils.ts
var import_vanilla = require("valtio/vanilla");
function toEvent(event) {

@@ -112,2 +113,12 @@ const obj = isString(event) ? { type: event } : event;

}
function subscribeKey(obj, key, fn, sync) {
let prev = Reflect.get((0, import_vanilla.snapshot)(obj), key);
return (0, import_vanilla.subscribe)(obj, () => {
const __obj = (0, import_vanilla.snapshot)(obj);
if (!Object.is(prev, __obj[key])) {
fn(__obj[key]);
prev = Reflect.get(__obj, key);
}
}, sync);
}

@@ -182,14 +193,16 @@ // src/guard-utils.ts

var import_json = require("klona/json");
var import_utils9 = require("valtio/utils");
var import_vanilla2 = require("valtio/vanilla");
var import_vanilla3 = require("valtio/vanilla");
// src/create-proxy.ts
var import_vanilla = require("valtio/vanilla");
var import_vanilla2 = require("valtio/vanilla");
var import_utils4 = require("valtio/utils");
function createProxy(config) {
var _a;
const state = (0, import_vanilla.proxy)({
var _a, _b;
const computedContext = (_a = config.computed) != null ? _a : cast({});
const initialContext = (_b = config.context) != null ? _b : cast({});
const state = (0, import_vanilla2.proxy)({
value: "",
previousValue: "",
event: cast({}),
context: (_a = config.context) != null ? _a : cast({}),
context: (0, import_utils4.proxyWithComputed)(initialContext, computedContext),
done: false,

@@ -207,4 +220,4 @@ tags: [],

get nextEvents() {
var _a2, _b, _c, _d;
const stateEvents = (_c = (_b = (_a2 = config.states) == null ? void 0 : _a2[this.value]) == null ? void 0 : _b["on"]) != null ? _c : {};
var _a2, _b2, _c, _d;
const stateEvents = (_c = (_b2 = (_a2 = config.states) == null ? void 0 : _a2[this.value]) == null ? void 0 : _b2["on"]) != null ? _c : {};
const globalEvents = (_d = config == null ? void 0 : config.on) != null ? _d : {};

@@ -280,2 +293,3 @@ return Object.keys(__spreadValues(__spreadValues({}, stateEvents), globalEvents));

this.type = "machine" /* Machine */;
this.deriving = false;
this.activityEvents = /* @__PURE__ */ new Map();

@@ -308,3 +322,3 @@ this.delayedEvents = /* @__PURE__ */ new Map();

this.performStateChangeEffects(info.target, info, event);
this.removeStateListener = (0, import_vanilla2.subscribe)(this.state, () => {
this.removeStateListener = (0, import_vanilla3.subscribe)(this.state, () => {
this.stateListeners.forEach((listener) => {

@@ -314,3 +328,3 @@ listener(this.stateSnapshot);

}, this.sync);
this.removeEventListener = (0, import_utils9.subscribeKey)(this.state, "event", (event2) => {
this.removeEventListener = subscribeKey(this.state, "event", (event2) => {
if (this.config.onEvent) {

@@ -331,3 +345,3 @@ this.executeActions(this.config.onEvent, event2);

for (const [key, fn] of Object.entries((_a = this.config.watch) != null ? _a : {})) {
this.contextWatchers.add((0, import_utils9.subscribeKey)(this.state.context, key, () => {
this.contextWatchers.add(subscribeKey(this.state.context, key, () => {
this.executeActions(fn, this.state.event);

@@ -337,11 +351,2 @@ }));

};
this.setupComputed = () => {
var _a;
const computed = cast((_a = this.config.computed) != null ? _a : {});
const deriveFns = Object.fromEntries(Object.entries(computed).map(([key, fn]) => [key, (get) => fn(get(this.state.context))]));
(0, import_utils9.derive)(deriveFns, { proxy: this.state.context, sync: this.sync || this.options.hookSync });
};
this.detachComputed = () => {
(0, import_utils9.underive)(this.state.context);
};
this.stop = () => {

@@ -361,3 +366,2 @@ if (this.status === "Stopped" /* Stopped */)

this.stopEventListeners();
this.detachComputed();
this.executeActions(this.config.exit, toEvent("machine.stop" /* Stop */));

@@ -435,3 +439,3 @@ this.status = "Stopped" /* Stopped */;

}).start();
return cast((0, import_vanilla2.ref)(actor));
return cast((0, import_vanilla3.ref)(actor));
};

@@ -464,3 +468,2 @@ this.addActivityCleanup = (state, cleanup) => {

this.withContext = (context) => {
this.detachComputed();
const newContext = __spreadValues(__spreadValues({}, this.config.context), context);

@@ -607,3 +610,3 @@ return new Machine(__spreadProps(__spreadValues({}, this.config), { context: newContext }), this.options);

this.setEvent = (event) => {
this.state.event = (0, import_vanilla2.ref)(toEvent(event));
this.state.event = (0, import_vanilla3.ref)(toEvent(event));
};

@@ -733,3 +736,2 @@ this.performExitEffects = (current, event) => {

this.state = createProxy((0, import_json.klona)(config));
this.setupComputed();
const event = toEvent("machine.created" /* Created */);

@@ -739,3 +741,3 @@ this.executeActions(config == null ? void 0 : config.created, event);

get stateSnapshot() {
return cast((0, import_vanilla2.snapshot)(this.state));
return cast((0, import_vanilla3.snapshot)(this.state));
}

@@ -742,0 +744,0 @@ get contextSnapshot() {

@@ -9,2 +9,3 @@ import { Dict, MachineStatus, MachineType, StateMachine as S, Writable } from "./types";

type: MachineType;
private deriving;
private activityEvents;

@@ -31,4 +32,2 @@ private delayedEvents;

private setupContextWatchers;
private setupComputed;
private detachComputed;
stop: () => this;

@@ -35,0 +34,0 @@ private stopEventListeners;

@@ -7,2 +7,3 @@ import type { StateMachine as S } from "./types";

};
export declare function subscribeKey<T extends object, K extends keyof T>(obj: T, key: K, fn: (value: T[K]) => void, sync?: boolean): () => void;
//# sourceMappingURL=utils.d.ts.map
{
"name": "@zag-js/core",
"version": "0.0.0-dev-20220508184419",
"version": "0.0.0-dev-20220509202935",
"description": "A minimal implementation of xstate fsm for UI machines",

@@ -40,3 +40,3 @@ "keywords": [

"dependencies": {
"@zag-js/utils": "0.0.0-dev-20220508184419",
"@zag-js/utils": "0.0.0-dev-20220509202935",
"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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc