@tanstack/table-core 9.0.0-alpha.41 → 9.0.0-alpha.43
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/coreFeatures.cjs.map +1 -1
- package/dist/core/coreFeatures.d.cts +2 -1
- package/dist/core/coreFeatures.d.ts +2 -1
- package/dist/core/coreFeatures.js.map +1 -1
- package/dist/core/reactivity/coreReactivityFeature.types.d.cts +38 -0
- package/dist/core/reactivity/coreReactivityFeature.types.d.ts +38 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.cjs +19 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.cjs.map +1 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.d.cts +14 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.d.ts +14 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.js +18 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.js.map +1 -0
- package/dist/core/table/constructTable.cjs +28 -20
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.js +28 -20
- package/dist/core/table/constructTable.js.map +1 -1
- package/dist/core/table/coreTablesFeature.types.d.cts +32 -24
- package/dist/core/table/coreTablesFeature.types.d.ts +32 -24
- package/dist/core/table/coreTablesFeature.utils.cjs +17 -3
- package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.d.cts +2 -1
- package/dist/core/table/coreTablesFeature.utils.d.ts +2 -1
- package/dist/core/table/coreTablesFeature.utils.js +17 -4
- package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/reactivity.cjs +4 -0
- package/dist/reactivity.d.cts +3 -0
- package/dist/reactivity.d.ts +3 -0
- package/dist/reactivity.js +3 -0
- package/dist/static-functions.cjs +1 -0
- package/dist/static-functions.d.cts +2 -2
- package/dist/static-functions.d.ts +2 -2
- package/dist/static-functions.js +2 -2
- package/dist/store-reactivity-bindings.cjs +36 -0
- package/dist/store-reactivity-bindings.cjs.map +1 -0
- package/dist/store-reactivity-bindings.d.cts +22 -0
- package/dist/store-reactivity-bindings.d.ts +22 -0
- package/dist/store-reactivity-bindings.js +35 -0
- package/dist/store-reactivity-bindings.js.map +1 -0
- package/dist/types/TableFeatures.d.cts +1 -1
- package/dist/types/TableFeatures.d.ts +1 -1
- package/package.json +9 -1
- package/src/core/coreFeatures.ts +2 -0
- package/src/core/reactivity/coreReactivityFeature.types.ts +41 -0
- package/src/core/reactivity/coreReactivityFeature.utils.ts +29 -0
- package/src/core/table/constructTable.ts +59 -35
- package/src/core/table/coreTablesFeature.types.ts +32 -24
- package/src/core/table/coreTablesFeature.utils.ts +31 -3
- package/src/index.ts +0 -3
- package/src/reactivity.ts +2 -0
- package/src/store-reactivity-bindings.ts +35 -0
- package/src/types/TableFeatures.ts +7 -7
- package/dist/features/table-reactivity/tableReactivityFeature.cjs +0 -46
- package/dist/features/table-reactivity/tableReactivityFeature.cjs.map +0 -1
- package/dist/features/table-reactivity/tableReactivityFeature.d.cts +0 -12
- package/dist/features/table-reactivity/tableReactivityFeature.d.ts +0 -12
- package/dist/features/table-reactivity/tableReactivityFeature.js +0 -45
- package/dist/features/table-reactivity/tableReactivityFeature.js.map +0 -1
- package/src/features/table-reactivity/tableReactivityFeature.ts +0 -92
|
@@ -12,13 +12,13 @@ export type ExtractFeatureTypes<
|
|
|
12
12
|
TFeatures extends TableFeatures,
|
|
13
13
|
> = UnionToIntersection<
|
|
14
14
|
{
|
|
15
|
-
[K in keyof TFeatures]:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
[K in keyof TFeatures]: K extends 'coreReativityFeature'
|
|
16
|
+
? never
|
|
17
|
+
: TFeatures[K] extends TableFeature<infer FeatureConstructorOptions>
|
|
18
|
+
? TKey extends keyof FeatureConstructorOptions
|
|
19
|
+
? FeatureConstructorOptions[TKey]
|
|
20
|
+
: never
|
|
21
|
+
: any
|
|
22
22
|
}[keyof TFeatures]
|
|
23
23
|
>
|
|
24
24
|
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/features/table-reactivity/tableReactivityFeature.ts
|
|
3
|
-
function constructReactivityFeature(bindings) {
|
|
4
|
-
return { constructTableAPIs: (table) => {
|
|
5
|
-
table.optionsStore = bindStore(table.optionsStore, bindings.optionsNotifier);
|
|
6
|
-
table.atoms = bindAtoms(table.atoms, bindings.stateNotifier);
|
|
7
|
-
} };
|
|
8
|
-
}
|
|
9
|
-
const bindStore = (store, notifier) => {
|
|
10
|
-
const stateDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(store), "state");
|
|
11
|
-
Object.defineProperty(store, "state", {
|
|
12
|
-
configurable: true,
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get() {
|
|
15
|
-
notifier === null || notifier === void 0 || notifier();
|
|
16
|
-
return stateDescriptor.get.call(store);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return store;
|
|
20
|
-
};
|
|
21
|
-
const bindAtoms = (atoms, notifier) => {
|
|
22
|
-
if (!notifier) return atoms;
|
|
23
|
-
const wrappedCache = /* @__PURE__ */ new Map();
|
|
24
|
-
return new Proxy(atoms, { get(target, prop, receiver) {
|
|
25
|
-
const atom = Reflect.get(target, prop, receiver);
|
|
26
|
-
if (!atom || typeof prop !== "string" || !isAtomLike(atom)) return atom;
|
|
27
|
-
if (wrappedCache.has(prop)) return wrappedCache.get(prop);
|
|
28
|
-
const originalGet = atom.get.bind(atom);
|
|
29
|
-
const wrapped = new Proxy(atom, { get(atomTarget, atomProp, atomReceiver) {
|
|
30
|
-
if (atomProp === "get") return () => {
|
|
31
|
-
notifier();
|
|
32
|
-
return originalGet();
|
|
33
|
-
};
|
|
34
|
-
return Reflect.get(atomTarget, atomProp, atomReceiver);
|
|
35
|
-
} });
|
|
36
|
-
wrappedCache.set(prop, wrapped);
|
|
37
|
-
return wrapped;
|
|
38
|
-
} });
|
|
39
|
-
};
|
|
40
|
-
function isAtomLike(value) {
|
|
41
|
-
return typeof value === "object" && value !== null && typeof value.get === "function";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
exports.constructReactivityFeature = constructReactivityFeature;
|
|
46
|
-
//# sourceMappingURL=tableReactivityFeature.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tableReactivityFeature.cjs","names":[],"sources":["../../../src/features/table-reactivity/tableReactivityFeature.ts"],"sourcesContent":["import type { ReadonlyStore, Store } from '@tanstack/store'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\nexport interface TableReactivityFeatureConstructors<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {}\n\nexport function constructReactivityFeature<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(bindings: {\n stateNotifier?: () => unknown\n optionsNotifier?: () => unknown\n}): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>> {\n return {\n constructTableAPIs: (table) => {\n table.optionsStore = bindStore(\n table.optionsStore,\n bindings.optionsNotifier,\n )\n table.atoms = bindAtoms(table.atoms, bindings.stateNotifier)\n },\n }\n}\n\nconst bindStore = <T extends Store<any> | ReadonlyStore<any>>(\n store: T,\n notifier?: () => unknown,\n): T => {\n const stateDescriptor = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(store),\n 'state',\n )!\n\n Object.defineProperty(store, 'state', {\n configurable: true,\n enumerable: true,\n get() {\n notifier?.()\n return stateDescriptor.get!.call(store)\n },\n })\n\n return store\n}\n\n// Wraps an atoms/baseAtoms map so that `.get()` on any individual atom\n// calls the framework notifier first — matching how `bindStore` wraps\n// `store.state`. The proxy also transparently forwards missing slices\n// (atoms for features not registered on this table) as `undefined`.\nconst bindAtoms = <T extends object>(atoms: T, notifier?: () => unknown): T => {\n if (!notifier) return atoms\n // Cache wrapped atoms so referential identity is stable per slice.\n const wrappedCache = new Map<PropertyKey, any>()\n return new Proxy(atoms, {\n get(target, prop, receiver) {\n const atom = Reflect.get(target, prop, receiver) as unknown\n if (!atom || typeof prop !== 'string' || !isAtomLike(atom)) {\n return atom\n }\n if (wrappedCache.has(prop)) return wrappedCache.get(prop)\n const originalGet = atom.get.bind(atom)\n const wrapped = new Proxy(atom, {\n get(atomTarget, atomProp, atomReceiver) {\n if (atomProp === 'get') {\n return () => {\n notifier()\n return originalGet()\n }\n }\n return Reflect.get(atomTarget, atomProp, atomReceiver)\n },\n })\n wrappedCache.set(prop, wrapped)\n return wrapped\n },\n })\n}\n\ninterface AtomLike {\n get: () => unknown\n}\n\nfunction isAtomLike(value: unknown): value is AtomLike {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { get?: unknown }).get === 'function'\n )\n}\n"],"mappings":";;AASA,SAAgB,2BAGd,UAGqE;AACrE,QAAO,EACL,qBAAqB,UAAU;AAC7B,QAAM,eAAe,UACnB,MAAM,cACN,SAAS,gBACV;AACD,QAAM,QAAQ,UAAU,MAAM,OAAO,SAAS,cAAc;IAE/D;;AAGH,MAAM,aACJ,OACA,aACM;CACN,MAAM,kBAAkB,OAAO,yBAC7B,OAAO,eAAe,MAAM,EAC5B,QACD;AAED,QAAO,eAAe,OAAO,SAAS;EACpC,cAAc;EACd,YAAY;EACZ,MAAM;AACJ,yDAAY;AACZ,UAAO,gBAAgB,IAAK,KAAK,MAAM;;EAE1C,CAAC;AAEF,QAAO;;AAOT,MAAM,aAA+B,OAAU,aAAgC;AAC7E,KAAI,CAAC,SAAU,QAAO;CAEtB,MAAM,+BAAe,IAAI,KAAuB;AAChD,QAAO,IAAI,MAAM,OAAO,EACtB,IAAI,QAAQ,MAAM,UAAU;EAC1B,MAAM,OAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAChD,MAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,CAAC,WAAW,KAAK,CACxD,QAAO;AAET,MAAI,aAAa,IAAI,KAAK,CAAE,QAAO,aAAa,IAAI,KAAK;EACzD,MAAM,cAAc,KAAK,IAAI,KAAK,KAAK;EACvC,MAAM,UAAU,IAAI,MAAM,MAAM,EAC9B,IAAI,YAAY,UAAU,cAAc;AACtC,OAAI,aAAa,MACf,cAAa;AACX,cAAU;AACV,WAAO,aAAa;;AAGxB,UAAO,QAAQ,IAAI,YAAY,UAAU,aAAa;KAEzD,CAAC;AACF,eAAa,IAAI,MAAM,QAAQ;AAC/B,SAAO;IAEV,CAAC;;AAOJ,SAAS,WAAW,OAAmC;AACrD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA4B,QAAQ"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { RowData } from "../../types/type-utils.cjs";
|
|
2
|
-
import { TableFeature, TableFeatures } from "../../types/TableFeatures.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/features/table-reactivity/tableReactivityFeature.d.ts
|
|
5
|
-
interface TableReactivityFeatureConstructors<TFeatures extends TableFeatures, TData extends RowData> {}
|
|
6
|
-
declare function constructReactivityFeature<TFeatures extends TableFeatures, TData extends RowData>(bindings: {
|
|
7
|
-
stateNotifier?: () => unknown;
|
|
8
|
-
optionsNotifier?: () => unknown;
|
|
9
|
-
}): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { TableReactivityFeatureConstructors, constructReactivityFeature };
|
|
12
|
-
//# sourceMappingURL=tableReactivityFeature.d.cts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { RowData } from "../../types/type-utils.js";
|
|
2
|
-
import { TableFeature, TableFeatures } from "../../types/TableFeatures.js";
|
|
3
|
-
|
|
4
|
-
//#region src/features/table-reactivity/tableReactivityFeature.d.ts
|
|
5
|
-
interface TableReactivityFeatureConstructors<TFeatures extends TableFeatures, TData extends RowData> {}
|
|
6
|
-
declare function constructReactivityFeature<TFeatures extends TableFeatures, TData extends RowData>(bindings: {
|
|
7
|
-
stateNotifier?: () => unknown;
|
|
8
|
-
optionsNotifier?: () => unknown;
|
|
9
|
-
}): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { TableReactivityFeatureConstructors, constructReactivityFeature };
|
|
12
|
-
//# sourceMappingURL=tableReactivityFeature.d.ts.map
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
//#region src/features/table-reactivity/tableReactivityFeature.ts
|
|
2
|
-
function constructReactivityFeature(bindings) {
|
|
3
|
-
return { constructTableAPIs: (table) => {
|
|
4
|
-
table.optionsStore = bindStore(table.optionsStore, bindings.optionsNotifier);
|
|
5
|
-
table.atoms = bindAtoms(table.atoms, bindings.stateNotifier);
|
|
6
|
-
} };
|
|
7
|
-
}
|
|
8
|
-
const bindStore = (store, notifier) => {
|
|
9
|
-
const stateDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(store), "state");
|
|
10
|
-
Object.defineProperty(store, "state", {
|
|
11
|
-
configurable: true,
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get() {
|
|
14
|
-
notifier === null || notifier === void 0 || notifier();
|
|
15
|
-
return stateDescriptor.get.call(store);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return store;
|
|
19
|
-
};
|
|
20
|
-
const bindAtoms = (atoms, notifier) => {
|
|
21
|
-
if (!notifier) return atoms;
|
|
22
|
-
const wrappedCache = /* @__PURE__ */ new Map();
|
|
23
|
-
return new Proxy(atoms, { get(target, prop, receiver) {
|
|
24
|
-
const atom = Reflect.get(target, prop, receiver);
|
|
25
|
-
if (!atom || typeof prop !== "string" || !isAtomLike(atom)) return atom;
|
|
26
|
-
if (wrappedCache.has(prop)) return wrappedCache.get(prop);
|
|
27
|
-
const originalGet = atom.get.bind(atom);
|
|
28
|
-
const wrapped = new Proxy(atom, { get(atomTarget, atomProp, atomReceiver) {
|
|
29
|
-
if (atomProp === "get") return () => {
|
|
30
|
-
notifier();
|
|
31
|
-
return originalGet();
|
|
32
|
-
};
|
|
33
|
-
return Reflect.get(atomTarget, atomProp, atomReceiver);
|
|
34
|
-
} });
|
|
35
|
-
wrappedCache.set(prop, wrapped);
|
|
36
|
-
return wrapped;
|
|
37
|
-
} });
|
|
38
|
-
};
|
|
39
|
-
function isAtomLike(value) {
|
|
40
|
-
return typeof value === "object" && value !== null && typeof value.get === "function";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
export { constructReactivityFeature };
|
|
45
|
-
//# sourceMappingURL=tableReactivityFeature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tableReactivityFeature.js","names":[],"sources":["../../../src/features/table-reactivity/tableReactivityFeature.ts"],"sourcesContent":["import type { ReadonlyStore, Store } from '@tanstack/store'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\nexport interface TableReactivityFeatureConstructors<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {}\n\nexport function constructReactivityFeature<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(bindings: {\n stateNotifier?: () => unknown\n optionsNotifier?: () => unknown\n}): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>> {\n return {\n constructTableAPIs: (table) => {\n table.optionsStore = bindStore(\n table.optionsStore,\n bindings.optionsNotifier,\n )\n table.atoms = bindAtoms(table.atoms, bindings.stateNotifier)\n },\n }\n}\n\nconst bindStore = <T extends Store<any> | ReadonlyStore<any>>(\n store: T,\n notifier?: () => unknown,\n): T => {\n const stateDescriptor = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(store),\n 'state',\n )!\n\n Object.defineProperty(store, 'state', {\n configurable: true,\n enumerable: true,\n get() {\n notifier?.()\n return stateDescriptor.get!.call(store)\n },\n })\n\n return store\n}\n\n// Wraps an atoms/baseAtoms map so that `.get()` on any individual atom\n// calls the framework notifier first — matching how `bindStore` wraps\n// `store.state`. The proxy also transparently forwards missing slices\n// (atoms for features not registered on this table) as `undefined`.\nconst bindAtoms = <T extends object>(atoms: T, notifier?: () => unknown): T => {\n if (!notifier) return atoms\n // Cache wrapped atoms so referential identity is stable per slice.\n const wrappedCache = new Map<PropertyKey, any>()\n return new Proxy(atoms, {\n get(target, prop, receiver) {\n const atom = Reflect.get(target, prop, receiver) as unknown\n if (!atom || typeof prop !== 'string' || !isAtomLike(atom)) {\n return atom\n }\n if (wrappedCache.has(prop)) return wrappedCache.get(prop)\n const originalGet = atom.get.bind(atom)\n const wrapped = new Proxy(atom, {\n get(atomTarget, atomProp, atomReceiver) {\n if (atomProp === 'get') {\n return () => {\n notifier()\n return originalGet()\n }\n }\n return Reflect.get(atomTarget, atomProp, atomReceiver)\n },\n })\n wrappedCache.set(prop, wrapped)\n return wrapped\n },\n })\n}\n\ninterface AtomLike {\n get: () => unknown\n}\n\nfunction isAtomLike(value: unknown): value is AtomLike {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { get?: unknown }).get === 'function'\n )\n}\n"],"mappings":";AASA,SAAgB,2BAGd,UAGqE;AACrE,QAAO,EACL,qBAAqB,UAAU;AAC7B,QAAM,eAAe,UACnB,MAAM,cACN,SAAS,gBACV;AACD,QAAM,QAAQ,UAAU,MAAM,OAAO,SAAS,cAAc;IAE/D;;AAGH,MAAM,aACJ,OACA,aACM;CACN,MAAM,kBAAkB,OAAO,yBAC7B,OAAO,eAAe,MAAM,EAC5B,QACD;AAED,QAAO,eAAe,OAAO,SAAS;EACpC,cAAc;EACd,YAAY;EACZ,MAAM;AACJ,yDAAY;AACZ,UAAO,gBAAgB,IAAK,KAAK,MAAM;;EAE1C,CAAC;AAEF,QAAO;;AAOT,MAAM,aAA+B,OAAU,aAAgC;AAC7E,KAAI,CAAC,SAAU,QAAO;CAEtB,MAAM,+BAAe,IAAI,KAAuB;AAChD,QAAO,IAAI,MAAM,OAAO,EACtB,IAAI,QAAQ,MAAM,UAAU;EAC1B,MAAM,OAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAChD,MAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,CAAC,WAAW,KAAK,CACxD,QAAO;AAET,MAAI,aAAa,IAAI,KAAK,CAAE,QAAO,aAAa,IAAI,KAAK;EACzD,MAAM,cAAc,KAAK,IAAI,KAAK,KAAK;EACvC,MAAM,UAAU,IAAI,MAAM,MAAM,EAC9B,IAAI,YAAY,UAAU,cAAc;AACtC,OAAI,aAAa,MACf,cAAa;AACX,cAAU;AACV,WAAO,aAAa;;AAGxB,UAAO,QAAQ,IAAI,YAAY,UAAU,aAAa;KAEzD,CAAC;AACF,eAAa,IAAI,MAAM,QAAQ;AAC/B,SAAO;IAEV,CAAC;;AAOJ,SAAS,WAAW,OAAmC;AACrD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA4B,QAAQ"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { ReadonlyStore, Store } from '@tanstack/store'
|
|
2
|
-
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
|
|
3
|
-
import type { RowData } from '../../types/type-utils'
|
|
4
|
-
|
|
5
|
-
export interface TableReactivityFeatureConstructors<
|
|
6
|
-
TFeatures extends TableFeatures,
|
|
7
|
-
TData extends RowData,
|
|
8
|
-
> {}
|
|
9
|
-
|
|
10
|
-
export function constructReactivityFeature<
|
|
11
|
-
TFeatures extends TableFeatures,
|
|
12
|
-
TData extends RowData,
|
|
13
|
-
>(bindings: {
|
|
14
|
-
stateNotifier?: () => unknown
|
|
15
|
-
optionsNotifier?: () => unknown
|
|
16
|
-
}): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>> {
|
|
17
|
-
return {
|
|
18
|
-
constructTableAPIs: (table) => {
|
|
19
|
-
table.optionsStore = bindStore(
|
|
20
|
-
table.optionsStore,
|
|
21
|
-
bindings.optionsNotifier,
|
|
22
|
-
)
|
|
23
|
-
table.atoms = bindAtoms(table.atoms, bindings.stateNotifier)
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const bindStore = <T extends Store<any> | ReadonlyStore<any>>(
|
|
29
|
-
store: T,
|
|
30
|
-
notifier?: () => unknown,
|
|
31
|
-
): T => {
|
|
32
|
-
const stateDescriptor = Object.getOwnPropertyDescriptor(
|
|
33
|
-
Object.getPrototypeOf(store),
|
|
34
|
-
'state',
|
|
35
|
-
)!
|
|
36
|
-
|
|
37
|
-
Object.defineProperty(store, 'state', {
|
|
38
|
-
configurable: true,
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get() {
|
|
41
|
-
notifier?.()
|
|
42
|
-
return stateDescriptor.get!.call(store)
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
return store
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Wraps an atoms/baseAtoms map so that `.get()` on any individual atom
|
|
50
|
-
// calls the framework notifier first — matching how `bindStore` wraps
|
|
51
|
-
// `store.state`. The proxy also transparently forwards missing slices
|
|
52
|
-
// (atoms for features not registered on this table) as `undefined`.
|
|
53
|
-
const bindAtoms = <T extends object>(atoms: T, notifier?: () => unknown): T => {
|
|
54
|
-
if (!notifier) return atoms
|
|
55
|
-
// Cache wrapped atoms so referential identity is stable per slice.
|
|
56
|
-
const wrappedCache = new Map<PropertyKey, any>()
|
|
57
|
-
return new Proxy(atoms, {
|
|
58
|
-
get(target, prop, receiver) {
|
|
59
|
-
const atom = Reflect.get(target, prop, receiver) as unknown
|
|
60
|
-
if (!atom || typeof prop !== 'string' || !isAtomLike(atom)) {
|
|
61
|
-
return atom
|
|
62
|
-
}
|
|
63
|
-
if (wrappedCache.has(prop)) return wrappedCache.get(prop)
|
|
64
|
-
const originalGet = atom.get.bind(atom)
|
|
65
|
-
const wrapped = new Proxy(atom, {
|
|
66
|
-
get(atomTarget, atomProp, atomReceiver) {
|
|
67
|
-
if (atomProp === 'get') {
|
|
68
|
-
return () => {
|
|
69
|
-
notifier()
|
|
70
|
-
return originalGet()
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return Reflect.get(atomTarget, atomProp, atomReceiver)
|
|
74
|
-
},
|
|
75
|
-
})
|
|
76
|
-
wrappedCache.set(prop, wrapped)
|
|
77
|
-
return wrapped
|
|
78
|
-
},
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
interface AtomLike {
|
|
83
|
-
get: () => unknown
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function isAtomLike(value: unknown): value is AtomLike {
|
|
87
|
-
return (
|
|
88
|
-
typeof value === 'object' &&
|
|
89
|
-
value !== null &&
|
|
90
|
-
typeof (value as { get?: unknown }).get === 'function'
|
|
91
|
-
)
|
|
92
|
-
}
|