@assistant-ui/tap 0.5.13 → 0.5.14
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.
- package/dist/core/ResourceFiber.d.ts.map +1 -1
- package/dist/core/helpers/commit.d.ts.map +1 -1
- package/dist/core/helpers/execution-context.d.ts.map +1 -1
- package/dist/core/helpers/root.d.ts.map +1 -1
- package/dist/core/helpers/root.js.map +1 -1
- package/dist/core/resource.d.ts.map +1 -1
- package/dist/core/scheduler.d.ts.map +1 -1
- package/dist/core/withKey.d.ts.map +1 -1
- package/dist/hooks/tap-const.d.ts.map +1 -1
- package/dist/hooks/tap-effect-event.d.ts.map +1 -1
- package/dist/hooks/tap-reducer.d.ts.map +1 -1
- package/dist/hooks/tap-ref.d.ts.map +1 -1
- package/dist/hooks/tap-resource.d.ts.map +1 -1
- package/dist/hooks/tap-resources.d.ts.map +1 -1
- package/dist/hooks/tap-state.d.ts.map +1 -1
- package/dist/react/use-resource.d.ts.map +1 -1
- package/dist/tapResourceRoot.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/basic/tapEffect.basic.test.ts +0 -2
- package/src/__tests__/lifecycle/lifecycle.mount-unmount.test.ts +0 -3
- package/src/__tests__/strictmode/react-strictmode-behavior.test.tsx +0 -3
- package/src/__tests__/strictmode/tap-strictmode-rerender-sources.test.ts +0 -3
- package/src/__tests__/test-utils.ts +0 -1
- package/src/core/helpers/root.ts +0 -1
- package/src/tapResourceRoot.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceFiber.d.ts","names":[],"sources":["../../src/core/ResourceFiber.ts"],"mappings":";;;iBAcgB,mBAAA,
|
|
1
|
+
{"version":3,"file":"ResourceFiber.d.ts","names":[],"sources":["../../src/core/ResourceFiber.ts"],"mappings":";;;iBAcgB,mBAAA,OACd,IAAA,EAAM,QAAA,CAAS,CAAA,EAAG,CAAA,GAClB,IAAA,EAAM,iBAAA,EACN,SAAA,6BACA,UAAA,6BACC,aAAA,CAAc,CAAA,EAAG,CAAA;AAAA,iBAeJ,oBAAA,OAA2B,KAAA,EAAO,aAAA,CAAc,CAAA,EAAG,CAAA;AAAA,iBAQnD,mBAAA,OACd,KAAA,EAAO,aAAA,CAAc,CAAA,EAAG,CAAA,GACxB,KAAA,EAAO,CAAA,GACN,YAAA;AAAA,iBAmBa,mBAAA,OACd,KAAA,EAAO,aAAA,CAAc,CAAA,EAAG,CAAA,GACxB,MAAA,EAAQ,YAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit.d.ts","names":[],"sources":["../../../src/core/helpers/commit.ts"],"mappings":";;;iBAEgB,gBAAA,CAAiB,YAA0B,EAAZ,YAAY;AAAA,iBAuB3C,iBAAA,
|
|
1
|
+
{"version":3,"file":"commit.d.ts","names":[],"sources":["../../../src/core/helpers/commit.ts"],"mappings":";;;iBAEgB,gBAAA,CAAiB,YAA0B,EAAZ,YAAY;AAAA,iBAuB3C,iBAAA,OAAwB,gBAAA,EAAkB,aAAA,CAAc,CAAA,EAAG,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-context.d.ts","names":[],"sources":["../../../src/core/helpers/execution-context.ts"],"mappings":";;;iBAKgB,iBAAA,
|
|
1
|
+
{"version":3,"file":"execution-context.d.ts","names":[],"sources":["../../../src/core/helpers/execution-context.ts"],"mappings":";;;iBAKgB,iBAAA,OACd,KAAA,EAAO,aAAA,CAAc,CAAA,EAAG,CAAA,GACxB,EAAA;AAAA,iBAsBc,uBAAA,IAA2B,aAAa;AAAA,iBAOxC,gBAAA,CAAiB,MAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","names":[],"sources":["../../../src/core/helpers/root.ts"],"mappings":";;;cAEa,uBAAA,GACX,cAAA,GAAiB,EAAA,6BAChB,iBAQF;AAAA,cAEY,UAAA,GAAc,IAAuB,EAAjB,iBAAiB;AAAA,cAWrC,cAAA,GACX,IAAA,EAAM,iBAAiB,EACvB,OAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"root.d.ts","names":[],"sources":["../../../src/core/helpers/root.ts"],"mappings":";;;cAEa,uBAAA,GACX,cAAA,GAAiB,EAAA,6BAChB,iBAQF;AAAA,cAEY,UAAA,GAAc,IAAuB,EAAjB,iBAAiB;AAAA,cAWrC,cAAA,GACX,IAAA,EAAM,iBAAiB,EACvB,OAAA;AAAA,cA8BW,aAAA,GACX,KAAA,EAAO,aAAA,YACP,IAAA,EAAM,IAAI;EAAK,IAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","names":[],"sources":["../../../src/core/helpers/root.ts"],"sourcesContent":["import type { Cell, ResourceFiber, ResourceFiberRoot } from \"../types\";\n\nexport const createResourceFiberRoot = (\n dispatchUpdate: (cb: () => boolean) => void,\n): ResourceFiberRoot => {\n return {\n version: 0,\n committedVersion: 0,\n dispatchUpdate,\n changelog: [],\n dirtyCells: [],\n };\n};\n\nexport const commitRoot = (root: ResourceFiberRoot): void => {\n for (const cell of root.dirtyCells) {\n cell.dirty = false;\n cell.queue.clear();\n cell.current = cell.workInProgress;\n }\n root.committedVersion = root.version;\n root.changelog.length = 0;\n root.dirtyCells.length = 0;\n};\n\nexport const setRootVersion = (\n root: ResourceFiberRoot,\n version: number,\n): void => {\n const rollback = root.version > version;\n root.version = version;\n if (rollback) {\n for (const cell of root.dirtyCells) {\n cell.dirty = false;\n cell.queue.clear();\n cell.workInProgress = cell.current;\n }\n root.dirtyCells.length = 0;\n\n if (version === root.committedVersion) {\n root.changelog.length = 0;\n } else {\n // commit happened without a useEffect update (offscreen API)\n\n if (root.committedVersion > version)\n throw new Error(\"Version is less than committed version\");\n\n while (root.committedVersion + root.changelog.length > version) {\n root.changelog.pop();\n }\n\n
|
|
1
|
+
{"version":3,"file":"root.js","names":[],"sources":["../../../src/core/helpers/root.ts"],"sourcesContent":["import type { Cell, ResourceFiber, ResourceFiberRoot } from \"../types\";\n\nexport const createResourceFiberRoot = (\n dispatchUpdate: (cb: () => boolean) => void,\n): ResourceFiberRoot => {\n return {\n version: 0,\n committedVersion: 0,\n dispatchUpdate,\n changelog: [],\n dirtyCells: [],\n };\n};\n\nexport const commitRoot = (root: ResourceFiberRoot): void => {\n for (const cell of root.dirtyCells) {\n cell.dirty = false;\n cell.queue.clear();\n cell.current = cell.workInProgress;\n }\n root.committedVersion = root.version;\n root.changelog.length = 0;\n root.dirtyCells.length = 0;\n};\n\nexport const setRootVersion = (\n root: ResourceFiberRoot,\n version: number,\n): void => {\n const rollback = root.version > version;\n root.version = version;\n if (rollback) {\n for (const cell of root.dirtyCells) {\n cell.dirty = false;\n cell.queue.clear();\n cell.workInProgress = cell.current;\n }\n root.dirtyCells.length = 0;\n\n if (version === root.committedVersion) {\n root.changelog.length = 0;\n } else {\n // commit happened without a useEffect update (offscreen API)\n\n if (root.committedVersion > version)\n throw new Error(\"Version is less than committed version\");\n\n while (root.committedVersion + root.changelog.length > version) {\n root.changelog.pop();\n }\n\n root.changelog.forEach((apply) => apply());\n commitRoot(root);\n }\n }\n};\n\nexport const markCellDirty = (\n fiber: ResourceFiber<any, any>,\n cell: Cell & { type: \"reducer\" },\n): void => {\n if (!cell.dirty) {\n cell.dirty = true;\n fiber.markDirty?.();\n fiber.root.dirtyCells.push(cell);\n }\n};\n"],"mappings":";AAEA,MAAa,2BACX,mBACsB;CACtB,OAAO;EACL,SAAS;EACT,kBAAkB;EAClB;EACA,WAAW,CAAC;EACZ,YAAY,CAAC;CACf;AACF;AAEA,MAAa,cAAc,SAAkC;CAC3D,KAAK,MAAM,QAAQ,KAAK,YAAY;EAClC,KAAK,QAAQ;EACb,KAAK,MAAM,MAAM;EACjB,KAAK,UAAU,KAAK;CACtB;CACA,KAAK,mBAAmB,KAAK;CAC7B,KAAK,UAAU,SAAS;CACxB,KAAK,WAAW,SAAS;AAC3B;AAEA,MAAa,kBACX,MACA,YACS;CACT,MAAM,WAAW,KAAK,UAAU;CAChC,KAAK,UAAU;CACf,IAAI,UAAU;EACZ,KAAK,MAAM,QAAQ,KAAK,YAAY;GAClC,KAAK,QAAQ;GACb,KAAK,MAAM,MAAM;GACjB,KAAK,iBAAiB,KAAK;EAC7B;EACA,KAAK,WAAW,SAAS;EAEzB,IAAI,YAAY,KAAK,kBACnB,KAAK,UAAU,SAAS;OACnB;GAGL,IAAI,KAAK,mBAAmB,SAC1B,MAAM,IAAI,MAAM,wCAAwC;GAE1D,OAAO,KAAK,mBAAmB,KAAK,UAAU,SAAS,SACrD,KAAK,UAAU,IAAI;GAGrB,KAAK,UAAU,SAAS,UAAU,MAAM,CAAC;GACzC,WAAW,IAAI;EACjB;CACF;AACF;AAEA,MAAa,iBACX,OACA,SACS;CACT,IAAI,CAAC,KAAK,OAAO;EACf,KAAK,QAAQ;EACb,MAAM,YAAY;EAClB,MAAM,KAAK,WAAW,KAAK,IAAI;CACjC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","names":[],"sources":["../../src/core/resource.ts"],"mappings":";;;iBAGgB,QAAA,
|
|
1
|
+
{"version":3,"file":"resource.d.ts","names":[],"sources":["../../src/core/resource.ts"],"mappings":";;;iBAGgB,QAAA,IAAY,EAAA,QAAU,CAAA,SAAU,eAAA,CAAgB,CAAA;AAAA,iBAChD,QAAA,OACd,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA,IAChB,KAAA,EAAO,CAAA,KAAM,eAAA,CAAgB,CAAA,EAAG,CAAA;AAAA,iBACpB,QAAA,OACd,EAAA,GAAK,KAAA,GAAQ,CAAA,KAAM,CAAA,IACjB,KAAA,GAAQ,CAAA,KAAM,eAAA,CAAgB,CAAA,EAAG,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","names":[],"sources":["../../src/core/scheduler.ts"],"mappings":";KAAK,IAAA;AAAA,cAaQ,eAAA;EAAA,iBAGkB,KAAA;EAAA,QAFrB,QAAA;cAEqB,KAAA,EAAO,IAAI;EAAA,IAEpC,OAAA
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","names":[],"sources":["../../src/core/scheduler.ts"],"mappings":";KAAK,IAAA;AAAA,cAaQ,eAAA;EAAA,iBAGkB,KAAA;EAAA,QAFrB,QAAA;cAEqB,KAAA,EAAO,IAAI;EAAA,IAEpC,OAAA;EAIJ,SAAA;EAOA,OAAA;AAAA;AAAA,cAiEW,kBAAA,MAAyB,QAAA,QAAgB,CAAA,KAAI,CAezD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withKey.d.ts","names":[],"sources":["../../src/core/withKey.ts"],"mappings":";;;iBAEgB,OAAA,WAAkB,eAAA,
|
|
1
|
+
{"version":3,"file":"withKey.d.ts","names":[],"sources":["../../src/core/withKey.ts"],"mappings":";;;iBAEgB,OAAA,WAAkB,eAAA,YAChC,GAAA,mBACA,OAAA,EAAS,CAAA,GACR,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-const.d.ts","names":[],"sources":["../../src/hooks/tap-const.ts"],"mappings":";iBAEgB,QAAA,
|
|
1
|
+
{"version":3,"file":"tap-const.d.ts","names":[],"sources":["../../src/hooks/tap-const.ts"],"mappings":";iBAEgB,QAAA,IAAY,QAAA,QAAgB,CAAA,EAAG,KAAA,qBAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-effect-event.d.ts","names":[],"sources":["../../src/hooks/tap-effect-event.ts"],"mappings":";;AAqBA;;;;;;;;;;AAEI;;;;iBAFY,cAAA,eAA6B,IAAA,
|
|
1
|
+
{"version":3,"file":"tap-effect-event.d.ts","names":[],"sources":["../../src/hooks/tap-effect-event.ts"],"mappings":";;AAqBA;;;;;;;;;;AAEI;;;;iBAFY,cAAA,eAA6B,IAAA,iBAC3C,QAAA,EAAU,CAAA,GACT,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-reducer.d.ts","names":[],"sources":["../../src/hooks/tap-reducer.ts"],"mappings":";KAMK,QAAA,OAAe,MAAA,EAAQ,CAAC;AAAA,iBAqGb,UAAA,
|
|
1
|
+
{"version":3,"file":"tap-reducer.d.ts","names":[],"sources":["../../src/hooks/tap-reducer.ts"],"mappings":";KAMK,QAAA,OAAe,MAAA,EAAQ,CAAC;AAAA,iBAqGb,UAAA,OACd,OAAA,GAAU,KAAA,EAAO,CAAA,EAAG,MAAA,EAAQ,CAAA,KAAM,CAAA,EAClC,YAAA,EAAc,CAAA,IACZ,CAAA,EAAG,QAAA,CAAS,CAAA;AAAA,iBACA,UAAA,UACd,OAAA,GAAU,KAAA,EAAO,CAAA,EAAG,MAAA,EAAQ,CAAA,KAAM,CAAA,EAClC,UAAA,EAAY,CAAA,EACZ,IAAA,GAAO,GAAA,EAAK,CAAA,KAAM,CAAA,IAChB,CAAA,EAAG,QAAA,CAAS,CAAA;AAAA,iBAcA,0BAAA,iBAA2C,CAAA,EACzD,OAAA,GAAU,KAAA,EAAO,CAAA,EAAG,MAAA,EAAQ,CAAA,KAAM,CAAA,EAClC,eAAA,GAAkB,KAAA,EAAO,CAAA,KAAM,CAAA,EAC/B,YAAA,EAAc,CAAA,IACZ,CAAA,EAAG,QAAA,CAAS,CAAA;AAAA,iBACA,0BAAA,oBAA8C,CAAA,EAC5D,OAAA,GAAU,KAAA,EAAO,CAAA,EAAG,MAAA,EAAQ,CAAA,KAAM,CAAA,EAClC,eAAA,GAAkB,KAAA,EAAO,CAAA,KAAM,CAAA,EAC/B,UAAA,EAAY,CAAA,EACZ,IAAA,GAAO,GAAA,EAAK,CAAA,KAAM,CAAA,IAChB,CAAA,EAAG,QAAA,CAAS,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-ref.d.ts","names":[],"sources":["../../src/hooks/tap-ref.ts"],"mappings":";kBAEiB,MAAA;EAAA,UACE,SAAA;IACf,OAAA,EAAS,CAAC;EAAA;AAAA;AAAA,iBAIE,MAAA,
|
|
1
|
+
{"version":3,"file":"tap-ref.d.ts","names":[],"sources":["../../src/hooks/tap-ref.ts"],"mappings":";kBAEiB,MAAA;EAAA,UACE,SAAA;IACf,OAAA,EAAS,CAAC;EAAA;AAAA;AAAA,iBAIE,MAAA,IAAU,YAAA,EAAc,CAAA,GAAI,MAAA,CAAO,SAAA,CAAU,CAAA;AAAA,iBAC7C,MAAA,mBAAyB,MAAA,CAAO,SAAS,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-resource.d.ts","names":[],"sources":["../../src/hooks/tap-resource.ts"],"mappings":";;;iBAYgB,WAAA,WAAsB,eAAA,
|
|
1
|
+
{"version":3,"file":"tap-resource.d.ts","names":[],"sources":["../../src/hooks/tap-resource.ts"],"mappings":";;;iBAYgB,WAAA,WAAsB,eAAA,YACpC,OAAA,EAAS,CAAA,GACR,yBAAA,CAA0B,CAAA;AAAA,iBACb,WAAA,WAAsB,eAAA,YACpC,OAAA,EAAS,CAAA,EACT,SAAA,uBACC,yBAAA,CAA0B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-resources.d.ts","names":[],"sources":["../../src/hooks/tap-resources.ts"],"mappings":";;;iBA2BgB,YAAA,WAAuB,eAAA,
|
|
1
|
+
{"version":3,"file":"tap-resources.d.ts","names":[],"sources":["../../src/hooks/tap-resources.ts"],"mappings":";;;iBA2BgB,YAAA,WAAuB,eAAA,YACrC,WAAA,iBAA4B,CAAA,IAC5B,eAAA,wBACC,yBAAA,CAA0B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-state.d.ts","names":[],"sources":["../../src/hooks/tap-state.ts"],"mappings":";kBAEiB,QAAA;EAAA,KACH,YAAA,MAAkB,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA;AAAA,iBAclC,QAAA,
|
|
1
|
+
{"version":3,"file":"tap-state.d.ts","names":[],"sources":["../../src/hooks/tap-state.ts"],"mappings":";kBAEiB,QAAA;EAAA,KACH,YAAA,MAAkB,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA;AAAA,iBAclC,QAAA,oBACd,CAAA,eACC,OAAA,EAAS,QAAA,CAAS,YAAA,CAAa,CAAA;AAAA,iBAElB,QAAA,IACd,OAAA,EAAS,CAAA,UAAW,CAAA,KAClB,CAAA,GAAI,OAAA,EAAS,QAAA,CAAS,YAAA,CAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-resource.d.ts","names":[],"sources":["../../src/react/use-resource.ts"],"mappings":";;;iBA+BgB,WAAA,WAAsB,eAAA,
|
|
1
|
+
{"version":3,"file":"use-resource.d.ts","names":[],"sources":["../../src/react/use-resource.ts"],"mappings":";;;iBA+BgB,WAAA,WAAsB,eAAA,YACpC,OAAA,EAAS,CAAA,GACR,yBAAA,CAA0B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tapResourceRoot.js","names":[],"sources":["../src/tapResourceRoot.ts"],"sourcesContent":["import {\n commitResourceFiber,\n createResourceFiber,\n renderResourceFiber,\n unmountResourceFiber,\n} from \"./core/ResourceFiber\";\nimport { UpdateScheduler } from \"./core/scheduler\";\nimport { tapConst } from \"./hooks/tap-const\";\nimport { tapMemo } from \"./hooks/tap-memo\";\nimport { tapEffect } from \"./hooks/tap-effect\";\nimport { tapEffectEvent } from \"./hooks/tap-effect-event\";\nimport { tapRef } from \"./hooks/tap-ref\";\nimport type { RenderResult, ResourceElement } from \"./core/types\";\nimport { isDevelopment } from \"./core/helpers/env\";\nimport {\n commitRoot,\n createResourceFiberRoot,\n setRootVersion,\n} from \"./core/helpers/root\";\n\nexport namespace tapResourceRoot {\n export type Unsubscribe = () => void;\n\n export interface SubscribableResource<TState> {\n /**\n * Get the current state of the store.\n */\n getValue(): TState;\n\n /**\n * Subscribe to the store.\n */\n subscribe(listener: () => void): Unsubscribe;\n }\n}\n\n// currently we never reset the root, because rollbakcs are not supported in tapResourceRoot\n\nexport const tapResourceRoot = <TState>(\n element: ResourceElement<TState>,\n): tapResourceRoot.SubscribableResource<TState> => {\n const scheduler = tapConst(\n () => new UpdateScheduler(() => handleUpdate(null)),\n [],\n );\n const queue = tapConst(() => [] as (() => void)[], []);\n\n const fiber = tapMemo(() => {\n void element.key;\n\n return createResourceFiber(\n element.type,\n createResourceFiberRoot((callback) => {\n if (!scheduler.isDirty && !callback()) return;\n queue.push(callback);\n scheduler.markDirty();\n }),\n );\n }, [element.type, element.key]);\n\n setRootVersion(fiber.root, fiber.root.committedVersion);\n const render = renderResourceFiber(fiber, element.props);\n\n const isMountedRef = tapRef(false);\n const committedPropsRef = tapRef(element.props);\n const valueRef = tapRef<TState>(render.output);\n const subscribers = tapConst(() => new Set<() => void>(), []);\n const handleUpdate = tapEffectEvent((render: RenderResult | null) => {\n if (render === null) {\n setRootVersion(fiber.root, 2);\n setRootVersion(fiber.root, 1);\n\n queue.forEach((callback) => {\n if (isDevelopment && fiber.devStrictMode) {\n callback();\n }\n\n callback();\n });\n\n if (isDevelopment && fiber.devStrictMode) {\n void renderResourceFiber(fiber, committedPropsRef.current);\n }\n\n render = renderResourceFiber(fiber, committedPropsRef.current);\n }\n\n if (scheduler.isDirty)\n throw new Error(\"Scheduler is dirty, this should never happen\");\n\n commitRoot(fiber.root);\n queue.length = 0;\n\n if (isMountedRef.current) {\n commitResourceFiber(fiber, render);\n }\n\n if (scheduler.isDirty || valueRef.current === render.output) return;\n valueRef.current = render.output;\n
|
|
1
|
+
{"version":3,"file":"tapResourceRoot.js","names":[],"sources":["../src/tapResourceRoot.ts"],"sourcesContent":["import {\n commitResourceFiber,\n createResourceFiber,\n renderResourceFiber,\n unmountResourceFiber,\n} from \"./core/ResourceFiber\";\nimport { UpdateScheduler } from \"./core/scheduler\";\nimport { tapConst } from \"./hooks/tap-const\";\nimport { tapMemo } from \"./hooks/tap-memo\";\nimport { tapEffect } from \"./hooks/tap-effect\";\nimport { tapEffectEvent } from \"./hooks/tap-effect-event\";\nimport { tapRef } from \"./hooks/tap-ref\";\nimport type { RenderResult, ResourceElement } from \"./core/types\";\nimport { isDevelopment } from \"./core/helpers/env\";\nimport {\n commitRoot,\n createResourceFiberRoot,\n setRootVersion,\n} from \"./core/helpers/root\";\n\nexport namespace tapResourceRoot {\n export type Unsubscribe = () => void;\n\n export interface SubscribableResource<TState> {\n /**\n * Get the current state of the store.\n */\n getValue(): TState;\n\n /**\n * Subscribe to the store.\n */\n subscribe(listener: () => void): Unsubscribe;\n }\n}\n\n// currently we never reset the root, because rollbakcs are not supported in tapResourceRoot\n\nexport const tapResourceRoot = <TState>(\n element: ResourceElement<TState>,\n): tapResourceRoot.SubscribableResource<TState> => {\n const scheduler = tapConst(\n () => new UpdateScheduler(() => handleUpdate(null)),\n [],\n );\n const queue = tapConst(() => [] as (() => void)[], []);\n\n const fiber = tapMemo(() => {\n void element.key;\n\n return createResourceFiber(\n element.type,\n createResourceFiberRoot((callback) => {\n if (!scheduler.isDirty && !callback()) return;\n queue.push(callback);\n scheduler.markDirty();\n }),\n );\n }, [element.type, element.key]);\n\n setRootVersion(fiber.root, fiber.root.committedVersion);\n const render = renderResourceFiber(fiber, element.props);\n\n const isMountedRef = tapRef(false);\n const committedPropsRef = tapRef(element.props);\n const valueRef = tapRef<TState>(render.output);\n const subscribers = tapConst(() => new Set<() => void>(), []);\n const handleUpdate = tapEffectEvent((render: RenderResult | null) => {\n if (render === null) {\n setRootVersion(fiber.root, 2);\n setRootVersion(fiber.root, 1);\n\n queue.forEach((callback) => {\n if (isDevelopment && fiber.devStrictMode) {\n callback();\n }\n\n callback();\n });\n\n if (isDevelopment && fiber.devStrictMode) {\n void renderResourceFiber(fiber, committedPropsRef.current);\n }\n\n render = renderResourceFiber(fiber, committedPropsRef.current);\n }\n\n if (scheduler.isDirty)\n throw new Error(\"Scheduler is dirty, this should never happen\");\n\n commitRoot(fiber.root);\n queue.length = 0;\n\n if (isMountedRef.current) {\n commitResourceFiber(fiber, render);\n }\n\n if (scheduler.isDirty || valueRef.current === render.output) return;\n valueRef.current = render.output;\n subscribers.forEach((callback) => callback());\n });\n\n tapEffect(() => {\n isMountedRef.current = true;\n return () => {\n isMountedRef.current = false;\n unmountResourceFiber(fiber);\n };\n }, [fiber]);\n\n tapEffect(() => {\n committedPropsRef.current = render.props;\n commitRoot(fiber.root);\n commitResourceFiber(fiber, render);\n\n if (scheduler.isDirty || valueRef.current === render.output) return;\n valueRef.current = render.output;\n subscribers.forEach((callback) => callback());\n });\n\n return tapMemo(\n () => ({\n getValue: () => valueRef.current,\n subscribe: (listener: () => void) => {\n subscribers.add(listener);\n return () => subscribers.delete(listener);\n },\n }),\n [],\n );\n};\n"],"mappings":";;;;;;;;;;AAsCA,MAAa,mBACX,YACiD;CACjD,MAAM,YAAY,eACV,IAAI,sBAAsB,aAAa,IAAI,CAAC,GAClD,CAAC,CACH;CACA,MAAM,QAAQ,eAAe,CAAC,GAAqB,CAAC,CAAC;CAErD,MAAM,QAAQ,cAAc;EAC1B,QAAa;EAEb,OAAO,oBACL,QAAQ,MACR,yBAAyB,aAAa;GACpC,IAAI,CAAC,UAAU,WAAW,CAAC,SAAS,GAAG;GACvC,MAAM,KAAK,QAAQ;GACnB,UAAU,UAAU;EACtB,CAAC,CACH;CACF,GAAG,CAAC,QAAQ,MAAM,QAAQ,GAAG,CAAC;CAE9B,eAAe,MAAM,MAAM,MAAM,KAAK,gBAAgB;CACtD,MAAM,SAAS,oBAAoB,OAAO,QAAQ,KAAK;CAEvD,MAAM,eAAe,OAAO,KAAK;CACjC,MAAM,oBAAoB,OAAO,QAAQ,KAAK;CAC9C,MAAM,WAAW,OAAe,OAAO,MAAM;CAC7C,MAAM,cAAc,+BAAe,IAAI,IAAgB,GAAG,CAAC,CAAC;CAC5D,MAAM,eAAe,gBAAgB,WAAgC;EACnE,IAAI,WAAW,MAAM;GACnB,eAAe,MAAM,MAAM,CAAC;GAC5B,eAAe,MAAM,MAAM,CAAC;GAE5B,MAAM,SAAS,aAAa;IAC1B,IAAI,iBAAiB,MAAM,eACzB,SAAS;IAGX,SAAS;GACX,CAAC;GAED,IAAI,iBAAiB,MAAM,eACzB,oBAAyB,OAAO,kBAAkB,OAAO;GAG3D,SAAS,oBAAoB,OAAO,kBAAkB,OAAO;EAC/D;EAEA,IAAI,UAAU,SACZ,MAAM,IAAI,MAAM,8CAA8C;EAEhE,WAAW,MAAM,IAAI;EACrB,MAAM,SAAS;EAEf,IAAI,aAAa,SACf,oBAAoB,OAAO,MAAM;EAGnC,IAAI,UAAU,WAAW,SAAS,YAAY,OAAO,QAAQ;EAC7D,SAAS,UAAU,OAAO;EAC1B,YAAY,SAAS,aAAa,SAAS,CAAC;CAC9C,CAAC;CAED,gBAAgB;EACd,aAAa,UAAU;EACvB,aAAa;GACX,aAAa,UAAU;GACvB,qBAAqB,KAAK;EAC5B;CACF,GAAG,CAAC,KAAK,CAAC;CAEV,gBAAgB;EACd,kBAAkB,UAAU,OAAO;EACnC,WAAW,MAAM,IAAI;EACrB,oBAAoB,OAAO,MAAM;EAEjC,IAAI,UAAU,WAAW,SAAS,YAAY,OAAO,QAAQ;EAC7D,SAAS,UAAU,OAAO;EAC1B,YAAY,SAAS,aAAa,SAAS,CAAC;CAC9C,CAAC;CAED,OAAO,eACE;EACL,gBAAgB,SAAS;EACzB,YAAY,aAAyB;GACnC,YAAY,IAAI,QAAQ;GACxB,aAAa,YAAY,OAAO,QAAQ;EAC1C;CACF,IACA,CAAC,CACH;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/tap",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.14",
|
|
4
4
|
"description": "Zero-dependency reactive state management inspired by React hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state-management",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"react": "^19.2.6",
|
|
55
55
|
"react-dom": "^19.2.6",
|
|
56
56
|
"vitest": "^4.1.7",
|
|
57
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
57
|
+
"@assistant-ui/x-buildutils": "0.0.10"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public",
|
|
@@ -107,7 +107,6 @@ describe("tapEffect - Basic Functionality", () => {
|
|
|
107
107
|
];
|
|
108
108
|
|
|
109
109
|
const testFiber = createTestResource(() => {
|
|
110
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
111
110
|
effects.forEach((fn) => tapEffect(fn));
|
|
112
111
|
return null;
|
|
113
112
|
});
|
|
@@ -135,7 +134,6 @@ describe("tapEffect - Basic Functionality", () => {
|
|
|
135
134
|
}, []);
|
|
136
135
|
|
|
137
136
|
// Effect with deps - runs when deps change
|
|
138
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: test
|
|
139
137
|
tapEffect(() => {
|
|
140
138
|
effectCalls.conditional++;
|
|
141
139
|
}, [props.value]);
|
|
@@ -13,7 +13,6 @@ describe("Lifecycle - Mount/Unmount", () => {
|
|
|
13
13
|
const effects = [vi.fn(), vi.fn(), vi.fn()];
|
|
14
14
|
|
|
15
15
|
const resource = createTestResource(() => {
|
|
16
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
17
16
|
effects.forEach((fn) => tapEffect(fn));
|
|
18
17
|
return null;
|
|
19
18
|
});
|
|
@@ -36,11 +35,9 @@ describe("Lifecycle - Mount/Unmount", () => {
|
|
|
36
35
|
});
|
|
37
36
|
|
|
38
37
|
renderTest(resource, undefined);
|
|
39
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
40
38
|
cleanups.forEach((fn) => expect(fn).not.toHaveBeenCalled());
|
|
41
39
|
|
|
42
40
|
unmountResource(resource);
|
|
43
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
44
41
|
cleanups.forEach((fn) => expect(fn).toHaveBeenCalledTimes(1));
|
|
45
42
|
});
|
|
46
43
|
|
|
@@ -712,7 +712,6 @@ describe("React Strict Mode Behavior Verification", () => {
|
|
|
712
712
|
const [count, setCount] = useState(0);
|
|
713
713
|
events.push(`render count=${count}`);
|
|
714
714
|
|
|
715
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: testing strict mode behavior with intentionally incomplete deps
|
|
716
715
|
useEffect(() => {
|
|
717
716
|
effectRunCount++;
|
|
718
717
|
events.push(`effect mount #${effectRunCount} count=${count}`);
|
|
@@ -763,7 +762,6 @@ describe("React Strict Mode Behavior Verification", () => {
|
|
|
763
762
|
const [count, setCount] = useState(0);
|
|
764
763
|
events.push(`render count=${count}`);
|
|
765
764
|
|
|
766
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: testing strict mode behavior with intentionally incomplete deps
|
|
767
765
|
useEffect(() => {
|
|
768
766
|
effectRunCount++;
|
|
769
767
|
events.push(`effect mount #${effectRunCount} count=${count}`);
|
|
@@ -814,7 +812,6 @@ describe("React Strict Mode Behavior Verification", () => {
|
|
|
814
812
|
const [count, setCount] = useState(0);
|
|
815
813
|
events.push(`render count=${count}`);
|
|
816
814
|
|
|
817
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: testing strict mode behavior with intentionally incomplete deps
|
|
818
815
|
useEffect(() => {
|
|
819
816
|
effectRunCount++;
|
|
820
817
|
events.push(`effect mount #${effectRunCount} count=${count}`);
|
|
@@ -551,7 +551,6 @@ describe("Tap Strict Mode - Rerender Sources", () => {
|
|
|
551
551
|
const [count, setCount] = tapState(0);
|
|
552
552
|
events.push(`render count=${count}`);
|
|
553
553
|
|
|
554
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: testing strict mode behavior with intentionally incomplete deps
|
|
555
554
|
tapEffect(() => {
|
|
556
555
|
effectRunCount++;
|
|
557
556
|
events.push(`effect mount #${effectRunCount} count=${count}`);
|
|
@@ -598,7 +597,6 @@ describe("Tap Strict Mode - Rerender Sources", () => {
|
|
|
598
597
|
const [count, setCount] = tapState(0);
|
|
599
598
|
events.push(`render count=${count}`);
|
|
600
599
|
|
|
601
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: testing strict mode behavior with intentionally incomplete deps
|
|
602
600
|
tapEffect(() => {
|
|
603
601
|
effectRunCount++;
|
|
604
602
|
events.push(`effect mount #${effectRunCount} count=${count}`);
|
|
@@ -644,7 +642,6 @@ describe("Tap Strict Mode - Rerender Sources", () => {
|
|
|
644
642
|
const [count, setCount] = tapState(0);
|
|
645
643
|
events.push(`render count=${count}`);
|
|
646
644
|
|
|
647
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: testing strict mode behavior with intentionally incomplete deps
|
|
648
645
|
tapEffect(() => {
|
|
649
646
|
effectRunCount++;
|
|
650
647
|
events.push(`effect mount #${effectRunCount} count=${count}`);
|
|
@@ -74,7 +74,6 @@ export function unmountResource<R, P>(fiber: ResourceFiber<R, P>) {
|
|
|
74
74
|
* Cleans up all resources. Should be called after each test.
|
|
75
75
|
*/
|
|
76
76
|
export function cleanupAllResources() {
|
|
77
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
78
77
|
activeResources.forEach((fiber) => unmountResourceFiber(fiber));
|
|
79
78
|
activeResources.clear();
|
|
80
79
|
}
|
package/src/core/helpers/root.ts
CHANGED
package/src/tapResourceRoot.ts
CHANGED
|
@@ -97,7 +97,6 @@ export const tapResourceRoot = <TState>(
|
|
|
97
97
|
|
|
98
98
|
if (scheduler.isDirty || valueRef.current === render.output) return;
|
|
99
99
|
valueRef.current = render.output;
|
|
100
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
101
100
|
subscribers.forEach((callback) => callback());
|
|
102
101
|
});
|
|
103
102
|
|
|
@@ -116,7 +115,6 @@ export const tapResourceRoot = <TState>(
|
|
|
116
115
|
|
|
117
116
|
if (scheduler.isDirty || valueRef.current === render.output) return;
|
|
118
117
|
valueRef.current = render.output;
|
|
119
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
120
118
|
subscribers.forEach((callback) => callback());
|
|
121
119
|
});
|
|
122
120
|
|