atom.io 0.21.1 → 0.23.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.
- package/data/dist/index.cjs +152 -63
- package/data/dist/index.d.ts +6 -0
- package/data/dist/index.js +3 -3
- package/data/src/join.ts +164 -51
- package/data/src/struct-family.ts +2 -2
- package/dist/chunk-6MLFYN32.js +18 -0
- package/dist/{chunk-HITX3MO4.js → chunk-7DT3PVS3.js} +151 -62
- package/dist/{chunk-RT43TVKP.js → chunk-GVHKIJ3G.js} +1 -1
- package/dist/chunk-OAYGID5B.js +27 -0
- package/dist/index.cjs +4 -18
- package/dist/index.d.ts +71 -28
- package/dist/index.js +6 -19
- package/ephemeral/dist/index.cjs +11 -0
- package/ephemeral/dist/index.js +9 -0
- package/ephemeral/package.json +16 -0
- package/ephemeral/src/index.ts +1 -0
- package/eslint-plugin/dist/index.cjs +155 -1
- package/eslint-plugin/dist/index.js +155 -1
- package/eslint-plugin/src/rules/index.ts +1 -0
- package/eslint-plugin/src/rules/lifespan.ts +203 -0
- package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -65
- package/eslint-plugin/src/walk.ts +73 -0
- package/immortal/dist/index.cjs +260 -0
- package/immortal/dist/index.js +212 -0
- package/immortal/package.json +16 -0
- package/immortal/src/index.ts +3 -0
- package/immortal/src/make-molecule.ts +222 -0
- package/immortal/src/molecule.ts +167 -0
- package/immortal/src/seek-state.ts +73 -0
- package/internal/dist/index.cjs +1242 -837
- package/internal/dist/index.d.ts +135 -22
- package/internal/dist/index.js +1215 -838
- package/internal/src/atom/create-regular-atom.ts +0 -2
- package/internal/src/atom/create-standalone-atom.ts +6 -2
- package/internal/src/atom/dispose-atom.ts +26 -3
- package/internal/src/families/create-readonly-selector-family.ts +15 -10
- package/internal/src/families/create-regular-atom-family.ts +20 -21
- package/internal/src/families/create-writable-selector-family.ts +13 -9
- package/{src/dispose.ts → internal/src/families/dispose-from-store.ts} +7 -4
- package/internal/src/families/find-in-store.ts +11 -6
- package/internal/src/families/index.ts +3 -0
- package/internal/src/families/init-family-member.ts +112 -0
- package/internal/src/families/seek-in-store.ts +123 -0
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/ingest-updates/index.ts +1 -0
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +104 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +26 -4
- package/internal/src/mutable/create-mutable-atom-family.ts +22 -24
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-family.ts +2 -2
- package/internal/src/mutable/get-json-token.ts +26 -12
- package/internal/src/mutable/tracker-family.ts +21 -19
- package/internal/src/not-found-error.ts +16 -3
- package/internal/src/selector/create-readonly-selector.ts +2 -3
- package/internal/src/selector/create-standalone-selector.ts +6 -2
- package/internal/src/selector/create-writable-selector.ts +2 -3
- package/internal/src/selector/dispose-selector.ts +68 -24
- package/internal/src/selector/register-selector.ts +10 -5
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +5 -1
- package/internal/src/store/deposit.ts +41 -7
- package/internal/src/store/index.ts +0 -1
- package/internal/src/store/store.ts +29 -5
- package/internal/src/store/withdraw.ts +28 -1
- package/internal/src/subscribe/subscribe-to-state.ts +2 -2
- package/internal/src/timeline/add-atom-to-timeline.ts +206 -182
- package/internal/src/timeline/create-timeline.ts +181 -60
- package/internal/src/timeline/time-travel.ts +20 -0
- package/internal/src/transaction/apply-transaction.ts +2 -12
- package/internal/src/transaction/build-transaction.ts +16 -2
- package/introspection/dist/index.cjs +40 -53
- package/introspection/dist/index.js +40 -53
- package/introspection/src/attach-atom-index.ts +38 -48
- package/introspection/src/attach-selector-index.ts +45 -50
- package/introspection/src/attach-timeline-family.ts +1 -0
- package/json/dist/index.cjs +40 -6
- package/json/dist/index.js +44 -9
- package/json/src/select-json-family.ts +47 -9
- package/package.json +30 -10
- package/react/dist/index.cjs +1 -1
- package/react/dist/index.js +1 -1
- package/react/src/use-json.ts +1 -1
- package/react-devtools/dist/index.cjs +69 -57
- package/react-devtools/dist/index.js +62 -49
- package/react-devtools/src/StateIndex.tsx +2 -1
- package/react-devtools/src/TimelineIndex.tsx +17 -14
- package/react-devtools/src/TransactionIndex.tsx +7 -7
- package/react-devtools/src/Updates.tsx +41 -32
- package/realtime-client/dist/index.cjs +3 -3
- package/realtime-client/dist/index.js +3 -3
- package/realtime-client/src/pull-mutable-atom-family-member.ts +1 -1
- package/realtime-client/src/pull-mutable-atom.ts +1 -1
- package/realtime-client/src/sync-continuity.ts +1 -2
- package/realtime-react/dist/index.cjs +1 -1
- package/realtime-react/dist/index.js +1 -1
- package/realtime-server/dist/index.cjs +39 -27
- package/realtime-server/dist/index.d.ts +1 -1
- package/realtime-server/dist/index.js +27 -16
- package/realtime-server/src/realtime-continuity-synchronizer.ts +5 -3
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
- package/realtime-server/src/realtime-mutable-provider.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +21 -11
- package/realtime-testing/dist/index.cjs +7 -2
- package/realtime-testing/dist/index.js +8 -5
- package/realtime-testing/src/setup-realtime-test.tsx +5 -2
- package/src/atom.ts +19 -7
- package/src/dispose-state.ts +10 -0
- package/src/index.ts +5 -2
- package/src/selector.ts +13 -7
- package/src/silo.ts +3 -3
- package/src/subscribe.ts +8 -4
- package/src/timeline.ts +18 -1
- package/src/transaction.ts +59 -4
- package/dist/chunk-BF4MVQF6.js +0 -44
- package/internal/src/store/withdraw-new-family-member.ts +0 -69
- /package/{src → ephemeral/src}/find-state.ts +0 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import type { Rule } from "eslint"
|
|
2
|
+
import type * as ESTree from "estree"
|
|
3
|
+
|
|
4
|
+
import { walk } from "../walk"
|
|
5
|
+
|
|
6
|
+
export const lifespan = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: `problem`,
|
|
9
|
+
docs: {
|
|
10
|
+
description: `atom.io provides tools for short-lived (ephemeral) and long-lived (immortal) stores. This rule allows you to guard against unsafe usage of tools for the other type of store.`,
|
|
11
|
+
category: `Possible Errors`,
|
|
12
|
+
recommended: false,
|
|
13
|
+
url: ``, // URL to documentation page for this rule
|
|
14
|
+
},
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: `string`,
|
|
18
|
+
enum: [`ephemeral`, `immortal`],
|
|
19
|
+
default: `ephemeral`,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
const storeLifespan = (context.options[0] ?? `ephemeral`) as
|
|
25
|
+
| `ephemeral`
|
|
26
|
+
| `immortal`
|
|
27
|
+
return {
|
|
28
|
+
ImportDeclaration(node) {
|
|
29
|
+
const importSource = node.source.value as string
|
|
30
|
+
if (!importSource.startsWith(`atom.io/`)) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
const [_, subPackageName] = importSource.split(`/`)
|
|
34
|
+
if (storeLifespan === `immortal` && subPackageName === `ephemeral`) {
|
|
35
|
+
context.report({
|
|
36
|
+
node,
|
|
37
|
+
message: `do not import from "${importSource}" in an ${storeLifespan} store`,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
CallExpression(node) {
|
|
43
|
+
if (storeLifespan === `ephemeral`) {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const functionCallee =
|
|
48
|
+
node.callee.type === `Identifier` ? node.callee : undefined
|
|
49
|
+
const methodCallee =
|
|
50
|
+
node.callee.type === `MemberExpression` &&
|
|
51
|
+
node.callee.property.type === `Identifier`
|
|
52
|
+
? node.callee.property
|
|
53
|
+
: undefined
|
|
54
|
+
const callee = functionCallee ?? methodCallee
|
|
55
|
+
|
|
56
|
+
if (callee === undefined) {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (callee.name === `findState`) {
|
|
61
|
+
context.report({
|
|
62
|
+
node,
|
|
63
|
+
message: `do not use findState in an ${storeLifespan} store`,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const storeProcedures: (
|
|
68
|
+
| ESTree.ArrowFunctionExpression
|
|
69
|
+
| ESTree.FunctionExpression
|
|
70
|
+
)[] = []
|
|
71
|
+
if (
|
|
72
|
+
callee.name === `selector` ||
|
|
73
|
+
callee.name === `selectorFamily` ||
|
|
74
|
+
callee.name === `transaction`
|
|
75
|
+
) {
|
|
76
|
+
if (node.arguments[0].type === `ObjectExpression`) {
|
|
77
|
+
const argProperties = node.arguments[0].properties
|
|
78
|
+
switch (callee.name) {
|
|
79
|
+
case `selector`:
|
|
80
|
+
case `selectorFamily`:
|
|
81
|
+
{
|
|
82
|
+
const getAndSetProps = argProperties.filter(
|
|
83
|
+
(prop): prop is ESTree.Property => {
|
|
84
|
+
return (
|
|
85
|
+
`key` in prop &&
|
|
86
|
+
`name` in prop.key &&
|
|
87
|
+
(prop.key.name === `get` || prop.key.name === `set`)
|
|
88
|
+
)
|
|
89
|
+
},
|
|
90
|
+
)
|
|
91
|
+
switch (callee.name) {
|
|
92
|
+
case `selector`:
|
|
93
|
+
{
|
|
94
|
+
for (const prop of getAndSetProps) {
|
|
95
|
+
if (
|
|
96
|
+
prop.value.type === `FunctionExpression` ||
|
|
97
|
+
prop.value.type === `ArrowFunctionExpression`
|
|
98
|
+
) {
|
|
99
|
+
storeProcedures.push(prop.value)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
break
|
|
104
|
+
case `selectorFamily`:
|
|
105
|
+
{
|
|
106
|
+
for (const prop of getAndSetProps) {
|
|
107
|
+
const { value } = prop
|
|
108
|
+
if (
|
|
109
|
+
value.type === `FunctionExpression` ||
|
|
110
|
+
value.type === `ArrowFunctionExpression`
|
|
111
|
+
) {
|
|
112
|
+
if (value.body.type === `BlockStatement`) {
|
|
113
|
+
for (const statement of value.body.body) {
|
|
114
|
+
if (
|
|
115
|
+
statement.type === `ReturnStatement` &&
|
|
116
|
+
statement.argument &&
|
|
117
|
+
(statement.argument.type ===
|
|
118
|
+
`FunctionExpression` ||
|
|
119
|
+
statement.argument.type ===
|
|
120
|
+
`ArrowFunctionExpression`)
|
|
121
|
+
) {
|
|
122
|
+
storeProcedures.push(statement.argument)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else if (
|
|
126
|
+
value.body.type === `FunctionExpression` ||
|
|
127
|
+
value.body.type === `ArrowFunctionExpression`
|
|
128
|
+
) {
|
|
129
|
+
storeProcedures.push(value.body)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
break
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
break
|
|
138
|
+
|
|
139
|
+
case `transaction`:
|
|
140
|
+
{
|
|
141
|
+
const doProp = argProperties.find(
|
|
142
|
+
(prop): prop is ESTree.Property => {
|
|
143
|
+
return (
|
|
144
|
+
`key` in prop &&
|
|
145
|
+
`name` in prop.key &&
|
|
146
|
+
prop.key.name === `do`
|
|
147
|
+
)
|
|
148
|
+
},
|
|
149
|
+
)
|
|
150
|
+
if (doProp) {
|
|
151
|
+
if (
|
|
152
|
+
doProp.value.type === `FunctionExpression` ||
|
|
153
|
+
doProp.value.type === `ArrowFunctionExpression`
|
|
154
|
+
) {
|
|
155
|
+
storeProcedures.push(doProp.value)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
break
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const storeProcedure of storeProcedures) {
|
|
165
|
+
const transactorsParam = storeProcedure.params[0]
|
|
166
|
+
const nonDestructuredTransactorsName =
|
|
167
|
+
transactorsParam && `name` in transactorsParam
|
|
168
|
+
? transactorsParam.name
|
|
169
|
+
: undefined
|
|
170
|
+
walk(storeProcedure.body, (n) => {
|
|
171
|
+
// console.log(`${`\t`.repeat(depth)}${n.type} ${n.name ?? ``}`)
|
|
172
|
+
if (n.type === `CallExpression`) {
|
|
173
|
+
let willReport = false
|
|
174
|
+
switch (n.callee.type) {
|
|
175
|
+
case `MemberExpression`:
|
|
176
|
+
if (
|
|
177
|
+
n.callee.object.type === `Identifier` &&
|
|
178
|
+
n.callee.object.name === nonDestructuredTransactorsName &&
|
|
179
|
+
n.callee.property.type === `Identifier` &&
|
|
180
|
+
n.callee.property.name === `find`
|
|
181
|
+
) {
|
|
182
|
+
willReport = true
|
|
183
|
+
}
|
|
184
|
+
break
|
|
185
|
+
case `Identifier`:
|
|
186
|
+
if (n.callee.name === `find`) {
|
|
187
|
+
willReport = true
|
|
188
|
+
}
|
|
189
|
+
break
|
|
190
|
+
}
|
|
191
|
+
if (willReport) {
|
|
192
|
+
context.report({
|
|
193
|
+
node: n,
|
|
194
|
+
message: `Using find in a transactor is not allowed in an immortal store.`,
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
} satisfies Rule.RuleModule
|
|
@@ -1,71 +1,7 @@
|
|
|
1
1
|
import type { Rule } from "eslint"
|
|
2
2
|
import type * as ESTree from "estree"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
node: ESTree.Node,
|
|
6
|
-
callback: (node: ESTree.Node, depth: number) => void,
|
|
7
|
-
depth = 0,
|
|
8
|
-
) {
|
|
9
|
-
callback(node, depth)
|
|
10
|
-
|
|
11
|
-
switch (node.type) {
|
|
12
|
-
case `FunctionDeclaration`:
|
|
13
|
-
case `FunctionExpression`:
|
|
14
|
-
case `ArrowFunctionExpression`:
|
|
15
|
-
for (const param of node.params) {
|
|
16
|
-
walk(param, callback, depth + 1)
|
|
17
|
-
}
|
|
18
|
-
walk(node.body, callback, depth + 1)
|
|
19
|
-
break
|
|
20
|
-
case `BlockStatement`:
|
|
21
|
-
for (const statement of node.body) {
|
|
22
|
-
walk(statement, callback, depth + 1)
|
|
23
|
-
}
|
|
24
|
-
break
|
|
25
|
-
case `IfStatement`:
|
|
26
|
-
walk(node.test, callback, depth)
|
|
27
|
-
walk(node.consequent, callback, depth)
|
|
28
|
-
if (node.alternate) {
|
|
29
|
-
walk(node.alternate, callback, depth)
|
|
30
|
-
}
|
|
31
|
-
break
|
|
32
|
-
case `SwitchStatement`:
|
|
33
|
-
walk(node.discriminant, callback, depth + 1)
|
|
34
|
-
for (const caseOrDefault of node.cases) {
|
|
35
|
-
walk(caseOrDefault, callback, depth)
|
|
36
|
-
}
|
|
37
|
-
break
|
|
38
|
-
case `ReturnStatement`:
|
|
39
|
-
if (node.argument) {
|
|
40
|
-
walk(node.argument, callback, depth)
|
|
41
|
-
}
|
|
42
|
-
break
|
|
43
|
-
case `SwitchCase`:
|
|
44
|
-
if (node.test) {
|
|
45
|
-
walk(node.test, callback, depth)
|
|
46
|
-
}
|
|
47
|
-
for (const statement of node.consequent) {
|
|
48
|
-
walk(statement, callback, depth)
|
|
49
|
-
}
|
|
50
|
-
break
|
|
51
|
-
case `VariableDeclaration`:
|
|
52
|
-
for (const declaration of node.declarations) {
|
|
53
|
-
walk(declaration, callback, depth)
|
|
54
|
-
if (declaration.init) {
|
|
55
|
-
walk(declaration.init, callback, depth)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
break
|
|
59
|
-
case `BinaryExpression`:
|
|
60
|
-
walk(node.left, callback, depth)
|
|
61
|
-
walk(node.right, callback, depth)
|
|
62
|
-
break
|
|
63
|
-
case `MemberExpression`:
|
|
64
|
-
walk(node.object, callback, depth)
|
|
65
|
-
walk(node.property, callback, depth)
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
|
-
}
|
|
4
|
+
import { walk } from "../walk"
|
|
69
5
|
|
|
70
6
|
export const synchronousSelectorDependencies = {
|
|
71
7
|
meta: {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type * as ESTree from "estree"
|
|
2
|
+
|
|
3
|
+
export function walk(
|
|
4
|
+
node: ESTree.Node,
|
|
5
|
+
callback: (node: ESTree.Node, depth: number) => void,
|
|
6
|
+
depth = 0,
|
|
7
|
+
): void {
|
|
8
|
+
callback(node, depth)
|
|
9
|
+
|
|
10
|
+
switch (node.type) {
|
|
11
|
+
case `FunctionDeclaration`:
|
|
12
|
+
case `FunctionExpression`:
|
|
13
|
+
case `ArrowFunctionExpression`:
|
|
14
|
+
for (const param of node.params) {
|
|
15
|
+
walk(param, callback, depth + 1)
|
|
16
|
+
}
|
|
17
|
+
walk(node.body, callback, depth + 1)
|
|
18
|
+
break
|
|
19
|
+
case `BlockStatement`:
|
|
20
|
+
for (const statement of node.body) {
|
|
21
|
+
walk(statement, callback, depth + 1)
|
|
22
|
+
}
|
|
23
|
+
break
|
|
24
|
+
case `IfStatement`:
|
|
25
|
+
walk(node.test, callback, depth)
|
|
26
|
+
walk(node.consequent, callback, depth)
|
|
27
|
+
if (node.alternate) {
|
|
28
|
+
walk(node.alternate, callback, depth)
|
|
29
|
+
}
|
|
30
|
+
break
|
|
31
|
+
case `SwitchStatement`:
|
|
32
|
+
walk(node.discriminant, callback, depth + 1)
|
|
33
|
+
for (const caseOrDefault of node.cases) {
|
|
34
|
+
walk(caseOrDefault, callback, depth)
|
|
35
|
+
}
|
|
36
|
+
break
|
|
37
|
+
case `ReturnStatement`:
|
|
38
|
+
if (node.argument) {
|
|
39
|
+
walk(node.argument, callback, depth)
|
|
40
|
+
}
|
|
41
|
+
break
|
|
42
|
+
case `SwitchCase`:
|
|
43
|
+
if (node.test) {
|
|
44
|
+
walk(node.test, callback, depth)
|
|
45
|
+
}
|
|
46
|
+
for (const statement of node.consequent) {
|
|
47
|
+
walk(statement, callback, depth)
|
|
48
|
+
}
|
|
49
|
+
break
|
|
50
|
+
case `VariableDeclaration`:
|
|
51
|
+
for (const declaration of node.declarations) {
|
|
52
|
+
walk(declaration, callback, depth)
|
|
53
|
+
if (declaration.init) {
|
|
54
|
+
walk(declaration.init, callback, depth)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
break
|
|
58
|
+
case `BinaryExpression`:
|
|
59
|
+
walk(node.left, callback, depth)
|
|
60
|
+
walk(node.right, callback, depth)
|
|
61
|
+
break
|
|
62
|
+
case `MemberExpression`:
|
|
63
|
+
walk(node.object, callback, depth)
|
|
64
|
+
walk(node.property, callback, depth)
|
|
65
|
+
break
|
|
66
|
+
case `CallExpression`:
|
|
67
|
+
walk(node.callee, callback, depth)
|
|
68
|
+
for (const argument of node.arguments) {
|
|
69
|
+
walk(argument, callback, depth)
|
|
70
|
+
}
|
|
71
|
+
break
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Internal = require('atom.io/internal');
|
|
4
|
+
var json = require('atom.io/json');
|
|
5
|
+
var data = require('atom.io/data');
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
|
|
26
|
+
|
|
27
|
+
var __defProp = Object.defineProperty;
|
|
28
|
+
var __defProps = Object.defineProperties;
|
|
29
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
30
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
31
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
32
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
33
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
34
|
+
var __spreadValues = (a, b) => {
|
|
35
|
+
for (var prop in b || (b = {}))
|
|
36
|
+
if (__hasOwnProp.call(b, prop))
|
|
37
|
+
__defNormalProp(a, prop, b[prop]);
|
|
38
|
+
if (__getOwnPropSymbols)
|
|
39
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
40
|
+
if (__propIsEnum.call(b, prop))
|
|
41
|
+
__defNormalProp(a, prop, b[prop]);
|
|
42
|
+
}
|
|
43
|
+
return a;
|
|
44
|
+
};
|
|
45
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
46
|
+
var Molecule = class _Molecule {
|
|
47
|
+
constructor(store, above, token) {
|
|
48
|
+
this.store = store;
|
|
49
|
+
this.token = token;
|
|
50
|
+
this.type = `molecule`;
|
|
51
|
+
this.below = [];
|
|
52
|
+
this.tokens = [];
|
|
53
|
+
this.joins = [];
|
|
54
|
+
this.subject = new Internal.Subject();
|
|
55
|
+
this.dispose = this[Symbol.dispose];
|
|
56
|
+
if (above) {
|
|
57
|
+
if (Array.isArray(above)) {
|
|
58
|
+
this.above = above;
|
|
59
|
+
for (const parent of above) {
|
|
60
|
+
parent.below.push(this);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
this.above = [above];
|
|
64
|
+
above.below.push(this);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
this.above = [];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
get key() {
|
|
71
|
+
return this.token.key;
|
|
72
|
+
}
|
|
73
|
+
bond(token) {
|
|
74
|
+
const state = Internal.initFamilyMember(token, this.token.key, this.store);
|
|
75
|
+
if (token.type === `mutable_atom_family`) {
|
|
76
|
+
const jsonFamily = Internal.getJsonFamily(token, this.store);
|
|
77
|
+
const jsonState = Internal.initFamilyMember(jsonFamily, this.token.key, this.store);
|
|
78
|
+
this.tokens.push(jsonState);
|
|
79
|
+
}
|
|
80
|
+
this.tokens.push(state);
|
|
81
|
+
this.subject.next({ type: `state_creation`, token: state });
|
|
82
|
+
return state;
|
|
83
|
+
}
|
|
84
|
+
spawn(key) {
|
|
85
|
+
const child = new _Molecule(this.store, this, { key, type: `molecule` });
|
|
86
|
+
return child;
|
|
87
|
+
}
|
|
88
|
+
with(molecule) {
|
|
89
|
+
return (key) => {
|
|
90
|
+
const child = new _Molecule(this.store, [this, molecule], {
|
|
91
|
+
key,
|
|
92
|
+
type: `molecule`
|
|
93
|
+
});
|
|
94
|
+
return child;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
detach(child) {
|
|
98
|
+
const childIndex = this.below.indexOf(child);
|
|
99
|
+
if (childIndex !== void 0) {
|
|
100
|
+
this.below.splice(childIndex, 1);
|
|
101
|
+
}
|
|
102
|
+
const parentIndex = child.above.indexOf(this);
|
|
103
|
+
if (parentIndex !== void 0) {
|
|
104
|
+
child.above.splice(parentIndex, 1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
claim(child) {
|
|
108
|
+
if (child === this) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for (const parent of child.above) {
|
|
112
|
+
parent.detach(child);
|
|
113
|
+
}
|
|
114
|
+
this.below.push(child);
|
|
115
|
+
child.above.push(this);
|
|
116
|
+
}
|
|
117
|
+
clear() {
|
|
118
|
+
var _a;
|
|
119
|
+
while (this.below.length > 0) {
|
|
120
|
+
(_a = this.below.pop()) == null ? void 0 : _a.dispose();
|
|
121
|
+
}
|
|
122
|
+
while (this.tokens.length > 0) {
|
|
123
|
+
const token = this.tokens.pop();
|
|
124
|
+
if (token) {
|
|
125
|
+
Internal.disposeFromStore(token, this.store);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
while (this.joins.length > 0) {
|
|
129
|
+
const join = this.joins.pop();
|
|
130
|
+
if (join) {
|
|
131
|
+
join.molecules.delete(json.stringifyJson(this.token.key));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
join(token) {
|
|
136
|
+
const join = data.getJoin(token, this.store);
|
|
137
|
+
join.molecules.set(json.stringifyJson(this.token.key), this);
|
|
138
|
+
this.joins.push(join);
|
|
139
|
+
}
|
|
140
|
+
[Symbol.dispose]() {
|
|
141
|
+
this.clear();
|
|
142
|
+
const target = Internal.newest(this.store);
|
|
143
|
+
target.molecules.delete(json.stringifyJson(this.token.key));
|
|
144
|
+
for (const parent of this.above) {
|
|
145
|
+
parent.detach(this);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// immortal/src/make-molecule.ts
|
|
151
|
+
function createMoleculeFamily(options, store) {
|
|
152
|
+
const subject = new Internal__namespace.Subject();
|
|
153
|
+
const token = {
|
|
154
|
+
key: options.key,
|
|
155
|
+
type: `molecule_family`
|
|
156
|
+
};
|
|
157
|
+
const family = Object.assign(options.new(store), __spreadProps(__spreadValues({}, token), { subject }));
|
|
158
|
+
store.moleculeFamilies.set(options.key, family);
|
|
159
|
+
return token;
|
|
160
|
+
}
|
|
161
|
+
function moleculeFamily(options) {
|
|
162
|
+
return createMoleculeFamily(options, Internal__namespace.IMPLICIT.STORE);
|
|
163
|
+
}
|
|
164
|
+
function makeMoleculeInStore(store, context, family, key, ...params) {
|
|
165
|
+
const target = Internal__namespace.newest(store);
|
|
166
|
+
const token = {
|
|
167
|
+
type: `molecule`,
|
|
168
|
+
key,
|
|
169
|
+
family
|
|
170
|
+
};
|
|
171
|
+
const contextArray = Array.isArray(context) ? context : [context];
|
|
172
|
+
const owners = contextArray.map((ctx) => store.molecules.get(json.stringifyJson(ctx.key))).filter((m) => m !== void 0);
|
|
173
|
+
const Formula = Internal__namespace.withdraw(family, store);
|
|
174
|
+
const molecule = new Formula(owners, token, ...params);
|
|
175
|
+
target.molecules.set(json.stringifyJson(key), molecule);
|
|
176
|
+
const update = {
|
|
177
|
+
type: `molecule_creation`,
|
|
178
|
+
token,
|
|
179
|
+
family,
|
|
180
|
+
context: contextArray,
|
|
181
|
+
params
|
|
182
|
+
};
|
|
183
|
+
const isTransaction = Internal__namespace.isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
184
|
+
if (isTransaction) {
|
|
185
|
+
target.transactionMeta.update.updates.push(update);
|
|
186
|
+
} else {
|
|
187
|
+
Formula.subject.next(update);
|
|
188
|
+
}
|
|
189
|
+
return token;
|
|
190
|
+
}
|
|
191
|
+
function makeMolecule(context, family, key, ...params) {
|
|
192
|
+
return makeMoleculeInStore(
|
|
193
|
+
Internal__namespace.IMPLICIT.STORE,
|
|
194
|
+
context,
|
|
195
|
+
family,
|
|
196
|
+
key,
|
|
197
|
+
...params
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
function useMoleculeFromStore(token, store) {
|
|
201
|
+
const molecule = store.molecules.get(json.stringifyJson(token.key));
|
|
202
|
+
return molecule;
|
|
203
|
+
}
|
|
204
|
+
function useMolecule(token) {
|
|
205
|
+
return useMoleculeFromStore(token, Internal__namespace.IMPLICIT.STORE);
|
|
206
|
+
}
|
|
207
|
+
function disposeMolecule(token, store) {
|
|
208
|
+
const mole = useMoleculeFromStore(token, store);
|
|
209
|
+
if (!mole || !token.family) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const { family } = token;
|
|
213
|
+
const Formula = Internal__namespace.withdraw(family, store);
|
|
214
|
+
const disposalEvent = {
|
|
215
|
+
type: `molecule_disposal`,
|
|
216
|
+
token,
|
|
217
|
+
family,
|
|
218
|
+
context: mole.above,
|
|
219
|
+
familyKeys: mole.tokens.map((t) => {
|
|
220
|
+
var _a;
|
|
221
|
+
return (_a = t.family) == null ? void 0 : _a.key;
|
|
222
|
+
}).filter((k) => typeof k === `string`)
|
|
223
|
+
};
|
|
224
|
+
if (token.family) {
|
|
225
|
+
disposalEvent.family = token.family;
|
|
226
|
+
}
|
|
227
|
+
const isTransaction = Internal__namespace.isChildStore(store) && store.transactionMeta.phase === `building`;
|
|
228
|
+
if (isTransaction) {
|
|
229
|
+
store.transactionMeta.update.updates.push(disposalEvent);
|
|
230
|
+
} else {
|
|
231
|
+
Formula.subject.next(disposalEvent);
|
|
232
|
+
}
|
|
233
|
+
mole.dispose();
|
|
234
|
+
}
|
|
235
|
+
function makeRootMolecule(key, store = Internal__namespace.IMPLICIT.STORE) {
|
|
236
|
+
const molecule = new Molecule(store, void 0, { key, type: `molecule` });
|
|
237
|
+
store.molecules.set(json.stringifyJson(key), molecule);
|
|
238
|
+
return {
|
|
239
|
+
key,
|
|
240
|
+
type: `molecule`
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function seekState(token, key) {
|
|
244
|
+
if (token.type === `molecule_family`) {
|
|
245
|
+
return Internal.seekInStore(token, key, Internal.IMPLICIT.STORE);
|
|
246
|
+
}
|
|
247
|
+
const state = Internal.seekInStore(token, key, Internal.IMPLICIT.STORE);
|
|
248
|
+
return state;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
exports.Molecule = Molecule;
|
|
252
|
+
exports.createMoleculeFamily = createMoleculeFamily;
|
|
253
|
+
exports.disposeMolecule = disposeMolecule;
|
|
254
|
+
exports.makeMolecule = makeMolecule;
|
|
255
|
+
exports.makeMoleculeInStore = makeMoleculeInStore;
|
|
256
|
+
exports.makeRootMolecule = makeRootMolecule;
|
|
257
|
+
exports.moleculeFamily = moleculeFamily;
|
|
258
|
+
exports.seekState = seekState;
|
|
259
|
+
exports.useMolecule = useMolecule;
|
|
260
|
+
exports.useMoleculeFromStore = useMoleculeFromStore;
|