atom.io 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -2
- package/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +18 -0
- package/json/dist/index.d.ts +18 -0
- package/json/dist/index.js +51 -0
- package/json/dist/index.js.map +1 -0
- package/json/dist/index.mjs +15 -0
- package/json/dist/index.mjs.map +1 -0
- package/package.json +13 -3
- package/react/dist/index.d.mts +24 -0
- package/react/dist/index.d.ts +24 -0
- package/react/dist/index.js +83 -0
- package/react/dist/index.js.map +1 -0
- package/react/dist/index.mjs +41 -0
- package/react/dist/index.mjs.map +1 -0
- package/react-devtools/dist/index.css +26 -0
- package/react-devtools/dist/index.css.map +1 -0
- package/react-devtools/dist/index.d.mts +15 -0
- package/react-devtools/dist/index.d.ts +15 -0
- package/react-devtools/dist/index.js +1596 -0
- package/react-devtools/dist/index.js.map +1 -0
- package/react-devtools/dist/index.mjs +1568 -0
- package/react-devtools/dist/index.mjs.map +1 -0
- package/realtime/dist/index.d.mts +27 -0
- package/realtime/dist/index.d.ts +27 -0
- package/realtime/dist/index.js +191 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/dist/index.mjs +152 -0
- package/realtime/dist/index.mjs.map +1 -0
- package/realtime-react/dist/index.d.mts +45 -0
- package/realtime-react/dist/index.d.ts +45 -0
- package/realtime-react/dist/index.js +213 -0
- package/realtime-react/dist/index.js.map +1 -0
- package/realtime-react/dist/index.mjs +168 -0
- package/realtime-react/dist/index.mjs.map +1 -0
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +153 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +117 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/realtime-testing/package.json +15 -0
- package/src/atom.ts +15 -15
- package/src/index.ts +59 -59
- package/src/internal/atom-internal.ts +36 -36
- package/src/internal/families-internal.ts +114 -114
- package/src/internal/get.ts +83 -83
- package/src/internal/is-default.ts +17 -17
- package/src/internal/meta/attach-meta.ts +7 -7
- package/src/internal/meta/meta-state.ts +115 -115
- package/src/internal/operation.ts +93 -93
- package/src/internal/selector/create-read-write-selector.ts +46 -46
- package/src/internal/selector/create-readonly-selector.ts +37 -37
- package/src/internal/selector/lookup-selector-sources.ts +9 -9
- package/src/internal/selector/register-selector.ts +44 -44
- package/src/internal/selector/trace-selector-atoms.ts +30 -30
- package/src/internal/selector/update-selector-atoms.ts +25 -25
- package/src/internal/selector-internal.ts +37 -37
- package/src/internal/set.ts +78 -78
- package/src/internal/store.ts +118 -118
- package/src/internal/subscribe-internal.ts +62 -62
- package/src/internal/time-travel-internal.ts +76 -76
- package/src/internal/timeline/add-atom-to-timeline.ts +158 -153
- package/src/internal/timeline-internal.ts +80 -80
- package/src/internal/transaction/abort-transaction.ts +8 -8
- package/src/internal/transaction/apply-transaction.ts +41 -41
- package/src/internal/transaction/build-transaction.ts +28 -28
- package/src/internal/transaction/index.ts +7 -7
- package/src/internal/transaction/redo-transaction.ts +13 -13
- package/src/internal/transaction/undo-transaction.ts +13 -13
- package/src/internal/transaction-internal.ts +48 -48
- package/src/json/select-json.ts +12 -12
- package/src/logger.ts +30 -30
- package/src/react/store-context.tsx +4 -4
- package/src/react/store-hooks.ts +18 -18
- package/src/react-devtools/AtomIODevtools.tsx +83 -82
- package/src/react-devtools/StateEditor.tsx +53 -53
- package/src/react-devtools/TokenList.tsx +47 -42
- package/src/react-explorer/AtomIOExplorer.tsx +197 -185
- package/src/react-explorer/explorer-effects.ts +11 -11
- package/src/react-explorer/explorer-states.ts +186 -193
- package/src/react-explorer/index.ts +11 -11
- package/src/react-explorer/space-states.ts +48 -50
- package/src/react-explorer/view-states.ts +25 -25
- package/src/realtime/hook-composition/expose-family.ts +81 -81
- package/src/realtime/hook-composition/expose-single.ts +26 -26
- package/src/realtime/hook-composition/expose-timeline.ts +60 -0
- package/src/realtime/hook-composition/index.ts +2 -2
- package/src/realtime/hook-composition/receive-state.ts +18 -18
- package/src/realtime/hook-composition/receive-transaction.ts +8 -8
- package/src/realtime-react/realtime-context.tsx +17 -17
- package/src/realtime-react/realtime-hooks.ts +17 -17
- package/src/realtime-react/realtime-state.ts +4 -4
- package/src/realtime-react/use-pull-family-member.ts +15 -15
- package/src/realtime-react/use-pull-family.ts +13 -13
- package/src/realtime-react/use-pull.ts +12 -12
- package/src/realtime-react/use-push.ts +15 -15
- package/src/realtime-react/use-server-action.ts +21 -21
- package/src/realtime-testing/index.ts +1 -0
- package/src/realtime-testing/setup-realtime-test.tsx +160 -0
- package/src/selector.ts +25 -25
- package/src/silo.ts +38 -38
- package/src/subscribe.ts +68 -68
- package/src/timeline.ts +13 -13
- package/src/transaction.ts +28 -28
- package/src/web-effects/storage.ts +17 -17
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import type { Store } from ".."
|
|
2
2
|
|
|
3
3
|
export const buildTransaction = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
key: string,
|
|
5
|
+
params: any[],
|
|
6
|
+
store: Store,
|
|
7
7
|
): void => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
store.transactionStatus = {
|
|
9
|
+
key,
|
|
10
|
+
phase: `building`,
|
|
11
|
+
time: Date.now(),
|
|
12
|
+
core: {
|
|
13
|
+
atoms: store.atoms,
|
|
14
|
+
atomsThatAreDefault: store.atomsThatAreDefault,
|
|
15
|
+
operation: { open: false },
|
|
16
|
+
readonlySelectors: store.readonlySelectors,
|
|
17
|
+
timelines: store.timelines,
|
|
18
|
+
timelineAtoms: store.timelineAtoms,
|
|
19
|
+
transactions: store.transactions,
|
|
20
|
+
selectorAtoms: store.selectorAtoms,
|
|
21
|
+
selectorGraph: store.selectorGraph,
|
|
22
|
+
selectors: store.selectors,
|
|
23
|
+
valueMap: store.valueMap,
|
|
24
|
+
},
|
|
25
|
+
atomUpdates: [],
|
|
26
|
+
params,
|
|
27
|
+
output: undefined,
|
|
28
|
+
}
|
|
29
|
+
store.config.logger?.info(
|
|
30
|
+
`🛫`,
|
|
31
|
+
`transaction "${key}" started in store "${store.config.name}"`,
|
|
32
|
+
)
|
|
33
33
|
}
|
|
@@ -10,16 +10,16 @@ export * from "./redo-transaction"
|
|
|
10
10
|
export * from "./undo-transaction"
|
|
11
11
|
|
|
12
12
|
export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
|
|
13
|
-
export type TransactionPhase =
|
|
13
|
+
export type TransactionPhase = typeof TRANSACTION_PHASES[number]
|
|
14
14
|
|
|
15
15
|
export type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
phase: `applying` | `building`
|
|
17
|
+
time: number
|
|
18
|
+
core: StoreCore
|
|
19
19
|
}
|
|
20
20
|
export type TransactionIdle = {
|
|
21
|
-
|
|
21
|
+
phase: `idle`
|
|
22
22
|
}
|
|
23
23
|
export type TransactionStatus<ƒ extends ƒn> =
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
| TransactionIdle
|
|
25
|
+
| TransactionUpdateInProgress<ƒ>
|
|
@@ -6,18 +6,18 @@ import type { AtomToken, TransactionUpdate } from "../.."
|
|
|
6
6
|
import { setState } from "../.."
|
|
7
7
|
|
|
8
8
|
export const redoTransactionUpdate = <ƒ extends ƒn>(
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
update: TransactionUpdate<ƒ>,
|
|
10
|
+
store: Store,
|
|
11
11
|
): void => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
store.config.logger?.info(` ⏭ redo transaction "${update.key}" (redo)`)
|
|
13
|
+
for (const { key, newValue } of update.atomUpdates) {
|
|
14
|
+
const token: AtomToken<unknown> = { key, type: `atom` }
|
|
15
|
+
const state = withdraw(token, store)
|
|
16
|
+
if (state === null) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
setState(state, newValue, store)
|
|
22
|
+
}
|
|
23
23
|
}
|
|
@@ -6,18 +6,18 @@ import type { AtomToken, TransactionUpdate } from "../.."
|
|
|
6
6
|
import { setState } from "../.."
|
|
7
7
|
|
|
8
8
|
export const undoTransactionUpdate = <ƒ extends ƒn>(
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
update: TransactionUpdate<ƒ>,
|
|
10
|
+
store: Store,
|
|
11
11
|
): void => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
store.config.logger?.info(` ⏮ undo transaction "${update.key}" (undo)`)
|
|
13
|
+
for (const { key, oldValue } of update.atomUpdates) {
|
|
14
|
+
const token: AtomToken<unknown> = { key, type: `atom` }
|
|
15
|
+
const state = withdraw(token, store)
|
|
16
|
+
if (state === null) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
setState(state, oldValue, store)
|
|
22
|
+
}
|
|
23
23
|
}
|
|
@@ -5,63 +5,63 @@ import type { ƒn } from "~/packages/anvl/src/function"
|
|
|
5
5
|
|
|
6
6
|
import type { Store, StoreCore } from "."
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
abortTransaction,
|
|
9
|
+
applyTransaction,
|
|
10
|
+
buildTransaction,
|
|
11
|
+
deposit,
|
|
12
|
+
IMPLICIT,
|
|
13
13
|
} from "."
|
|
14
14
|
import type { TransactionOptions, TransactionToken, TransactionUpdate } from ".."
|
|
15
15
|
import { getState, setState } from ".."
|
|
16
16
|
|
|
17
17
|
export type Transaction<ƒ extends ƒn> = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
key: string
|
|
19
|
+
type: `transaction`
|
|
20
|
+
install: (store: Store) => void
|
|
21
|
+
subject: Rx.Subject<TransactionUpdate<ƒ>>
|
|
22
|
+
run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function transaction__INTERNAL<ƒ extends ƒn>(
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
options: TransactionOptions<ƒ>,
|
|
27
|
+
store: Store = IMPLICIT.STORE,
|
|
28
28
|
): TransactionToken<ƒ> {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
29
|
+
const newTransaction: Transaction<ƒ> = {
|
|
30
|
+
key: options.key,
|
|
31
|
+
type: `transaction`,
|
|
32
|
+
run: (...params: Parameters<ƒ>) => {
|
|
33
|
+
buildTransaction(options.key, params, store)
|
|
34
|
+
try {
|
|
35
|
+
const output = options.do(
|
|
36
|
+
{
|
|
37
|
+
get: (token) => getState(token, store),
|
|
38
|
+
set: (token, value) => setState(token, value, store),
|
|
39
|
+
},
|
|
40
|
+
...params,
|
|
41
|
+
)
|
|
42
|
+
applyTransaction(output, store)
|
|
43
|
+
return output
|
|
44
|
+
} catch (thrown) {
|
|
45
|
+
abortTransaction(store)
|
|
46
|
+
store.config.logger?.error(`Transaction ${options.key} failed`, thrown)
|
|
47
|
+
throw thrown
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
install: (store) => transaction__INTERNAL(options, store),
|
|
51
|
+
subject: new Rx.Subject(),
|
|
52
|
+
}
|
|
53
|
+
const core = target(store)
|
|
54
|
+
core.transactions = HAMT.set(
|
|
55
|
+
newTransaction.key,
|
|
56
|
+
newTransaction,
|
|
57
|
+
core.transactions,
|
|
58
|
+
)
|
|
59
|
+
const token = deposit(newTransaction)
|
|
60
|
+
store.subject.transactionCreation.next(token)
|
|
61
|
+
return token
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export const target = (store: Store = IMPLICIT.STORE): StoreCore =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
store.transactionStatus.phase === `building`
|
|
66
|
+
? store.transactionStatus.core
|
|
67
|
+
: store
|
package/src/json/select-json.ts
CHANGED
|
@@ -3,16 +3,16 @@ import * as AtomIO from "atom.io"
|
|
|
3
3
|
import type { Json, JsonInterface } from "~/packages/anvl/src/json"
|
|
4
4
|
|
|
5
5
|
export const selectJson = <T, J extends Json>(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
atom: AtomIO.AtomToken<T>,
|
|
7
|
+
transform: JsonInterface<T, J>,
|
|
8
|
+
store: AtomIO.Store = AtomIO.__INTERNAL__.IMPLICIT.STORE,
|
|
9
9
|
): AtomIO.SelectorToken<J> =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
AtomIO.__INTERNAL__.selector__INTERNAL(
|
|
11
|
+
{
|
|
12
|
+
key: `${atom.key}JSON`,
|
|
13
|
+
get: ({ get }) => transform.toJson(get(atom)),
|
|
14
|
+
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),
|
|
15
|
+
},
|
|
16
|
+
undefined,
|
|
17
|
+
store,
|
|
18
|
+
)
|
package/src/logger.ts
CHANGED
|
@@ -5,42 +5,42 @@ import { IMPLICIT } from "./internal/store"
|
|
|
5
5
|
|
|
6
6
|
export type Logger = Pick<Console, `error` | `info` | `warn`>
|
|
7
7
|
export const LOG_LEVELS: ReadonlyArray<keyof Logger> = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
`info`,
|
|
9
|
+
`warn`,
|
|
10
|
+
`error`,
|
|
11
11
|
] as const
|
|
12
12
|
|
|
13
13
|
export const setLogLevel = (
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
preferredLevel: `error` | `info` | `warn` | null,
|
|
15
|
+
store: Store = IMPLICIT.STORE,
|
|
16
16
|
): void => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
const { logger__INTERNAL } = store.config
|
|
18
|
+
if (preferredLevel === null) {
|
|
19
|
+
store.config.logger = null
|
|
20
|
+
} else {
|
|
21
|
+
store.config.logger = { ...console }
|
|
22
|
+
LOG_LEVELS.forEach((logLevel) => {
|
|
23
|
+
if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
|
|
24
|
+
// rome-ignore lint/style/noNonNullAssertion: we just set it
|
|
25
|
+
store.config.logger![logLevel] = doNothing
|
|
26
|
+
} else {
|
|
27
|
+
// rome-ignore lint/style/noNonNullAssertion: we just set it
|
|
28
|
+
store.config.logger![logLevel] = logger__INTERNAL[logLevel]
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export const useLogger = (
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
logger: Logger,
|
|
36
|
+
store: Store = IMPLICIT.STORE,
|
|
37
37
|
): void => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const currentLogLevel =
|
|
39
|
+
store.config.logger === null
|
|
40
|
+
? null
|
|
41
|
+
: LOG_LEVELS.find(
|
|
42
|
+
(logLevel) => store.config.logger?.[logLevel] !== doNothing,
|
|
43
|
+
) ?? null
|
|
44
|
+
store.config.logger__INTERNAL = { ...logger }
|
|
45
|
+
setLogLevel(currentLogLevel, store)
|
|
46
46
|
}
|
|
@@ -3,12 +3,12 @@ import * as React from "react"
|
|
|
3
3
|
import * as AtomIO from "atom.io"
|
|
4
4
|
|
|
5
5
|
export const StoreContext = React.createContext<AtomIO.Store>(
|
|
6
|
-
|
|
6
|
+
AtomIO.__INTERNAL__.IMPLICIT.STORE,
|
|
7
7
|
)
|
|
8
8
|
|
|
9
9
|
export const StoreProvider: React.FC<{
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
children: React.ReactNode
|
|
11
|
+
store?: AtomIO.Store
|
|
12
12
|
}> = ({ children, store = AtomIO.__INTERNAL__.IMPLICIT.STORE }) => (
|
|
13
|
-
|
|
13
|
+
<StoreContext.Provider value={store}>{children}</StoreContext.Provider>
|
|
14
14
|
)
|
package/src/react/store-hooks.ts
CHANGED
|
@@ -7,42 +7,42 @@ import type { Modifier } from "~/packages/anvl/src/function"
|
|
|
7
7
|
import { StoreContext } from "./store-context"
|
|
8
8
|
|
|
9
9
|
export type StoreHooks = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
useI: <T>(token: AtomIO.StateToken<T>) => (next: Modifier<T> | T) => void
|
|
11
|
+
useO: <T>(token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>) => T
|
|
12
|
+
useIO: <T>(token: AtomIO.StateToken<T>) => [T, (next: Modifier<T> | T) => void]
|
|
13
13
|
}
|
|
14
14
|
export const storeHooks: StoreHooks = { useI, useO, useIO }
|
|
15
15
|
|
|
16
16
|
export function useI<T>(
|
|
17
|
-
|
|
17
|
+
token: AtomIO.StateToken<T>,
|
|
18
18
|
): (next: Modifier<T> | T) => void {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const store = React.useContext(StoreContext)
|
|
20
|
+
const update = (next: Modifier<T> | T) => AtomIO.setState(token, next, store)
|
|
21
|
+
return update
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function useO<T>(
|
|
25
|
-
|
|
25
|
+
token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>,
|
|
26
26
|
): T {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const store = React.useContext(StoreContext)
|
|
28
|
+
return React.useSyncExternalStore<T>(
|
|
29
|
+
(observe) => AtomIO.subscribe(token, observe, store),
|
|
30
|
+
() => AtomIO.getState(token, store),
|
|
31
|
+
)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function useIO<T>(
|
|
35
|
-
|
|
35
|
+
token: AtomIO.StateToken<T>,
|
|
36
36
|
): [T, (next: Modifier<T> | T) => void] {
|
|
37
|
-
|
|
37
|
+
return [useO(token), useI(token)]
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export function useStore<T>(
|
|
41
|
-
|
|
41
|
+
token: AtomIO.StateToken<T>,
|
|
42
42
|
): [T, (next: Modifier<T> | T) => void]
|
|
43
43
|
export function useStore<T>(token: AtomIO.ReadonlySelectorToken<T>): T
|
|
44
44
|
export function useStore<T>(
|
|
45
|
-
|
|
45
|
+
token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>,
|
|
46
46
|
): T | [T, (next: Modifier<T> | T) => void] {
|
|
47
|
-
|
|
47
|
+
return token.type === `readonly_selector` ? useO(token) : useIO(token)
|
|
48
48
|
}
|
|
@@ -12,96 +12,97 @@ import { lazyLocalStorageEffect } from "../web-effects"
|
|
|
12
12
|
import "./devtools.scss"
|
|
13
13
|
|
|
14
14
|
const { atomTokenIndexState, selectorTokenIndexState } =
|
|
15
|
-
|
|
15
|
+
__INTERNAL__.META.attachMetaState()
|
|
16
16
|
|
|
17
17
|
const devtoolsAreOpenState = atom<boolean>({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
key: `👁🗨_devtools_are_open`,
|
|
19
|
+
default: true,
|
|
20
|
+
effects: [lazyLocalStorageEffect(`👁🗨_devtools_are_open`)],
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
export const composeDevtools = (storeHooks: StoreHooks): FC => {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const Devtools: FC = () => {
|
|
25
|
+
const constraintsRef = useRef(null)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const [devtoolsAreOpen, setDevtoolsAreOpen] =
|
|
28
|
+
storeHooks.useIO(devtoolsAreOpenState)
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const mouseHasMoved = useRef(false)
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
<motion.span
|
|
35
|
+
ref={constraintsRef}
|
|
36
|
+
className="atom_io_devtools_zone"
|
|
37
|
+
style={{
|
|
38
|
+
position: `fixed`,
|
|
39
|
+
top: 0,
|
|
40
|
+
left: 0,
|
|
41
|
+
right: 0,
|
|
42
|
+
bottom: 0,
|
|
43
|
+
pointerEvents: `none`,
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
<motion.main
|
|
47
|
+
drag
|
|
48
|
+
dragConstraints={constraintsRef}
|
|
49
|
+
className="atom_io_devtools"
|
|
50
|
+
transition={spring}
|
|
51
|
+
style={
|
|
52
|
+
devtoolsAreOpen
|
|
53
|
+
? {}
|
|
54
|
+
: {
|
|
55
|
+
backgroundColor: `#0000`,
|
|
56
|
+
borderColor: `#0000`,
|
|
57
|
+
maxHeight: 28,
|
|
58
|
+
maxWidth: 33,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
>
|
|
62
|
+
{devtoolsAreOpen ? (
|
|
63
|
+
<>
|
|
64
|
+
<motion.header>
|
|
65
|
+
<h1>atom.io</h1>
|
|
66
|
+
</motion.header>
|
|
67
|
+
<motion.main>
|
|
68
|
+
<LayoutGroup>
|
|
69
|
+
<section>
|
|
70
|
+
<h2>atoms</h2>
|
|
71
|
+
<TokenList
|
|
72
|
+
storeHooks={storeHooks}
|
|
73
|
+
tokenIndex={atomTokenIndexState}
|
|
74
|
+
/>
|
|
75
|
+
</section>
|
|
76
|
+
<section>
|
|
77
|
+
<h2>selectors</h2>
|
|
78
|
+
<TokenList
|
|
79
|
+
storeHooks={storeHooks}
|
|
80
|
+
tokenIndex={selectorTokenIndexState}
|
|
81
|
+
/>
|
|
82
|
+
</section>
|
|
83
|
+
</LayoutGroup>
|
|
84
|
+
</motion.main>
|
|
85
|
+
</>
|
|
86
|
+
) : null}
|
|
87
|
+
<footer>
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
onMouseDown={() => (mouseHasMoved.current = false)}
|
|
91
|
+
onMouseMove={() => (mouseHasMoved.current = true)}
|
|
92
|
+
onMouseUp={() => {
|
|
93
|
+
if (!mouseHasMoved.current) {
|
|
94
|
+
setDevtoolsAreOpen((open) => !open)
|
|
95
|
+
}
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
👁🗨
|
|
99
|
+
</button>
|
|
100
|
+
</footer>
|
|
101
|
+
</motion.main>
|
|
102
|
+
</>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
return Devtools
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
export const AtomIODevtools = composeDevtools({ useI, useO, useIO })
|