@assistant-ui/tap 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ function callResourceFn(resource, props) {
6
6
  }
7
7
  return fn(props);
8
8
  }
9
- var fnSymbol = Symbol("fnSymbol");
9
+ var fnSymbol = /* @__PURE__ */ Symbol("fnSymbol");
10
10
  export {
11
11
  callResourceFn,
12
12
  fnSymbol
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/callResourceFn.ts"],"sourcesContent":["import { Resource } from \"./types\";\n\n/**\n * Renders a resource with the given props.\n * @internal This is for internal use only.\n */\nexport function callResourceFn<R, P>(resource: Resource<R, P>, props: P): R {\n const fn = (resource as unknown as { [fnSymbol]?: (props: P) => R })[\n fnSymbol\n ];\n if (!fn) {\n throw new Error(\"ResourceElement.type is not a valid Resource\");\n }\n return fn(props);\n}\n\n/**\n * Symbol used to store the ResourceFn in the Resource constructor.\n * @internal This is for internal use only.\n */\nexport const fnSymbol = Symbol(\"fnSymbol\");\n"],"mappings":";AAMO,SAAS,eAAqB,UAA0B,OAAa;AAC1E,QAAM,KAAM,SACV,QACF;AACA,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO,GAAG,KAAK;AACjB;AAMO,IAAM,WAAW,OAAO,UAAU;","names":[]}
1
+ {"version":3,"sources":["../../src/core/callResourceFn.ts"],"sourcesContent":["import { Resource } from \"./types\";\n\n/**\n * Renders a resource with the given props.\n * @internal This is for internal use only.\n */\nexport function callResourceFn<R, P>(resource: Resource<R, P>, props: P): R {\n const fn = (resource as unknown as { [fnSymbol]?: (props: P) => R })[\n fnSymbol\n ];\n if (!fn) {\n throw new Error(\"ResourceElement.type is not a valid Resource\");\n }\n return fn(props);\n}\n\n/**\n * Symbol used to store the ResourceFn in the Resource constructor.\n * @internal This is for internal use only.\n */\nexport const fnSymbol = Symbol(\"fnSymbol\");\n"],"mappings":";AAMO,SAAS,eAAqB,UAA0B,OAAa;AAC1E,QAAM,KAAM,SACV,QACF;AACA,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO,GAAG,KAAK;AACjB;AAMO,IAAM,WAAW,uBAAO,UAAU;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../src/core/commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEtD,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GACzB,IAAI,CAuDN;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,QAgB5E"}
1
+ {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../src/core/commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEtD,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GACzB,IAAI,CAiDN;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,QAgB5E"}
@@ -25,19 +25,15 @@ function commitRender(renderResult, fiber) {
25
25
  effectCell.mounted = false;
26
26
  }
27
27
  }
28
- try {
29
- const cleanup = task.effect();
30
- if (cleanup !== void 0 && typeof cleanup !== "function") {
31
- throw new Error(
32
- `An effect function must either return a cleanup function or nothing. Received: ${typeof cleanup}`
33
- );
34
- }
35
- effectCell.mounted = true;
36
- effectCell.cleanup = typeof cleanup === "function" ? cleanup : void 0;
37
- effectCell.deps = task.deps;
38
- } catch (error) {
39
- throw error;
28
+ const cleanup = task.effect();
29
+ if (cleanup !== void 0 && typeof cleanup !== "function") {
30
+ throw new Error(
31
+ `An effect function must either return a cleanup function or nothing. Received: ${typeof cleanup}`
32
+ );
40
33
  }
34
+ effectCell.mounted = true;
35
+ effectCell.cleanup = typeof cleanup === "function" ? cleanup : void 0;
36
+ effectCell.deps = task.deps;
41
37
  }
42
38
  });
43
39
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/commit.ts"],"sourcesContent":["import { ResourceFiber, RenderResult } from \"./types\";\n\nexport function commitRender<R, P>(\n renderResult: RenderResult,\n fiber: ResourceFiber<R, P>,\n): void {\n // Process all tasks collected during render\n renderResult.commitTasks.forEach((task) => {\n const cellIndex = task.cellIndex;\n const effectCell = fiber.cells[cellIndex]!;\n if (effectCell.type !== \"effect\") {\n throw new Error(\"Cannot find effect cell\");\n }\n\n // Check if deps changed\n let shouldRunEffect = true;\n\n if (effectCell.deps !== undefined && task.deps !== undefined) {\n shouldRunEffect =\n effectCell.deps.length !== task.deps.length ||\n effectCell.deps.some((dep, j) => !Object.is(dep, task.deps![j]));\n }\n\n // Run cleanup if effect will re-run\n if (shouldRunEffect) {\n if (effectCell.mounted) {\n if (typeof effectCell.deps !== typeof task.deps) {\n throw new Error(\n \"tapEffect called with and without dependencies across re-renders\",\n );\n }\n\n try {\n if (effectCell.mounted && effectCell.cleanup) {\n effectCell.cleanup();\n }\n } finally {\n effectCell.mounted = false;\n }\n }\n\n try {\n const cleanup = task.effect();\n\n if (cleanup !== undefined && typeof cleanup !== \"function\") {\n throw new Error(\n \"An effect function must either return a cleanup function or nothing. \" +\n `Received: ${typeof cleanup}`,\n );\n }\n\n effectCell.mounted = true;\n effectCell.cleanup =\n typeof cleanup === \"function\" ? cleanup : undefined;\n effectCell.deps = task.deps;\n } catch (error) {\n throw error;\n }\n }\n });\n}\n\nexport function cleanupAllEffects<R, P>(executionContext: ResourceFiber<R, P>) {\n let firstError: unknown | null = null;\n // Run cleanups in reverse order\n for (let i = executionContext.cells.length - 1; i >= 0; i--) {\n const cell = executionContext.cells[i];\n if (cell?.type === \"effect\" && cell.mounted && cell.cleanup) {\n try {\n cell.cleanup();\n } catch (e) {\n if (firstError == null) firstError = e;\n } finally {\n cell.mounted = false;\n }\n }\n }\n if (firstError != null) throw firstError;\n}\n"],"mappings":";AAEO,SAAS,aACd,cACA,OACM;AAEN,eAAa,YAAY,QAAQ,CAAC,SAAS;AACzC,UAAM,YAAY,KAAK;AACvB,UAAM,aAAa,MAAM,MAAM,SAAS;AACxC,QAAI,WAAW,SAAS,UAAU;AAChC,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AAGA,QAAI,kBAAkB;AAEtB,QAAI,WAAW,SAAS,UAAa,KAAK,SAAS,QAAW;AAC5D,wBACE,WAAW,KAAK,WAAW,KAAK,KAAK,UACrC,WAAW,KAAK,KAAK,CAAC,KAAK,MAAM,CAAC,OAAO,GAAG,KAAK,KAAK,KAAM,CAAC,CAAC,CAAC;AAAA,IACnE;AAGA,QAAI,iBAAiB;AACnB,UAAI,WAAW,SAAS;AACtB,YAAI,OAAO,WAAW,SAAS,OAAO,KAAK,MAAM;AAC/C,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AACF,cAAI,WAAW,WAAW,WAAW,SAAS;AAC5C,uBAAW,QAAQ;AAAA,UACrB;AAAA,QACF,UAAE;AACA,qBAAW,UAAU;AAAA,QACvB;AAAA,MACF;AAEA,UAAI;AACF,cAAM,UAAU,KAAK,OAAO;AAE5B,YAAI,YAAY,UAAa,OAAO,YAAY,YAAY;AAC1D,gBAAM,IAAI;AAAA,YACR,kFACe,OAAO,OAAO;AAAA,UAC/B;AAAA,QACF;AAEA,mBAAW,UAAU;AACrB,mBAAW,UACT,OAAO,YAAY,aAAa,UAAU;AAC5C,mBAAW,OAAO,KAAK;AAAA,MACzB,SAAS,OAAO;AACd,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,SAAS,kBAAwB,kBAAuC;AAC7E,MAAI,aAA6B;AAEjC,WAAS,IAAI,iBAAiB,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3D,UAAM,OAAO,iBAAiB,MAAM,CAAC;AACrC,QAAI,MAAM,SAAS,YAAY,KAAK,WAAW,KAAK,SAAS;AAC3D,UAAI;AACF,aAAK,QAAQ;AAAA,MACf,SAAS,GAAG;AACV,YAAI,cAAc,KAAM,cAAa;AAAA,MACvC,UAAE;AACA,aAAK,UAAU;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,MAAI,cAAc,KAAM,OAAM;AAChC;","names":[]}
1
+ {"version":3,"sources":["../../src/core/commit.ts"],"sourcesContent":["import { ResourceFiber, RenderResult } from \"./types\";\n\nexport function commitRender<R, P>(\n renderResult: RenderResult,\n fiber: ResourceFiber<R, P>,\n): void {\n // Process all tasks collected during render\n renderResult.commitTasks.forEach((task) => {\n const cellIndex = task.cellIndex;\n const effectCell = fiber.cells[cellIndex]!;\n if (effectCell.type !== \"effect\") {\n throw new Error(\"Cannot find effect cell\");\n }\n\n // Check if deps changed\n let shouldRunEffect = true;\n\n if (effectCell.deps !== undefined && task.deps !== undefined) {\n shouldRunEffect =\n effectCell.deps.length !== task.deps.length ||\n effectCell.deps.some((dep, j) => !Object.is(dep, task.deps![j]));\n }\n\n // Run cleanup if effect will re-run\n if (shouldRunEffect) {\n if (effectCell.mounted) {\n if (typeof effectCell.deps !== typeof task.deps) {\n throw new Error(\n \"tapEffect called with and without dependencies across re-renders\",\n );\n }\n\n try {\n if (effectCell.mounted && effectCell.cleanup) {\n effectCell.cleanup();\n }\n } finally {\n effectCell.mounted = false;\n }\n }\n const cleanup = task.effect();\n\n if (cleanup !== undefined && typeof cleanup !== \"function\") {\n throw new Error(\n \"An effect function must either return a cleanup function or nothing. \" +\n `Received: ${typeof cleanup}`,\n );\n }\n\n effectCell.mounted = true;\n effectCell.cleanup = typeof cleanup === \"function\" ? cleanup : undefined;\n effectCell.deps = task.deps;\n }\n });\n}\n\nexport function cleanupAllEffects<R, P>(executionContext: ResourceFiber<R, P>) {\n let firstError: unknown | null = null;\n // Run cleanups in reverse order\n for (let i = executionContext.cells.length - 1; i >= 0; i--) {\n const cell = executionContext.cells[i];\n if (cell?.type === \"effect\" && cell.mounted && cell.cleanup) {\n try {\n cell.cleanup();\n } catch (e) {\n if (firstError == null) firstError = e;\n } finally {\n cell.mounted = false;\n }\n }\n }\n if (firstError != null) throw firstError;\n}\n"],"mappings":";AAEO,SAAS,aACd,cACA,OACM;AAEN,eAAa,YAAY,QAAQ,CAAC,SAAS;AACzC,UAAM,YAAY,KAAK;AACvB,UAAM,aAAa,MAAM,MAAM,SAAS;AACxC,QAAI,WAAW,SAAS,UAAU;AAChC,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AAGA,QAAI,kBAAkB;AAEtB,QAAI,WAAW,SAAS,UAAa,KAAK,SAAS,QAAW;AAC5D,wBACE,WAAW,KAAK,WAAW,KAAK,KAAK,UACrC,WAAW,KAAK,KAAK,CAAC,KAAK,MAAM,CAAC,OAAO,GAAG,KAAK,KAAK,KAAM,CAAC,CAAC,CAAC;AAAA,IACnE;AAGA,QAAI,iBAAiB;AACnB,UAAI,WAAW,SAAS;AACtB,YAAI,OAAO,WAAW,SAAS,OAAO,KAAK,MAAM;AAC/C,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AACF,cAAI,WAAW,WAAW,WAAW,SAAS;AAC5C,uBAAW,QAAQ;AAAA,UACrB;AAAA,QACF,UAAE;AACA,qBAAW,UAAU;AAAA,QACvB;AAAA,MACF;AACA,YAAM,UAAU,KAAK,OAAO;AAE5B,UAAI,YAAY,UAAa,OAAO,YAAY,YAAY;AAC1D,cAAM,IAAI;AAAA,UACR,kFACe,OAAO,OAAO;AAAA,QAC/B;AAAA,MACF;AAEA,iBAAW,UAAU;AACrB,iBAAW,UAAU,OAAO,YAAY,aAAa,UAAU;AAC/D,iBAAW,OAAO,KAAK;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,kBAAwB,kBAAuC;AAC7E,MAAI,aAA6B;AAEjC,WAAS,IAAI,iBAAiB,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3D,UAAM,OAAO,iBAAiB,MAAM,CAAC;AACrC,QAAI,MAAM,SAAS,YAAY,KAAK,WAAW,KAAK,SAAS;AAC3D,UAAI;AACF,aAAK,QAAQ;AAAA,MACf,SAAS,GAAG;AACV,YAAI,cAAc,KAAM,cAAa;AAAA,MACvC,UAAE;AACA,aAAK,UAAU;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,MAAI,cAAc,KAAM,OAAM;AAChC;","names":[]}
@@ -1,5 +1,5 @@
1
1
  // src/core/context.ts
2
- var contextValue = Symbol("tap.Context");
2
+ var contextValue = /* @__PURE__ */ Symbol("tap.Context");
3
3
  var createContext = (defaultValue) => {
4
4
  return {
5
5
  [contextValue]: defaultValue
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/context.ts"],"sourcesContent":["const contextValue: unique symbol = Symbol(\"tap.Context\");\ntype Context<T> = {\n [contextValue]: T;\n};\n\nexport const createContext = <T>(defaultValue: T): Context<T> => {\n return {\n [contextValue]: defaultValue,\n };\n};\n\nexport const withContextProvider = <T, TResult>(\n context: Context<T>,\n value: T,\n fn: () => TResult,\n) => {\n const previousValue = context[contextValue];\n context[contextValue] = value;\n try {\n return fn();\n } finally {\n context[contextValue] = previousValue;\n }\n};\n\nexport const tapContext = <T>(context: Context<T>) => {\n return context[contextValue];\n};\n"],"mappings":";AAAA,IAAM,eAA8B,OAAO,aAAa;AAKjD,IAAM,gBAAgB,CAAI,iBAAgC;AAC/D,SAAO;AAAA,IACL,CAAC,YAAY,GAAG;AAAA,EAClB;AACF;AAEO,IAAM,sBAAsB,CACjC,SACA,OACA,OACG;AACH,QAAM,gBAAgB,QAAQ,YAAY;AAC1C,UAAQ,YAAY,IAAI;AACxB,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,YAAQ,YAAY,IAAI;AAAA,EAC1B;AACF;AAEO,IAAM,aAAa,CAAI,YAAwB;AACpD,SAAO,QAAQ,YAAY;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../../src/core/context.ts"],"sourcesContent":["const contextValue: unique symbol = Symbol(\"tap.Context\");\ntype Context<T> = {\n [contextValue]: T;\n};\n\nexport const createContext = <T>(defaultValue: T): Context<T> => {\n return {\n [contextValue]: defaultValue,\n };\n};\n\nexport const withContextProvider = <T, TResult>(\n context: Context<T>,\n value: T,\n fn: () => TResult,\n) => {\n const previousValue = context[contextValue];\n context[contextValue] = value;\n try {\n return fn();\n } finally {\n context[contextValue] = previousValue;\n }\n};\n\nexport const tapContext = <T>(context: Context<T>) => {\n return context[contextValue];\n};\n"],"mappings":";AAAA,IAAM,eAA8B,uBAAO,aAAa;AAKjD,IAAM,gBAAgB,CAAI,iBAAgC;AAC/D,SAAO;AAAA,IACL,CAAC,YAAY,GAAG;AAAA,EAClB;AACF;AAEO,IAAM,sBAAsB,CACjC,SACA,OACA,OACG;AACH,QAAM,gBAAgB,QAAQ,YAAY;AAC1C,UAAQ,YAAY,IAAI;AACxB,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,YAAQ,YAAY,IAAI;AAAA,EAC1B;AACF;AAEO,IAAM,aAAa,CAAI,YAAwB;AACpD,SAAO,QAAQ,YAAY;AAC7B;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/tap",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "Zero-dependency reactive state management inspired by React hooks",
6
6
  "main": "dist/index.js",
@@ -20,10 +20,10 @@
20
20
  "devDependencies": {
21
21
  "@types/node": "^24.10.1",
22
22
  "@types/react": "*",
23
- "@vitest/ui": "^4.0.14",
24
- "tsx": "^4.20.6",
23
+ "@vitest/ui": "^4.0.15",
24
+ "tsx": "^4.21.0",
25
25
  "typescript": "^5.9.3",
26
- "vitest": "^4.0.14",
26
+ "vitest": "^4.0.15",
27
27
  "@assistant-ui/x-buildutils": "0.0.1"
28
28
  },
29
29
  "exports": {
@@ -52,7 +52,6 @@
52
52
  },
53
53
  "scripts": {
54
54
  "build": "tsx build.mts",
55
- "lint": "eslint .",
56
55
  "test": "vitest",
57
56
  "test:run": "vitest run"
58
57
  }