atom.io 0.8.2 → 0.9.0

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.
Files changed (41) hide show
  1. package/README.md +33 -28
  2. package/data/dist/index.d.mts +31 -0
  3. package/data/dist/index.d.ts +31 -0
  4. package/data/dist/index.js +77 -0
  5. package/data/dist/index.js.map +1 -0
  6. package/data/dist/index.mjs +73 -0
  7. package/data/dist/index.mjs.map +1 -0
  8. package/data/package.json +15 -0
  9. package/data/src/dict.ts +31 -0
  10. package/data/src/index.ts +3 -0
  11. package/data/src/struct-family.ts +38 -0
  12. package/data/src/struct.ts +45 -0
  13. package/dist/index.js +2 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +2 -2
  16. package/dist/index.mjs.map +1 -1
  17. package/internal/dist/index.js +20 -18
  18. package/internal/dist/index.js.map +1 -1
  19. package/internal/dist/index.mjs +20 -18
  20. package/internal/dist/index.mjs.map +1 -1
  21. package/internal/src/store/store.ts +15 -16
  22. package/package.json +46 -28
  23. package/react-devtools/dist/index.d.mts +4 -4
  24. package/react-devtools/dist/index.d.ts +4 -4
  25. package/react-devtools/dist/index.js +12 -8
  26. package/react-devtools/dist/index.js.map +1 -1
  27. package/react-devtools/dist/index.mjs +12 -8
  28. package/react-devtools/dist/index.mjs.map +1 -1
  29. package/react-devtools/src/StateIndex.tsx +3 -2
  30. package/realtime-server/dist/index.js +30 -18
  31. package/realtime-server/dist/index.js.map +1 -1
  32. package/realtime-server/dist/index.mjs +30 -18
  33. package/realtime-server/dist/index.mjs.map +1 -1
  34. package/realtime-server/src/hook-composition/expose-family.ts +11 -5
  35. package/realtime-server/src/hook-composition/expose-mutable-family.ts +11 -5
  36. package/realtime-testing/dist/index.js +11 -4
  37. package/realtime-testing/dist/index.js.map +1 -1
  38. package/realtime-testing/dist/index.mjs +11 -4
  39. package/realtime-testing/dist/index.mjs.map +1 -1
  40. package/realtime-testing/src/setup-realtime-test.tsx +11 -5
  41. package/src/logger.ts +2 -2
package/README.md CHANGED
@@ -1,10 +1,40 @@
1
- <hr>
1
+
2
+
2
3
 
3
4
  <div align="center">
4
- <img alt="corners logo" src="https://raw.githubusercontent.com/jeremybanka/wayforge/main/packages/atom.io/assets/logo.png"/>
5
+ <picture>
6
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jeremybanka/wayforge/main/packages/atom.io/__assets__/logo-dark-mode.png">
7
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/jeremybanka/wayforge/main/packages/atom.io/__assets__/logo-light-mode.png">
8
+ <img alt="Banner text reading 'atom.io'" src="https://raw.githubusercontent.com/jeremybanka/wayforge/main/packages/atom.io/__assets__/logo-light-mode.png" style="max-width: 100%;">
9
+ </picture>
5
10
  </div>
6
11
 
7
- <br>
12
+ <h1 align="center">
13
+ atom.io
14
+ </h1>
15
+
16
+ <h3 align="center">
17
+ Composable, high-performance reactivity for ECMAScript inspired by <a href="https://recoiljs.org/">Recoil</a> 💙
18
+ </h3>
19
+
20
+
21
+
22
+ <h3 align="center">
23
+ <a href="https://atom.io.fyi">📖 Read the docs at atom.io.fyi</a>
24
+ </h3>
25
+
26
+
27
+
28
+
29
+ ```shell
30
+ npm i atom.io
31
+ ```
32
+ ```shell
33
+ pnpm i atom.io
34
+ ```
35
+ ```shell
36
+ bun i atom.io
37
+ ```
8
38
 
9
39
  <p align="center">
10
40
  <a href="https://bundlephobia.com/result?p=atom.io">
@@ -21,31 +51,6 @@
21
51
  </a>
22
52
  </p>
23
53
 
24
- ```shell
25
- npm i atom.io
26
- ```
27
- ```shell
28
- pnpm i atom.io
29
- ```
30
- ```shell
31
- bun i atom.io
32
- ```
33
- <hr>
34
-
35
- Fine-grained reactivity for JavaScript environments.
36
54
 
37
- 💙 Inspired by [Recoil](https://recoiljs.org/).
38
55
 
39
- # Usage
40
56
 
41
- ```typescript
42
- import { atom } from 'atom.io'
43
-
44
- const countState = atom({
45
- key: 'count',
46
- default: 0
47
- })
48
- // { key: 'count', type: 'atom' }
49
-
50
-
51
- ```
@@ -0,0 +1,31 @@
1
+ import * as AtomIO from 'atom.io';
2
+ import { Store } from 'atom.io/internal';
3
+ import { Json, Stringified } from 'atom.io/json';
4
+
5
+ declare function dict<State, Key extends Json.Serializable>(findState: AtomIO.AtomFamily<State, Key> | AtomIO.ReadonlySelectorFamily<State, Key> | AtomIO.SelectorFamily<State, Key>, index: AtomIO.AtomToken<Key[]> | AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.SelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
6
+ [K in Stringified<Key>]: State;
7
+ }>;
8
+
9
+ declare function struct<Struct extends {
10
+ [key: string]: unknown;
11
+ }>(options: {
12
+ key: string;
13
+ default: Struct;
14
+ }, store?: Store): [
15
+ {
16
+ [K in keyof Struct]: AtomIO.AtomToken<Struct[K]>;
17
+ },
18
+ AtomIO.ReadonlySelectorToken<Struct>
19
+ ];
20
+
21
+ declare function structFamily<Struct extends object>(options: {
22
+ key: string;
23
+ default: Struct;
24
+ }): [
25
+ {
26
+ [K in keyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>;
27
+ },
28
+ AtomIO.ReadonlySelectorFamily<Struct>
29
+ ];
30
+
31
+ export { dict, struct, structFamily };
@@ -0,0 +1,31 @@
1
+ import * as AtomIO from 'atom.io';
2
+ import { Store } from 'atom.io/internal';
3
+ import { Json, Stringified } from 'atom.io/json';
4
+
5
+ declare function dict<State, Key extends Json.Serializable>(findState: AtomIO.AtomFamily<State, Key> | AtomIO.ReadonlySelectorFamily<State, Key> | AtomIO.SelectorFamily<State, Key>, index: AtomIO.AtomToken<Key[]> | AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.SelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
6
+ [K in Stringified<Key>]: State;
7
+ }>;
8
+
9
+ declare function struct<Struct extends {
10
+ [key: string]: unknown;
11
+ }>(options: {
12
+ key: string;
13
+ default: Struct;
14
+ }, store?: Store): [
15
+ {
16
+ [K in keyof Struct]: AtomIO.AtomToken<Struct[K]>;
17
+ },
18
+ AtomIO.ReadonlySelectorToken<Struct>
19
+ ];
20
+
21
+ declare function structFamily<Struct extends object>(options: {
22
+ key: string;
23
+ default: Struct;
24
+ }): [
25
+ {
26
+ [K in keyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>;
27
+ },
28
+ AtomIO.ReadonlySelectorFamily<Struct>
29
+ ];
30
+
31
+ export { dict, struct, structFamily };
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var internal = require('atom.io/internal');
4
+
5
+ // src/dict.ts
6
+ function dict(findState, index, store = internal.IMPLICIT.STORE) {
7
+ return internal.createSelector(
8
+ {
9
+ key: `dict`,
10
+ get: ({ get }) => {
11
+ const keys = get(index);
12
+ return keys.reduce((acc, key) => {
13
+ acc[key] = get(findState(key));
14
+ return acc;
15
+ }, {});
16
+ }
17
+ },
18
+ void 0,
19
+ store
20
+ );
21
+ }
22
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
23
+ function struct(options, store = internal.IMPLICIT.STORE) {
24
+ const atoms = Object.keys(options.default).reduce((acc, key) => {
25
+ const atomName = options.key + capitalize(key) + `State`;
26
+ acc[atomName] = internal.createAtom(
27
+ {
28
+ key: `${options.key}.${key}`,
29
+ default: options.default[key]
30
+ },
31
+ void 0,
32
+ store
33
+ );
34
+ return acc;
35
+ }, {});
36
+ const structState = internal.createSelector(
37
+ {
38
+ key: options.key,
39
+ get: ({ get }) => {
40
+ return Object.keys(options.default).reduce((acc, key) => {
41
+ acc[key] = get(atoms[options.key + capitalize(key) + `State`]);
42
+ return acc;
43
+ }, {});
44
+ }
45
+ },
46
+ void 0,
47
+ store
48
+ );
49
+ return [atoms, structState];
50
+ }
51
+ var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
52
+ function structFamily(options) {
53
+ const atoms = Object.keys(options.default).reduce((acc, key) => {
54
+ const atomFamilyName = `find` + capitalize2(options.key) + capitalize2(key) + `State`;
55
+ acc[atomFamilyName] = internal.createAtomFamily({
56
+ key: `${options.key}.${key}`,
57
+ default: options.default[key]
58
+ });
59
+ return acc;
60
+ }, {});
61
+ const findStructState = internal.createSelectorFamily({
62
+ key: options.key,
63
+ get: (id) => ({ get }) => {
64
+ return Object.keys(options.default).reduce((acc, key) => {
65
+ acc[key] = get(atoms[key](id));
66
+ return acc;
67
+ }, {});
68
+ }
69
+ });
70
+ return [atoms, findStructState];
71
+ }
72
+
73
+ exports.dict = dict;
74
+ exports.struct = struct;
75
+ exports.structFamily = structFamily;
76
+ //# sourceMappingURL=out.js.map
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dict.ts","../src/struct.ts","../src/struct-family.ts"],"names":["IMPLICIT","createSelector","capitalize"],"mappings":";AAEA,SAAS,UAAU,sBAAsB;AAGlC,SAAS,KACf,WAIA,OAIA,QAAe,SAAS,OAC2C;AACnE,SAAO;AAAA,IACN;AAAA,MACC,KAAK;AAAA,MACL,KAAK,CAAC,EAAE,IAAI,MAAM;AACjB,cAAM,OAAO,IAAI,KAAK;AACtB,eAAO,KAAK,OAAO,CAAC,KAAK,QAAQ;AAChC,cAAI,GAAG,IAAI,IAAI,UAAU,GAAG,CAAC;AAC7B,iBAAO;AAAA,QACR,GAAG,CAAC,CAAQ;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;AC5BA,SAAS,YAAAA,iBAAgB;AAEzB,SAAS,YAAY,kBAAAC,uBAAsB;AAE3C,IAAM,aAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAE/D,SAAS,OACf,SAIA,QAAeD,UAAS,OAIvB;AACD,QAAM,QAAQ,OAAO,KAAK,QAAQ,OAAO,EAAE,OAAO,CAAC,KAAK,QAAQ;AAC/D,UAAM,WAAW,QAAQ,MAAM,WA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KAAK,QAAQ;AACxD,YAAI,GAAG,IAAI,IAAK,MAAc,GAAG,EAAE,EAAE,CAAC;AACtC,eAAO;AAAA,MACR,GAAG,CAAC,CAAQ;AAAA,IACb;AAAA,EACD,CAAC;AACD,SAAO,CAAC,OAAO,eAAe;AAC/B","sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector } from \"atom.io/internal\"\nimport type { Json, Stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Json.Serializable>(\n\tfindState:\n\t\t| AtomIO.AtomFamily<State, Key>\n\t\t| AtomIO.ReadonlySelectorFamily<State, Key>\n\t\t| AtomIO.SelectorFamily<State, Key>,\n\tindex:\n\t\t| AtomIO.AtomToken<Key[]>\n\t\t| AtomIO.ReadonlySelectorToken<Key[]>\n\t\t| AtomIO.SelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlySelectorToken<{ [K in Stringified<Key>]: State }> {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `dict`,\n\t\t\tget: ({ get }) => {\n\t\t\t\tconst keys = get(index)\n\t\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(findState(key))\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createAtom, createSelector } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function struct<Struct extends { [key: string]: unknown }>(\n\toptions: {\n\t\tkey: string\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{ [K in keyof Struct]: AtomIO.AtomToken<Struct[K]> },\n\tAtomIO.ReadonlySelectorToken<Struct>,\n] {\n\tconst atoms = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createAtom(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t\tstore,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createSelector(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget: ({ get }) => {\n\t\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport { createAtomFamily, createSelectorFamily } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function structFamily<Struct extends object>(options: {\n\tkey: string\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in\n\t\t\tkeyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>\n\t},\n\tAtomIO.ReadonlySelectorFamily<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in\n\t\t\tkeyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomFamilyName =\n\t\t\t`find` + capitalize(options.key) + capitalize(key) + `State`\n\t\tacc[atomFamilyName] = createAtomFamily({\n\t\t\tkey: `${options.key}.${key}`,\n\t\t\tdefault: (options.default as any)[key],\n\t\t})\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState = createSelectorFamily({\n\t\tkey: options.key,\n\t\tget: (id) => ({ get }) => {\n\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\tacc[key] = get((atoms as any)[key](id))\n\t\t\t\treturn acc\n\t\t\t}, {} as any)\n\t\t},\n\t})\n\treturn [atoms, findStructState]\n}\n"]}
@@ -0,0 +1,73 @@
1
+ import { createSelector, IMPLICIT, createAtom, createAtomFamily, createSelectorFamily } from 'atom.io/internal';
2
+
3
+ // src/dict.ts
4
+ function dict(findState, index, store = IMPLICIT.STORE) {
5
+ return createSelector(
6
+ {
7
+ key: `dict`,
8
+ get: ({ get }) => {
9
+ const keys = get(index);
10
+ return keys.reduce((acc, key) => {
11
+ acc[key] = get(findState(key));
12
+ return acc;
13
+ }, {});
14
+ }
15
+ },
16
+ void 0,
17
+ store
18
+ );
19
+ }
20
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
21
+ function struct(options, store = IMPLICIT.STORE) {
22
+ const atoms = Object.keys(options.default).reduce((acc, key) => {
23
+ const atomName = options.key + capitalize(key) + `State`;
24
+ acc[atomName] = createAtom(
25
+ {
26
+ key: `${options.key}.${key}`,
27
+ default: options.default[key]
28
+ },
29
+ void 0,
30
+ store
31
+ );
32
+ return acc;
33
+ }, {});
34
+ const structState = createSelector(
35
+ {
36
+ key: options.key,
37
+ get: ({ get }) => {
38
+ return Object.keys(options.default).reduce((acc, key) => {
39
+ acc[key] = get(atoms[options.key + capitalize(key) + `State`]);
40
+ return acc;
41
+ }, {});
42
+ }
43
+ },
44
+ void 0,
45
+ store
46
+ );
47
+ return [atoms, structState];
48
+ }
49
+ var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
50
+ function structFamily(options) {
51
+ const atoms = Object.keys(options.default).reduce((acc, key) => {
52
+ const atomFamilyName = `find` + capitalize2(options.key) + capitalize2(key) + `State`;
53
+ acc[atomFamilyName] = createAtomFamily({
54
+ key: `${options.key}.${key}`,
55
+ default: options.default[key]
56
+ });
57
+ return acc;
58
+ }, {});
59
+ const findStructState = createSelectorFamily({
60
+ key: options.key,
61
+ get: (id) => ({ get }) => {
62
+ return Object.keys(options.default).reduce((acc, key) => {
63
+ acc[key] = get(atoms[key](id));
64
+ return acc;
65
+ }, {});
66
+ }
67
+ });
68
+ return [atoms, findStructState];
69
+ }
70
+
71
+ export { dict, struct, structFamily };
72
+ //# sourceMappingURL=out.js.map
73
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dict.ts","../src/struct.ts","../src/struct-family.ts"],"names":["IMPLICIT","createSelector","capitalize"],"mappings":";AAEA,SAAS,UAAU,sBAAsB;AAGlC,SAAS,KACf,WAIA,OAIA,QAAe,SAAS,OAC2C;AACnE,SAAO;AAAA,IACN;AAAA,MACC,KAAK;AAAA,MACL,KAAK,CAAC,EAAE,IAAI,MAAM;AACjB,cAAM,OAAO,IAAI,KAAK;AACtB,eAAO,KAAK,OAAO,CAAC,KAAK,QAAQ;AAChC,cAAI,GAAG,IAAI,IAAI,UAAU,GAAG,CAAC;AAC7B,iBAAO;AAAA,QACR,GAAG,CAAC,CAAQ;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;AC5BA,SAAS,YAAAA,iBAAgB;AAEzB,SAAS,YAAY,kBAAAC,uBAAsB;AAE3C,IAAM,aAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAE/D,SAAS,OACf,SAIA,QAAeD,UAAS,OAIvB;AACD,QAAM,QAAQ,OAAO,KAAK,QAAQ,OAAO,EAAE,OAAO,CAAC,KAAK,QAAQ;AAC/D,UAAM,WAAW,QAAQ,MAAM,WAAW,GAAG,IAAI;AACjD,QAAI,QAAQ,IAAI;AAAA,MACf;AAAA,QACC,KAAK,GAAG,QAAQ,GAAG,IAAI,GAAG;AAAA,QAC1B,SAAS,QAAQ,QAAQ,GAAG;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,WAAO;AAAA,EACR,GAAG,CAAC,CAAQ;AACZ,QAAM,cAAcC;AAAA,IACnB;AAAA,MACC,KAAK,QAAQ;AAAA,MACb,KAAK,CAAC,EAAE,IAAI,MAAM;AACjB,eAAO,OAAO,KAAK,QAAQ,OAAO,EAAE,OAAO,CAAC,KAAK,QAAQ;AACxD,cAAI,GAAG,IAAI,IAAI,MAAM,QAAQ,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC;AAC7D,iBAAO;AAAA,QACR,GAAG,CAAC,CAAQ;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,SAAO,CAAC,OAAO,WAAW;AAC3B;;;AC3CA,SAAS,kBAAkB,4BAA4B;AAEvD,IAAMC,cAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAE/D,SAAS,aAAoC,SASlD;AACD,QAAM,QAGF,OAAO,KAAK,QAAQ,OAAO,EAAE,OAAO,CAAC,KAAK,QAAQ;AACrD,UAAM,iBACL,SAASA,YAAW,QAAQ,GAAG,IAAIA,YAAW,GAAG,IAAI;AACtD,QAAI,cAAc,IAAI,iBAAiB;AAAA,MACtC,KAAK,GAAG,QAAQ,GAAG,IAAI,GAAG;AAAA,MAC1B,SAAU,QAAQ,QAAgB,GAAG;AAAA,IACtC,CAAC;AACD,WAAO;AAAA,EACR,GAAG,CAAC,CAAQ;AACZ,QAAM,kBAAkB,qBAAqB;AAAA,IAC5C,KAAK,QAAQ;AAAA,IACb,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,MAAM;AACzB,aAAO,OAAO,KAAK,QAAQ,OAAO,EAAE,OAAO,CAAC,KAAK,QAAQ;AACxD,YAAI,GAAG,IAAI,IAAK,MAAc,GAAG,EAAE,EAAE,CAAC;AACtC,eAAO;AAAA,MACR,GAAG,CAAC,CAAQ;AAAA,IACb;AAAA,EACD,CAAC;AACD,SAAO,CAAC,OAAO,eAAe;AAC/B","sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector } from \"atom.io/internal\"\nimport type { Json, Stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Json.Serializable>(\n\tfindState:\n\t\t| AtomIO.AtomFamily<State, Key>\n\t\t| AtomIO.ReadonlySelectorFamily<State, Key>\n\t\t| AtomIO.SelectorFamily<State, Key>,\n\tindex:\n\t\t| AtomIO.AtomToken<Key[]>\n\t\t| AtomIO.ReadonlySelectorToken<Key[]>\n\t\t| AtomIO.SelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlySelectorToken<{ [K in Stringified<Key>]: State }> {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `dict`,\n\t\t\tget: ({ get }) => {\n\t\t\t\tconst keys = get(index)\n\t\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(findState(key))\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createAtom, createSelector } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function struct<Struct extends { [key: string]: unknown }>(\n\toptions: {\n\t\tkey: string\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{ [K in keyof Struct]: AtomIO.AtomToken<Struct[K]> },\n\tAtomIO.ReadonlySelectorToken<Struct>,\n] {\n\tconst atoms = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createAtom(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t\tstore,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createSelector(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget: ({ get }) => {\n\t\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport { createAtomFamily, createSelectorFamily } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function structFamily<Struct extends object>(options: {\n\tkey: string\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in\n\t\t\tkeyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>\n\t},\n\tAtomIO.ReadonlySelectorFamily<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in\n\t\t\tkeyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomFamilyName =\n\t\t\t`find` + capitalize(options.key) + capitalize(key) + `State`\n\t\tacc[atomFamilyName] = createAtomFamily({\n\t\t\tkey: `${options.key}.${key}`,\n\t\t\tdefault: (options.default as any)[key],\n\t\t})\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState = createSelectorFamily({\n\t\tkey: options.key,\n\t\tget: (id) => ({ get }) => {\n\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\tacc[key] = get((atoms as any)[key](id))\n\t\t\t\treturn acc\n\t\t\t}, {} as any)\n\t\t},\n\t})\n\treturn [atoms, findStructState]\n}\n"]}
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "atom.io-data",
3
+ "private": true,
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "module": "dist/index.mjs",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "browser": "./dist/index.mjs",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,31 @@
1
+ import type * as AtomIO from "atom.io"
2
+ import type { Store } from "atom.io/internal"
3
+ import { IMPLICIT, createSelector } from "atom.io/internal"
4
+ import type { Json, Stringified } from "atom.io/json"
5
+
6
+ export function dict<State, Key extends Json.Serializable>(
7
+ findState:
8
+ | AtomIO.AtomFamily<State, Key>
9
+ | AtomIO.ReadonlySelectorFamily<State, Key>
10
+ | AtomIO.SelectorFamily<State, Key>,
11
+ index:
12
+ | AtomIO.AtomToken<Key[]>
13
+ | AtomIO.ReadonlySelectorToken<Key[]>
14
+ | AtomIO.SelectorToken<Key[]>,
15
+ store: Store = IMPLICIT.STORE,
16
+ ): AtomIO.ReadonlySelectorToken<{ [K in Stringified<Key>]: State }> {
17
+ return createSelector(
18
+ {
19
+ key: `dict`,
20
+ get: ({ get }) => {
21
+ const keys = get(index)
22
+ return keys.reduce((acc, key) => {
23
+ acc[key] = get(findState(key))
24
+ return acc
25
+ }, {} as any)
26
+ },
27
+ },
28
+ undefined,
29
+ store,
30
+ )
31
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./dict"
2
+ export * from "./struct"
3
+ export * from "./struct-family"
@@ -0,0 +1,38 @@
1
+ import type * as AtomIO from "atom.io"
2
+ import { createAtomFamily, createSelectorFamily } from "atom.io/internal"
3
+
4
+ const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
5
+
6
+ export function structFamily<Struct extends object>(options: {
7
+ key: string
8
+ default: Struct
9
+ }): [
10
+ {
11
+ [K in
12
+ keyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>
13
+ },
14
+ AtomIO.ReadonlySelectorFamily<Struct>,
15
+ ] {
16
+ const atoms: {
17
+ [K in
18
+ keyof Struct as `find${Capitalize<K & string>}`]: AtomIO.AtomFamily<string>
19
+ } = Object.keys(options.default).reduce((acc, key) => {
20
+ const atomFamilyName =
21
+ `find` + capitalize(options.key) + capitalize(key) + `State`
22
+ acc[atomFamilyName] = createAtomFamily({
23
+ key: `${options.key}.${key}`,
24
+ default: (options.default as any)[key],
25
+ })
26
+ return acc
27
+ }, {} as any)
28
+ const findStructState = createSelectorFamily({
29
+ key: options.key,
30
+ get: (id) => ({ get }) => {
31
+ return Object.keys(options.default).reduce((acc, key) => {
32
+ acc[key] = get((atoms as any)[key](id))
33
+ return acc
34
+ }, {} as any)
35
+ },
36
+ })
37
+ return [atoms, findStructState]
38
+ }
@@ -0,0 +1,45 @@
1
+ import type * as AtomIO from "atom.io"
2
+ import type { Store } from "atom.io/internal"
3
+ import { IMPLICIT } from "atom.io/internal"
4
+
5
+ import { createAtom, createSelector } from "atom.io/internal"
6
+
7
+ const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
8
+
9
+ export function struct<Struct extends { [key: string]: unknown }>(
10
+ options: {
11
+ key: string
12
+ default: Struct
13
+ },
14
+ store: Store = IMPLICIT.STORE,
15
+ ): [
16
+ { [K in keyof Struct]: AtomIO.AtomToken<Struct[K]> },
17
+ AtomIO.ReadonlySelectorToken<Struct>,
18
+ ] {
19
+ const atoms = Object.keys(options.default).reduce((acc, key) => {
20
+ const atomName = options.key + capitalize(key) + `State`
21
+ acc[atomName] = createAtom(
22
+ {
23
+ key: `${options.key}.${key}`,
24
+ default: options.default[key],
25
+ },
26
+ undefined,
27
+ store,
28
+ )
29
+ return acc
30
+ }, {} as any)
31
+ const structState = createSelector(
32
+ {
33
+ key: options.key,
34
+ get: ({ get }) => {
35
+ return Object.keys(options.default).reduce((acc, key) => {
36
+ acc[key] = get(atoms[options.key + capitalize(key) + `State`])
37
+ return acc
38
+ }, {} as any)
39
+ },
40
+ },
41
+ undefined,
42
+ store,
43
+ )
44
+ return [atoms, structState]
45
+ }
package/dist/index.js CHANGED
@@ -91,13 +91,13 @@ var setLogLevel = (preferredLevel, store = Internal.IMPLICIT.STORE) => {
91
91
  store.config.logger = null;
92
92
  } else {
93
93
  store.config.logger = __spreadValues({}, console);
94
- LOG_LEVELS.forEach((logLevel) => {
94
+ for (const logLevel of LOG_LEVELS) {
95
95
  if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
96
96
  store.config.logger[logLevel] = NO_OP;
97
97
  } else {
98
98
  store.config.logger[logLevel] = logger__INTERNAL[logLevel];
99
99
  }
100
- });
100
+ }
101
101
  }
102
102
  };
103
103
  var useLogger = (logger, store = Internal.IMPLICIT.STORE) => {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACjGA,YAAY,cAAc;AAGnB,IAAM,WAAW,CACvB,OACA,QAAiC,kBAAS,UACnC;AANR;AAOC,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,SAAgB,4BAAmB,OAAO,KAAK;AAChD;AAEO,IAAM,WAAW,CACvB,OACA,OACA,QAAiC,kBAAS,UAChC;AApBX;AAqBC,QAAM,YAAqB,uBAAc,OAAO,KAAK;AACrD,MAAI,WAAW;AACd;AAAA,EACD;AACA,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCA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BACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T => {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void => {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tLOG_LEVELS.forEach((logLevel) => {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
1
+ {"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACjGA,YAAY,cAAc;AAGnB,IAAM,WAAW,CACvB,OACA,QAAiC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AA,EACA,kBAAAC;AAAA,OACM;AAmBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOT,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAW,gBAAe,OAAOX,UAAS,KAAK;AACrC;;;ACtCA,SAAS,YAAAA,WAAU,yBAAAY,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T => {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void => {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tfor (const logLevel of LOG_LEVELS) {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
package/dist/index.mjs CHANGED
@@ -70,13 +70,13 @@ var setLogLevel = (preferredLevel, store = IMPLICIT.STORE) => {
70
70
  store.config.logger = null;
71
71
  } else {
72
72
  store.config.logger = __spreadValues({}, console);
73
- LOG_LEVELS.forEach((logLevel) => {
73
+ for (const logLevel of LOG_LEVELS) {
74
74
  if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
75
75
  store.config.logger[logLevel] = NO_OP;
76
76
  } else {
77
77
  store.config.logger[logLevel] = logger__INTERNAL[logLevel];
78
78
  }
79
- });
79
+ }
80
80
  }
81
81
  };
82
82
  var useLogger = (logger, store = IMPLICIT.STORE) => {