atom.io 0.27.4 → 0.27.5
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/data/dist/index.js +57 -72
- package/data/src/dict.ts +9 -12
- package/data/src/join.ts +25 -26
- package/data/src/struct-family.ts +17 -23
- package/data/src/struct.ts +9 -12
- package/dist/{chunk-JRENM6KL.js → chunk-6ABWLAGY.js} +177 -151
- package/dist/index.d.ts +3 -3
- package/dist/index.js +33 -53
- package/ephemeral/dist/index.js +1 -1
- package/ephemeral/src/find-state.ts +1 -1
- package/immortal/dist/index.js +2 -2
- package/immortal/src/seek-state.ts +2 -2
- package/internal/dist/index.d.ts +80 -62
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/create-standalone-atom.ts +7 -5
- package/internal/src/families/create-atom-family.ts +5 -5
- package/internal/src/families/create-readonly-selector-family.ts +20 -9
- package/internal/src/families/create-regular-atom-family.ts +15 -6
- package/internal/src/families/create-selector-family.ts +5 -5
- package/internal/src/families/create-writable-selector-family.ts +20 -10
- package/internal/src/families/dispose-from-store.ts +11 -14
- package/internal/src/families/find-in-store.ts +11 -11
- package/internal/src/families/init-family-member.ts +9 -9
- package/internal/src/families/seek-in-store.ts +10 -10
- package/internal/src/get-state/get-from-store.ts +32 -18
- package/internal/src/ingest-updates/ingest-atom-update.ts +1 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +5 -5
- package/internal/src/molecule/create-molecule-family.ts +1 -1
- package/internal/src/molecule/dispose-molecule.ts +1 -1
- package/internal/src/molecule/grow-molecule-in-store.ts +1 -1
- package/internal/src/molecule/make-molecule-in-store.ts +5 -5
- package/internal/src/mutable/create-mutable-atom-family.ts +15 -6
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +2 -2
- package/internal/src/mutable/tracker-family.ts +3 -3
- package/internal/src/mutable/tracker.ts +14 -18
- package/internal/src/selector/create-readonly-selector.ts +2 -2
- package/internal/src/selector/create-standalone-selector.ts +5 -5
- package/internal/src/selector/create-writable-selector.ts +2 -2
- package/internal/src/selector/register-selector.ts +9 -9
- package/internal/src/set-state/set-into-store.ts +8 -16
- package/internal/src/store/deposit.ts +53 -13
- package/internal/src/store/store.ts +1 -1
- package/internal/src/subscribe/index.ts +2 -0
- package/internal/src/subscribe/subscribe-in-store.ts +62 -0
- package/internal/src/timeline/time-travel.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +6 -6
- package/introspection/dist/index.js +66 -87
- package/introspection/src/attach-atom-index.ts +5 -8
- package/introspection/src/attach-selector-index.ts +6 -8
- package/introspection/src/attach-timeline-family.ts +25 -28
- package/introspection/src/attach-timeline-index.ts +5 -8
- package/introspection/src/attach-transaction-index.ts +5 -8
- package/introspection/src/attach-transaction-logs.ts +21 -27
- package/json/dist/index.js +12 -15
- package/json/src/select-json-family.ts +4 -4
- package/json/src/select-json.ts +6 -9
- package/package.json +1 -1
- package/react/dist/index.js +7 -7
- package/react/src/parse-state-overloads.ts +2 -2
- package/react/src/use-i.ts +1 -1
- package/react/src/use-json.ts +2 -2
- package/react/src/use-o.ts +2 -2
- package/realtime-client/dist/index.js +35 -55
- package/realtime-client/src/pull-atom-family-member.ts +1 -1
- package/realtime-client/src/pull-atom.ts +1 -1
- package/realtime-client/src/pull-mutable-atom-family-member.ts +3 -3
- package/realtime-client/src/pull-mutable-atom.ts +3 -3
- package/realtime-client/src/sync-continuity.ts +27 -47
- package/realtime-react/dist/index.js +3 -3
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-server/dist/index.js +32 -32
- package/realtime-server/src/realtime-continuity-synchronizer.ts +16 -16
- package/realtime-server/src/realtime-family-provider.ts +3 -3
- package/realtime-server/src/realtime-mutable-family-provider.ts +5 -5
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-state-provider.ts +1 -1
- package/realtime-server/src/realtime-state-receiver.ts +1 -1
- package/realtime-testing/dist/index.js +7 -7
- package/realtime-testing/src/setup-realtime-test.tsx +7 -7
- package/src/atom.ts +2 -2
- package/src/dispose-state.ts +2 -2
- package/src/get-state.ts +9 -13
- package/src/molecule.ts +1 -1
- package/src/selector.ts +2 -2
- package/src/set-state.ts +10 -7
- package/src/silo.ts +23 -53
- package/src/subscribe.ts +3 -23
- package/src/timeline.ts +2 -2
- package/internal/src/families/throw-in-case-of-conflicting-family.ts +0 -18
|
@@ -36,7 +36,7 @@ export function realtimeContinuitySynchronizer({
|
|
|
36
36
|
socket.id,
|
|
37
37
|
store,
|
|
38
38
|
).userKeyOfSocket
|
|
39
|
-
const userKey = getFromStore(
|
|
39
|
+
const userKey = getFromStore(store, userKeyState)
|
|
40
40
|
if (!userKey) {
|
|
41
41
|
store.logger.error(
|
|
42
42
|
`❌`,
|
|
@@ -70,8 +70,8 @@ export function realtimeContinuitySynchronizer({
|
|
|
70
70
|
)
|
|
71
71
|
return
|
|
72
72
|
}
|
|
73
|
-
const newSocketState = findInStore(socketAtoms, newSocketKey
|
|
74
|
-
const newSocket = getFromStore(
|
|
73
|
+
const newSocketState = findInStore(store, socketAtoms, newSocketKey)
|
|
74
|
+
const newSocket = getFromStore(store, newSocketState)
|
|
75
75
|
socket = newSocket
|
|
76
76
|
},
|
|
77
77
|
`sync-continuity:${continuityKey}:${userKey}`,
|
|
@@ -79,13 +79,13 @@ export function realtimeContinuitySynchronizer({
|
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
const userUnacknowledgedQueue = findInStore(
|
|
82
|
+
store,
|
|
82
83
|
userUnacknowledgedQueues,
|
|
83
84
|
userKey,
|
|
84
|
-
store,
|
|
85
85
|
)
|
|
86
86
|
const userUnacknowledgedUpdates = getFromStore(
|
|
87
|
-
userUnacknowledgedQueue,
|
|
88
87
|
store,
|
|
88
|
+
userUnacknowledgedQueue,
|
|
89
89
|
)
|
|
90
90
|
const unsubscribeFunctions: (() => void)[] = []
|
|
91
91
|
|
|
@@ -93,7 +93,7 @@ export function realtimeContinuitySynchronizer({
|
|
|
93
93
|
const unsubFns: (() => void)[] = []
|
|
94
94
|
for (const perspective of continuity.perspectives) {
|
|
95
95
|
const { viewAtoms } = perspective
|
|
96
|
-
const userViewState = findInStore(viewAtoms, userKey
|
|
96
|
+
const userViewState = findInStore(store, viewAtoms, userKey)
|
|
97
97
|
const unsubscribe = subscribeToState(
|
|
98
98
|
userViewState,
|
|
99
99
|
({ oldValue, newValue }) => {
|
|
@@ -107,9 +107,9 @@ export function realtimeContinuitySynchronizer({
|
|
|
107
107
|
.flatMap((token) => {
|
|
108
108
|
const resourceToken =
|
|
109
109
|
token.type === `mutable_atom`
|
|
110
|
-
? getJsonToken(
|
|
110
|
+
? getJsonToken(store, token)
|
|
111
111
|
: token
|
|
112
|
-
const resource = getFromStore(
|
|
112
|
+
const resource = getFromStore(store, resourceToken)
|
|
113
113
|
return [resourceToken, resource]
|
|
114
114
|
})
|
|
115
115
|
store.logger.info(
|
|
@@ -141,13 +141,13 @@ export function realtimeContinuitySynchronizer({
|
|
|
141
141
|
const initialPayload: Json.Serializable[] = []
|
|
142
142
|
for (const atom of continuity.globals) {
|
|
143
143
|
const resourceToken =
|
|
144
|
-
atom.type === `mutable_atom` ? getJsonToken(
|
|
145
|
-
initialPayload.push(resourceToken, getFromStore(
|
|
144
|
+
atom.type === `mutable_atom` ? getJsonToken(store, atom) : atom
|
|
145
|
+
initialPayload.push(resourceToken, getFromStore(store, atom))
|
|
146
146
|
}
|
|
147
147
|
for (const perspective of continuity.perspectives) {
|
|
148
148
|
const { viewAtoms, resourceAtoms } = perspective
|
|
149
|
-
const userViewState = findInStore(viewAtoms, userKey
|
|
150
|
-
const userView = getFromStore(
|
|
149
|
+
const userViewState = findInStore(store, viewAtoms, userKey)
|
|
150
|
+
const userView = getFromStore(store, userViewState)
|
|
151
151
|
store.logger.info(`👁`, `atom`, resourceAtoms.key, `${userKey} can see`, {
|
|
152
152
|
viewAtoms,
|
|
153
153
|
resourceAtoms,
|
|
@@ -156,9 +156,9 @@ export function realtimeContinuitySynchronizer({
|
|
|
156
156
|
for (const visibleToken of userView) {
|
|
157
157
|
const resourceToken =
|
|
158
158
|
visibleToken.type === `mutable_atom`
|
|
159
|
-
? getJsonToken(
|
|
159
|
+
? getJsonToken(store, visibleToken)
|
|
160
160
|
: visibleToken
|
|
161
|
-
const resource = getFromStore(
|
|
161
|
+
const resource = getFromStore(store, resourceToken)
|
|
162
162
|
|
|
163
163
|
initialPayload.push(resourceToken, resource)
|
|
164
164
|
}
|
|
@@ -181,13 +181,13 @@ export function realtimeContinuitySynchronizer({
|
|
|
181
181
|
continuity.perspectives.flatMap((perspective) => {
|
|
182
182
|
const { viewAtoms } = perspective
|
|
183
183
|
const userPerspectiveTokenState = findInStore(
|
|
184
|
+
store,
|
|
184
185
|
viewAtoms,
|
|
185
186
|
userKey,
|
|
186
|
-
store,
|
|
187
187
|
)
|
|
188
188
|
const visibleTokens = getFromStore(
|
|
189
|
-
userPerspectiveTokenState,
|
|
190
189
|
store,
|
|
190
|
+
userPerspectiveTokenState,
|
|
191
191
|
)
|
|
192
192
|
return visibleTokens.map((token) => {
|
|
193
193
|
const key =
|
|
@@ -34,11 +34,11 @@ export function realtimeAtomFamilyProvider({
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const fillSubRequest = (subKey: K) => {
|
|
37
|
-
const exposedSubKeys = getFromStore(
|
|
37
|
+
const exposedSubKeys = getFromStore(store, index)
|
|
38
38
|
for (const exposedSubKey of exposedSubKeys) {
|
|
39
39
|
if (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {
|
|
40
|
-
const token = findInStore(family, subKey
|
|
41
|
-
socket.emit(`serve:${token.key}`, getFromStore(
|
|
40
|
+
const token = findInStore(store, family, subKey)
|
|
41
|
+
socket.emit(`serve:${token.key}`, getFromStore(store, token))
|
|
42
42
|
const unsubscribe = subscribeToState(
|
|
43
43
|
token,
|
|
44
44
|
({ newValue }) => {
|
|
@@ -40,14 +40,14 @@ export function realtimeMutableFamilyProvider({
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const fillSubRequest = (subKey: K) => {
|
|
43
|
-
const exposedSubKeys = getFromStore(
|
|
43
|
+
const exposedSubKeys = getFromStore(store, index)
|
|
44
44
|
for (const exposedSubKey of exposedSubKeys) {
|
|
45
45
|
if (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {
|
|
46
|
-
const token = findInStore(family, subKey
|
|
47
|
-
getFromStore(
|
|
48
|
-
const jsonToken = getJsonToken(
|
|
46
|
+
const token = findInStore(store, family, subKey)
|
|
47
|
+
getFromStore(store, token)
|
|
48
|
+
const jsonToken = getJsonToken(store, token)
|
|
49
49
|
const updateToken = getUpdateToken(token)
|
|
50
|
-
socket.emit(`init:${token.key}`, getFromStore(
|
|
50
|
+
socket.emit(`init:${token.key}`, getFromStore(store, jsonToken))
|
|
51
51
|
const unsubscribe = subscribeToState(
|
|
52
52
|
updateToken,
|
|
53
53
|
({ newValue }) => {
|
|
@@ -22,7 +22,7 @@ export function realtimeMutableProvider({
|
|
|
22
22
|
>(token: AtomIO.MutableAtomToken<Core, SerializableCore>): () => void {
|
|
23
23
|
let unsubscribeFromStateUpdates: (() => void) | null = null
|
|
24
24
|
|
|
25
|
-
const jsonToken = getJsonToken(
|
|
25
|
+
const jsonToken = getJsonToken(store, token)
|
|
26
26
|
const trackerToken = getUpdateToken(token)
|
|
27
27
|
|
|
28
28
|
const fillUnsubRequest = () => {
|
|
@@ -32,7 +32,7 @@ export function realtimeMutableProvider({
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const fillSubRequest = () => {
|
|
35
|
-
socket.emit(`init:${token.key}`, getFromStore(
|
|
35
|
+
socket.emit(`init:${token.key}`, getFromStore(store, jsonToken))
|
|
36
36
|
unsubscribeFromStateUpdates = subscribeToState(
|
|
37
37
|
trackerToken,
|
|
38
38
|
({ newValue }) => {
|
|
@@ -15,7 +15,7 @@ export function realtimeStateProvider({
|
|
|
15
15
|
let unsubscribeFromStateUpdates: (() => void) | undefined
|
|
16
16
|
|
|
17
17
|
const fillSubRequest = () => {
|
|
18
|
-
socket.emit(`serve:${token.key}`, getFromStore(
|
|
18
|
+
socket.emit(`serve:${token.key}`, getFromStore(store, token))
|
|
19
19
|
|
|
20
20
|
unsubscribeFromStateUpdates = subscribeToState(
|
|
21
21
|
token,
|
|
@@ -29,8 +29,8 @@ var setupRealtimeTestServer = (options) => {
|
|
|
29
29
|
const server = new SocketIO.Server(httpServer).use((socket, next) => {
|
|
30
30
|
const { token, username } = socket.handshake.auth;
|
|
31
31
|
if (token === `test` && socket.id) {
|
|
32
|
-
const socketState = findInStore(RTS.socketAtoms, socket.id
|
|
33
|
-
setIntoStore(socketState, socket
|
|
32
|
+
const socketState = findInStore(silo.store, RTS.socketAtoms, socket.id);
|
|
33
|
+
setIntoStore(silo.store, socketState, socket);
|
|
34
34
|
editRelationsInStore(
|
|
35
35
|
RTS.usersOfSockets,
|
|
36
36
|
(relations) => {
|
|
@@ -38,8 +38,8 @@ var setupRealtimeTestServer = (options) => {
|
|
|
38
38
|
},
|
|
39
39
|
silo.store
|
|
40
40
|
);
|
|
41
|
-
setIntoStore(RTS.userIndex, (index) => index.add(username)
|
|
42
|
-
setIntoStore(RTS.socketIndex, (index) => index.add(socket.id)
|
|
41
|
+
setIntoStore(silo.store, RTS.userIndex, (index) => index.add(username));
|
|
42
|
+
setIntoStore(silo.store, RTS.socketIndex, (index) => index.add(socket.id));
|
|
43
43
|
console.log(`${username} connected on ${socket.id}`);
|
|
44
44
|
next();
|
|
45
45
|
} else {
|
|
@@ -51,10 +51,10 @@ var setupRealtimeTestServer = (options) => {
|
|
|
51
51
|
});
|
|
52
52
|
const dispose = () => {
|
|
53
53
|
server.close();
|
|
54
|
-
const roomKeys = getFromStore(
|
|
54
|
+
const roomKeys = getFromStore(silo.store, RT.roomIndex);
|
|
55
55
|
for (const roomKey of roomKeys) {
|
|
56
|
-
const roomState = findInStore(RTS.roomSelectors, roomKey
|
|
57
|
-
const room = getFromStore(
|
|
56
|
+
const roomState = findInStore(silo.store, RTS.roomSelectors, roomKey);
|
|
57
|
+
const room = getFromStore(silo.store, roomState);
|
|
58
58
|
if (room && !(room instanceof Promise)) {
|
|
59
59
|
room.process.kill();
|
|
60
60
|
}
|
|
@@ -89,8 +89,8 @@ export const setupRealtimeTestServer = (
|
|
|
89
89
|
const server = new SocketIO.Server(httpServer).use((socket, next) => {
|
|
90
90
|
const { token, username } = socket.handshake.auth
|
|
91
91
|
if (token === `test` && socket.id) {
|
|
92
|
-
const socketState = findInStore(RTS.socketAtoms, socket.id
|
|
93
|
-
setIntoStore(socketState, socket
|
|
92
|
+
const socketState = findInStore(silo.store, RTS.socketAtoms, socket.id)
|
|
93
|
+
setIntoStore(silo.store, socketState, socket)
|
|
94
94
|
editRelationsInStore(
|
|
95
95
|
RTS.usersOfSockets,
|
|
96
96
|
(relations) => {
|
|
@@ -98,8 +98,8 @@ export const setupRealtimeTestServer = (
|
|
|
98
98
|
},
|
|
99
99
|
silo.store,
|
|
100
100
|
)
|
|
101
|
-
setIntoStore(RTS.userIndex, (index) => index.add(username)
|
|
102
|
-
setIntoStore(RTS.socketIndex, (index) => index.add(socket.id)
|
|
101
|
+
setIntoStore(silo.store, RTS.userIndex, (index) => index.add(username))
|
|
102
|
+
setIntoStore(silo.store, RTS.socketIndex, (index) => index.add(socket.id))
|
|
103
103
|
console.log(`${username} connected on ${socket.id}`)
|
|
104
104
|
next()
|
|
105
105
|
} else {
|
|
@@ -113,10 +113,10 @@ export const setupRealtimeTestServer = (
|
|
|
113
113
|
|
|
114
114
|
const dispose = () => {
|
|
115
115
|
server.close()
|
|
116
|
-
const roomKeys = getFromStore(
|
|
116
|
+
const roomKeys = getFromStore(silo.store, RT.roomIndex)
|
|
117
117
|
for (const roomKey of roomKeys) {
|
|
118
|
-
const roomState = findInStore(RTS.roomSelectors, roomKey
|
|
119
|
-
const room = getFromStore(
|
|
118
|
+
const roomState = findInStore(silo.store, RTS.roomSelectors, roomKey)
|
|
119
|
+
const room = getFromStore(silo.store, roomState)
|
|
120
120
|
if (room && !(room instanceof Promise)) {
|
|
121
121
|
room.process.kill()
|
|
122
122
|
}
|
package/src/atom.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
|
|
|
53
53
|
export function atom(
|
|
54
54
|
options: MutableAtomOptions<any, any> | RegularAtomOptions<any>,
|
|
55
55
|
): AtomToken<any> {
|
|
56
|
-
return createStandaloneAtom(
|
|
56
|
+
return createStandaloneAtom(IMPLICIT.STORE, options)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
@@ -112,5 +112,5 @@ export function atomFamily<T, K extends Canonical>(
|
|
|
112
112
|
| MutableAtomFamilyOptions<any, any, any>
|
|
113
113
|
| RegularAtomFamilyOptions<T, K>,
|
|
114
114
|
): MutableAtomFamilyToken<any, any, any> | RegularAtomFamilyToken<T, K> {
|
|
115
|
-
return createAtomFamily(
|
|
115
|
+
return createAtomFamily(IMPLICIT.STORE, options)
|
|
116
116
|
}
|
package/src/dispose-state.ts
CHANGED
|
@@ -32,8 +32,8 @@ export function disposeState(
|
|
|
32
32
|
key?: Json.Serializable,
|
|
33
33
|
): void {
|
|
34
34
|
if (key) {
|
|
35
|
-
Internal.disposeFromStore(token as any, key
|
|
35
|
+
Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any, key)
|
|
36
36
|
} else {
|
|
37
|
-
Internal.disposeFromStore(token as any
|
|
37
|
+
Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any)
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/get-state.ts
CHANGED
|
@@ -26,19 +26,15 @@ export function getState<M extends MoleculeConstructor>(
|
|
|
26
26
|
): InstanceType<M>
|
|
27
27
|
|
|
28
28
|
export function getState(
|
|
29
|
-
|
|
30
|
-
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
...params:
|
|
30
|
+
| [
|
|
31
|
+
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
32
|
+
key: Canonical,
|
|
33
|
+
]
|
|
34
|
+
| [token: MoleculeToken<any> | ReadableToken<any>]
|
|
35
35
|
): any {
|
|
36
|
-
if (
|
|
37
|
-
return Internal.getFromStore(
|
|
38
|
-
token as any,
|
|
39
|
-
key as any,
|
|
40
|
-
Internal.IMPLICIT.STORE,
|
|
41
|
-
)
|
|
36
|
+
if (params.length === 2) {
|
|
37
|
+
return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
|
|
42
38
|
}
|
|
43
|
-
return Internal.getFromStore(
|
|
39
|
+
return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
|
|
44
40
|
}
|
package/src/molecule.ts
CHANGED
|
@@ -101,7 +101,7 @@ export type MoleculeToken<M extends MoleculeConstructor> = {
|
|
|
101
101
|
export function moleculeFamily<M extends MoleculeConstructor>(
|
|
102
102
|
options: MoleculeFamilyOptions<M>,
|
|
103
103
|
): MoleculeFamilyToken<M> {
|
|
104
|
-
return createMoleculeFamily(
|
|
104
|
+
return createMoleculeFamily(IMPLICIT.STORE, options)
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
export function makeMolecule<M extends MoleculeConstructor>(
|
package/src/selector.ts
CHANGED
|
@@ -27,7 +27,7 @@ export function selector<T>(
|
|
|
27
27
|
export function selector<T>(
|
|
28
28
|
options: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,
|
|
29
29
|
): ReadonlySelectorToken<T> | WritableSelectorToken<T> {
|
|
30
|
-
return createStandaloneSelector(
|
|
30
|
+
return createStandaloneSelector(IMPLICIT.STORE, options)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export type WritableSelectorFamilyOptions<T, K extends Canonical> = {
|
|
@@ -69,5 +69,5 @@ export function selectorFamily<T, K extends Canonical>(
|
|
|
69
69
|
| ReadonlySelectorFamilyOptions<T, K>
|
|
70
70
|
| WritableSelectorFamilyOptions<T, K>,
|
|
71
71
|
): ReadonlySelectorFamilyToken<T, K> | WritableSelectorFamilyToken<T, K> {
|
|
72
|
-
return createSelectorFamily(
|
|
72
|
+
return createSelectorFamily(IMPLICIT.STORE, options)
|
|
73
73
|
}
|
package/src/set-state.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
|
-
import type { Json } from "rel8"
|
|
4
3
|
|
|
5
4
|
import type { WritableFamilyToken, WritableToken } from "."
|
|
6
5
|
|
|
@@ -32,13 +31,17 @@ export function setState<T, K extends Canonical, New extends T, Key extends K>(
|
|
|
32
31
|
): void
|
|
33
32
|
|
|
34
33
|
export function setState<T, New extends T>(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
...params:
|
|
35
|
+
| [
|
|
36
|
+
token: WritableFamilyToken<T, Canonical>,
|
|
37
|
+
key: Canonical,
|
|
38
|
+
value: New | ((oldValue: T) => New),
|
|
39
|
+
]
|
|
40
|
+
| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]
|
|
38
41
|
): void {
|
|
39
|
-
if (
|
|
40
|
-
Internal.setIntoStore(
|
|
42
|
+
if (params.length === 2) {
|
|
43
|
+
Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
|
|
41
44
|
} else {
|
|
42
|
-
Internal.setIntoStore(
|
|
45
|
+
Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
|
|
43
46
|
}
|
|
44
47
|
}
|
package/src/silo.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { findState } from "atom.io/ephemeral"
|
|
2
|
-
import type { Transceiver } from "atom.io/internal"
|
|
3
2
|
import {
|
|
4
3
|
createAtomFamily,
|
|
5
4
|
createMoleculeFamily,
|
|
@@ -14,30 +13,21 @@ import {
|
|
|
14
13
|
makeMoleculeInStore,
|
|
15
14
|
setIntoStore,
|
|
16
15
|
Store,
|
|
16
|
+
subscribeInStore,
|
|
17
17
|
timeTravel,
|
|
18
18
|
} from "atom.io/internal"
|
|
19
|
-
import type { Canonical, Json } from "atom.io/json"
|
|
20
19
|
|
|
21
20
|
import type {
|
|
22
|
-
AtomToken,
|
|
23
21
|
disposeState,
|
|
24
22
|
getState,
|
|
25
23
|
makeMolecule,
|
|
26
24
|
moleculeFamily,
|
|
27
|
-
MutableAtomFamilyOptions,
|
|
28
|
-
MutableAtomFamilyToken,
|
|
29
|
-
MutableAtomOptions,
|
|
30
|
-
MutableAtomToken,
|
|
31
25
|
redo,
|
|
32
|
-
RegularAtomFamilyOptions,
|
|
33
|
-
RegularAtomFamilyToken,
|
|
34
|
-
RegularAtomOptions,
|
|
35
|
-
RegularAtomToken,
|
|
36
26
|
setState,
|
|
27
|
+
subscribe,
|
|
37
28
|
timeline,
|
|
38
29
|
undo,
|
|
39
30
|
} from "."
|
|
40
|
-
import { subscribe } from "."
|
|
41
31
|
import type { atom, atomFamily } from "./atom"
|
|
42
32
|
import type { selector, selectorFamily } from "./selector"
|
|
43
33
|
import type { transaction } from "./transaction"
|
|
@@ -61,60 +51,40 @@ export class Silo {
|
|
|
61
51
|
public makeMolecule: typeof makeMolecule
|
|
62
52
|
public constructor(config: Store[`config`], fromStore: Store | null = null) {
|
|
63
53
|
const s = new Store(config, fromStore)
|
|
64
|
-
function _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
|
|
65
|
-
function _atom<T extends Transceiver<any>, J extends Json.Serializable>(
|
|
66
|
-
options: MutableAtomOptions<T, J>,
|
|
67
|
-
): MutableAtomToken<T, J>
|
|
68
|
-
function _atom<T>(
|
|
69
|
-
options: MutableAtomOptions<any, any> | RegularAtomOptions<T>,
|
|
70
|
-
): AtomToken<T> {
|
|
71
|
-
return createStandaloneAtom(options, s)
|
|
72
|
-
}
|
|
73
|
-
function _atomFamily<
|
|
74
|
-
T extends Transceiver<any>,
|
|
75
|
-
J extends Json.Serializable,
|
|
76
|
-
K extends Canonical,
|
|
77
|
-
>(
|
|
78
|
-
options: MutableAtomFamilyOptions<T, J, K>,
|
|
79
|
-
): MutableAtomFamilyToken<T, J, K>
|
|
80
|
-
function _atomFamily<T, K extends Canonical>(
|
|
81
|
-
options: RegularAtomFamilyOptions<T, K>,
|
|
82
|
-
): RegularAtomFamilyToken<T, K>
|
|
83
|
-
function _atomFamily<T, K extends Canonical>(
|
|
84
|
-
options:
|
|
85
|
-
| MutableAtomFamilyOptions<any, any, any>
|
|
86
|
-
| RegularAtomFamilyOptions<T, K>,
|
|
87
|
-
): MutableAtomFamilyToken<any, any, any> | RegularAtomFamilyToken<T, K> {
|
|
88
|
-
return createAtomFamily(options, s)
|
|
89
|
-
}
|
|
90
54
|
this.store = s
|
|
91
|
-
this.atom =
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
|
|
55
|
+
this.atom = ((options: Parameters<typeof atom>[0]) =>
|
|
56
|
+
createStandaloneAtom(s, options)) as typeof atom
|
|
57
|
+
this.atomFamily = ((options: Parameters<typeof atomFamily>[0]) =>
|
|
58
|
+
createAtomFamily(s, options)) as typeof atomFamily
|
|
59
|
+
this.selector = ((options: Parameters<typeof selector>[0]) =>
|
|
60
|
+
createStandaloneSelector(s, options)) as typeof selector
|
|
61
|
+
this.selectorFamily = ((options: Parameters<typeof selectorFamily>[0]) =>
|
|
62
|
+
createSelectorFamily(s, options)) as typeof selectorFamily
|
|
95
63
|
this.transaction = (options) => createTransaction(options, s)
|
|
96
64
|
this.timeline = (options) => createTimeline(options, s)
|
|
97
|
-
this.findState = (
|
|
65
|
+
this.findState = ((...params: Parameters<typeof findState>) =>
|
|
66
|
+
findInStore(s, ...params)) as typeof findState
|
|
98
67
|
this.getState = ((...params: Parameters<typeof getState>) =>
|
|
99
|
-
getFromStore(...params
|
|
68
|
+
getFromStore(s, ...params)) as typeof getState
|
|
100
69
|
this.setState = ((...params: Parameters<typeof setState>) => {
|
|
101
|
-
setIntoStore(...params
|
|
70
|
+
setIntoStore(s, ...params)
|
|
102
71
|
}) as typeof setState
|
|
103
72
|
this.disposeState = ((...params: Parameters<typeof disposeState>) => {
|
|
104
|
-
disposeFromStore(...params
|
|
73
|
+
disposeFromStore(s, ...params)
|
|
105
74
|
}) as typeof disposeState
|
|
106
|
-
this.subscribe = (
|
|
75
|
+
this.subscribe = ((...params: Parameters<typeof subscribe>) =>
|
|
76
|
+
subscribeInStore(s, ...params)) as typeof subscribe
|
|
107
77
|
this.undo = (token) => {
|
|
108
|
-
timeTravel(`undo`, token
|
|
78
|
+
timeTravel(s, `undo`, token)
|
|
109
79
|
}
|
|
110
80
|
this.redo = (token) => {
|
|
111
|
-
timeTravel(`redo`, token
|
|
81
|
+
timeTravel(s, `redo`, token)
|
|
112
82
|
}
|
|
113
|
-
this.moleculeFamily = ((
|
|
114
|
-
return createMoleculeFamily(
|
|
115
|
-
}) as
|
|
83
|
+
this.moleculeFamily = ((options: Parameters<typeof moleculeFamily>[0]) => {
|
|
84
|
+
return createMoleculeFamily(s, options)
|
|
85
|
+
}) as typeof moleculeFamily
|
|
116
86
|
this.makeMolecule = ((...params: Parameters<typeof makeMolecule>) => {
|
|
117
87
|
return makeMoleculeInStore(s, ...params)
|
|
118
|
-
}) as
|
|
88
|
+
}) as typeof makeMolecule
|
|
119
89
|
}
|
|
120
90
|
}
|
package/src/subscribe.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type { Flat, Func
|
|
2
|
-
import {
|
|
3
|
-
arbitrary,
|
|
4
|
-
IMPLICIT,
|
|
5
|
-
subscribeToState,
|
|
6
|
-
subscribeToTimeline,
|
|
7
|
-
subscribeToTransaction,
|
|
8
|
-
} from "atom.io/internal"
|
|
1
|
+
import type { Flat, Func } from "atom.io/internal"
|
|
2
|
+
import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
|
|
9
3
|
|
|
10
4
|
import type {
|
|
11
5
|
FamilyMetadata,
|
|
@@ -35,35 +29,21 @@ export function subscribe<T>(
|
|
|
35
29
|
token: ReadableToken<T>,
|
|
36
30
|
handleUpdate: UpdateHandler<T>,
|
|
37
31
|
key?: string,
|
|
38
|
-
store?: Store,
|
|
39
32
|
): () => void
|
|
40
33
|
export function subscribe<F extends Func>(
|
|
41
34
|
token: TransactionToken<F>,
|
|
42
35
|
handleUpdate: TransactionUpdateHandler<F>,
|
|
43
36
|
key?: string,
|
|
44
|
-
store?: Store,
|
|
45
37
|
): () => void
|
|
46
38
|
export function subscribe<M extends TimelineManageable>(
|
|
47
39
|
token: TimelineToken<M>,
|
|
48
40
|
handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,
|
|
49
41
|
key?: string,
|
|
50
|
-
store?: Store,
|
|
51
42
|
): () => void
|
|
52
43
|
export function subscribe(
|
|
53
44
|
token: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,
|
|
54
45
|
handleUpdate: (update: any) => void,
|
|
55
46
|
key: string = arbitrary(),
|
|
56
|
-
store = IMPLICIT.STORE,
|
|
57
47
|
): () => void {
|
|
58
|
-
|
|
59
|
-
case `atom`:
|
|
60
|
-
case `mutable_atom`:
|
|
61
|
-
case `readonly_selector`:
|
|
62
|
-
case `selector`:
|
|
63
|
-
return subscribeToState(token, handleUpdate, key, store)
|
|
64
|
-
case `transaction`:
|
|
65
|
-
return subscribeToTransaction(token, handleUpdate, key, store)
|
|
66
|
-
case `timeline`:
|
|
67
|
-
return subscribeToTimeline(token, handleUpdate, key, store)
|
|
68
|
-
}
|
|
48
|
+
return subscribeInStore(IMPLICIT.STORE, token, handleUpdate, key)
|
|
69
49
|
}
|
package/src/timeline.ts
CHANGED
|
@@ -54,9 +54,9 @@ export const timeline = <ManagedAtom extends TimelineManageable>(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export const redo = (tl: TimelineToken<any>): void => {
|
|
57
|
-
timeTravel(`redo`, tl
|
|
57
|
+
timeTravel(IMPLICIT.STORE, `redo`, tl)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export const undo = (tl: TimelineToken<any>): void => {
|
|
61
|
-
timeTravel(`undo`, tl
|
|
61
|
+
timeTravel(IMPLICIT.STORE, `undo`, tl)
|
|
62
62
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AtomFamilyToken, SelectorFamilyToken } from "atom.io"
|
|
2
|
-
|
|
3
|
-
import { prettyPrintTokenType } from "../pretty-print"
|
|
4
|
-
import type { Store } from "../store"
|
|
5
|
-
|
|
6
|
-
export function throwInCaseOfConflictingFamily(
|
|
7
|
-
family: AtomFamilyToken<any, any> | SelectorFamilyToken<any, any>,
|
|
8
|
-
store: Store,
|
|
9
|
-
): void {
|
|
10
|
-
const existingFamily = store.families.get(family.key)
|
|
11
|
-
if (existingFamily) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`Tried to create ${family.type === `atom_family` ? `an` : `a`} ${prettyPrintTokenType(family)} with key "${family.key}", but "${family.key}" already exists in store "${store.config.name}" as ${existingFamily.type === `atom_family` ? `an` : `a`} ${prettyPrintTokenType(
|
|
14
|
-
existingFamily,
|
|
15
|
-
)}`,
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
}
|