atom.io 0.6.5 → 0.6.7
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/README.md +32 -78
- package/dist/index.d.mts +11 -43
- package/dist/index.d.ts +11 -43
- package/dist/index.js +111 -291
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -278
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +273 -0
- package/introspection/dist/index.d.ts +273 -0
- package/introspection/dist/index.js +350 -0
- package/introspection/dist/index.js.map +1 -0
- package/introspection/dist/index.mjs +327 -0
- package/introspection/dist/index.mjs.map +1 -0
- package/introspection/package.json +15 -0
- package/package.json +22 -12
- package/react-devtools/dist/index.css +22 -5
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +347 -10
- package/react-devtools/dist/index.d.ts +347 -10
- package/react-devtools/dist/index.js +2743 -696
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +2739 -701
- package/react-devtools/dist/index.mjs.map +1 -1
- package/src/internal/atom-internal.ts +5 -6
- package/src/internal/get.ts +7 -9
- package/src/internal/index.ts +0 -1
- package/src/internal/operation.ts +15 -21
- package/src/internal/selector/create-read-write-selector.ts +8 -4
- package/src/internal/selector/create-readonly-selector.ts +1 -7
- package/src/internal/selector-internal.ts +1 -3
- package/src/internal/set.ts +1 -4
- package/src/internal/store.ts +22 -24
- package/src/internal/subscribe-internal.ts +7 -1
- package/src/internal/time-travel-internal.ts +2 -0
- package/src/internal/timeline/add-atom-to-timeline.ts +11 -12
- package/src/internal/timeline-internal.ts +6 -4
- package/src/internal/transaction/apply-transaction.ts +9 -6
- package/src/internal/transaction/build-transaction.ts +6 -6
- package/src/internal/transaction-internal.ts +1 -7
- package/src/introspection/attach-atom-index.ts +73 -0
- package/src/introspection/attach-introspection-states.ts +42 -0
- package/src/introspection/attach-selector-index.ts +77 -0
- package/src/introspection/attach-timeline-family.ts +59 -0
- package/src/introspection/attach-timeline-index.ts +36 -0
- package/src/introspection/attach-transaction-index.ts +38 -0
- package/src/introspection/attach-transaction-logs.ts +40 -0
- package/src/introspection/index.ts +20 -0
- package/src/react-devtools/AtomIODevtools.tsx +97 -97
- package/src/react-devtools/Button.tsx +24 -0
- package/src/react-devtools/StateEditor.tsx +14 -16
- package/src/react-devtools/StateIndex.tsx +153 -0
- package/src/react-devtools/TimelineIndex.tsx +92 -0
- package/src/react-devtools/TransactionIndex.tsx +70 -0
- package/src/react-devtools/Updates.tsx +145 -0
- package/src/react-devtools/devtools.scss +196 -15
- package/src/react-devtools/index.ts +71 -0
- package/src/react-explorer/AtomIOExplorer.tsx +3 -4
- package/src/react-explorer/explorer-states.ts +1 -1
- package/src/react-explorer/space-states.ts +3 -1
- package/src/react-explorer/view-states.ts +0 -2
- package/realtime-testing/dist/index.d.mts +0 -49
- package/realtime-testing/dist/index.d.ts +0 -49
- package/realtime-testing/dist/index.js +0 -165
- package/realtime-testing/dist/index.js.map +0 -1
- package/realtime-testing/dist/index.mjs +0 -129
- package/realtime-testing/dist/index.mjs.map +0 -1
- package/src/internal/meta/attach-meta.ts +0 -17
- package/src/internal/meta/index.ts +0 -4
- package/src/internal/meta/meta-state.ts +0 -135
- package/src/internal/meta/meta-timelines.ts +0 -1
- package/src/internal/meta/meta-transactions.ts +0 -1
- package/src/react-devtools/TokenList.tsx +0 -61
|
@@ -1 +1,72 @@
|
|
|
1
|
+
import { isPlainObject } from "~/packages/anvl/src/object"
|
|
2
|
+
import { Refinery } from "~/packages/anvl/src/refinement/refinery"
|
|
3
|
+
import {
|
|
4
|
+
diffArray,
|
|
5
|
+
diffBoolean,
|
|
6
|
+
diffNumber,
|
|
7
|
+
diffObject,
|
|
8
|
+
diffString,
|
|
9
|
+
Differ,
|
|
10
|
+
} from "~/packages/anvl/src/tree/differ"
|
|
11
|
+
|
|
12
|
+
import { atom, atomFamily } from ".."
|
|
13
|
+
import { attachIntrospectionStates } from "../introspection"
|
|
14
|
+
import { lazyLocalStorageEffect } from "../web-effects"
|
|
15
|
+
|
|
1
16
|
export * from "./AtomIODevtools"
|
|
17
|
+
|
|
18
|
+
export const {
|
|
19
|
+
atomIndex,
|
|
20
|
+
selectorIndex,
|
|
21
|
+
transactionIndex,
|
|
22
|
+
findTransactionLogState,
|
|
23
|
+
timelineIndex,
|
|
24
|
+
findTimelineState,
|
|
25
|
+
} = attachIntrospectionStates()
|
|
26
|
+
|
|
27
|
+
export const devtoolsAreOpenState = atom<boolean>({
|
|
28
|
+
key: `👁🗨 Devtools Are Open`,
|
|
29
|
+
default: true,
|
|
30
|
+
effects: [lazyLocalStorageEffect(`👁🗨 Devtools Are Open`)],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
type DevtoolsView = `atoms` | `selectors` | `timelines` | `transactions`
|
|
34
|
+
|
|
35
|
+
export const devtoolsViewSelectionState = atom<DevtoolsView>({
|
|
36
|
+
key: `👁🗨 Devtools View Selection`,
|
|
37
|
+
default: `atoms`,
|
|
38
|
+
effects: [lazyLocalStorageEffect(`👁🗨 Devtools View`)],
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export const devtoolsViewOptionsState = atom<DevtoolsView[]>({
|
|
42
|
+
key: `👁🗨 Devtools View Options`,
|
|
43
|
+
default: [`atoms`, `selectors`, `transactions`, `timelines`],
|
|
44
|
+
effects: [lazyLocalStorageEffect(`👁🗨 Devtools View Options`)],
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
export const findViewIsOpenState = atomFamily<boolean, string>({
|
|
48
|
+
key: `👁🗨 Devtools View Is Open`,
|
|
49
|
+
default: false,
|
|
50
|
+
effects: (key) => [lazyLocalStorageEffect(key + `:view-is-open`)],
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
export const primitiveRefinery = new Refinery({
|
|
54
|
+
number: (input: unknown): input is number => typeof input === `number`,
|
|
55
|
+
string: (input: unknown): input is string => typeof input === `string`,
|
|
56
|
+
boolean: (input: unknown): input is boolean => typeof input === `boolean`,
|
|
57
|
+
null: (input: unknown): input is null => input === null,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
export const jsonTreeRefinery = new Refinery({
|
|
61
|
+
object: isPlainObject,
|
|
62
|
+
array: (input: unknown): input is unknown[] => Array.isArray(input),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
export const prettyJson = new Differ(primitiveRefinery, jsonTreeRefinery, {
|
|
66
|
+
number: diffNumber,
|
|
67
|
+
string: diffString,
|
|
68
|
+
boolean: diffBoolean,
|
|
69
|
+
null: () => ({ summary: `No Change` }),
|
|
70
|
+
object: diffObject,
|
|
71
|
+
array: diffArray,
|
|
72
|
+
})
|
|
@@ -3,7 +3,7 @@ import type { FC, ReactNode } from "react"
|
|
|
3
3
|
import { useEffect } from "react"
|
|
4
4
|
import { Link, MemoryRouter, useLocation } from "react-router-dom"
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { RecoverableErrorBoundary } from "~/packages/hamr/src/react-error-boundary"
|
|
7
7
|
import type { WC } from "~/packages/hamr/src/react-json-editor"
|
|
8
8
|
|
|
9
9
|
import { attachExplorerState } from "./explorer-states"
|
|
@@ -132,14 +132,14 @@ export const composeExplorer = ({
|
|
|
132
132
|
const view = useO(findViewState(focusedViewId))
|
|
133
133
|
return (
|
|
134
134
|
<div className="space">
|
|
135
|
-
<
|
|
135
|
+
<RecoverableErrorBoundary>
|
|
136
136
|
<MemoryRouter
|
|
137
137
|
initialEntries={view.location ? [view.location.pathname] : []}
|
|
138
138
|
>
|
|
139
139
|
<TabBar spaceId={spaceId} viewIds={viewIds} />
|
|
140
140
|
<View viewId={focusedViewId}>{children}</View>
|
|
141
141
|
</MemoryRouter>
|
|
142
|
-
</
|
|
142
|
+
</RecoverableErrorBoundary>
|
|
143
143
|
</div>
|
|
144
144
|
)
|
|
145
145
|
}
|
|
@@ -151,7 +151,6 @@ export const composeExplorer = ({
|
|
|
151
151
|
const spaceLayout = useO(findSpaceLayoutNode(spaceId))
|
|
152
152
|
const viewIds = useO(findSpaceViewsState(spaceId))
|
|
153
153
|
const focusedViewId = useO(findSpaceFocusedViewState(spaceId))
|
|
154
|
-
console.log({ spaceLayout, viewIds, focusedViewId })
|
|
155
154
|
return (
|
|
156
155
|
<div className="spaces">
|
|
157
156
|
{spaceLayout.childSpaceIds.length === 0 ? (
|
|
@@ -31,7 +31,7 @@ export const makeViewsPerSpaceState = (
|
|
|
31
31
|
): AtomToken<Join<null, `viewId`, `spaceId`>> =>
|
|
32
32
|
atom<Join<null, `viewId`, `spaceId`>>({
|
|
33
33
|
key: `${key}:views_per_space`,
|
|
34
|
-
default: new Join({ relationType: `1:n` }),
|
|
34
|
+
default: new Join({ relationType: `1:n` }).from(`viewId`).to(`spaceId`),
|
|
35
35
|
effects: [
|
|
36
36
|
persistAtom<Join<null, `viewId`, `spaceId`>>(localStorage)({
|
|
37
37
|
stringify: (index) => JSON.stringify(index.toJSON()),
|
|
@@ -21,7 +21,9 @@ export const makeSpaceLayoutState = (
|
|
|
21
21
|
): AtomToken<Join<{ size: number }, `parent`, `child`>> =>
|
|
22
22
|
atom({
|
|
23
23
|
key: `${key}:space_layout`,
|
|
24
|
-
default: new Join({ relationType: `1:n` })
|
|
24
|
+
default: new Join<{ size: number }>({ relationType: `1:n` })
|
|
25
|
+
.from(`parent`)
|
|
26
|
+
.to(`child`),
|
|
25
27
|
effects: [
|
|
26
28
|
persistAtom<Join<{ size: number }, `parent`, `child`>>(localStorage)({
|
|
27
29
|
stringify: (join) => stringifyJson(join.toJSON()),
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { RenderResult } from '@testing-library/react';
|
|
2
|
-
import * as AtomIO from 'atom.io';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import * as SocketIO from 'socket.io';
|
|
5
|
-
|
|
6
|
-
type TestSetupOptions = {
|
|
7
|
-
server: (tools: {
|
|
8
|
-
socket: SocketIO.Socket;
|
|
9
|
-
silo: AtomIO.Silo;
|
|
10
|
-
}) => void;
|
|
11
|
-
};
|
|
12
|
-
type TestSetupOptions__SingleClient = TestSetupOptions & {
|
|
13
|
-
client: React.FC;
|
|
14
|
-
};
|
|
15
|
-
type TestSetupOptions__MultiClient<ClientNames extends string> = TestSetupOptions & {
|
|
16
|
-
clients: {
|
|
17
|
-
[K in ClientNames]: React.FC;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
type RealtimeTestTools = {
|
|
21
|
-
name: string;
|
|
22
|
-
silo: AtomIO.Silo;
|
|
23
|
-
dispose: () => void;
|
|
24
|
-
};
|
|
25
|
-
type RealtimeTestClient = RealtimeTestTools & {
|
|
26
|
-
renderResult: RenderResult;
|
|
27
|
-
prettyPrint: () => void;
|
|
28
|
-
reconnect: () => void;
|
|
29
|
-
disconnect: () => void;
|
|
30
|
-
};
|
|
31
|
-
type RealtimeTestServer = RealtimeTestTools & {
|
|
32
|
-
port: number;
|
|
33
|
-
};
|
|
34
|
-
type RealtimeTestAPI = {
|
|
35
|
-
server: RealtimeTestServer;
|
|
36
|
-
teardown: () => void;
|
|
37
|
-
};
|
|
38
|
-
type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {
|
|
39
|
-
client: RealtimeTestClient;
|
|
40
|
-
};
|
|
41
|
-
type RealtimeTestAPI__MultiClient<ClientNames extends string> = RealtimeTestAPI & {
|
|
42
|
-
clients: Record<ClientNames, RealtimeTestClient>;
|
|
43
|
-
};
|
|
44
|
-
declare const setupRealtimeTestServer: (options: TestSetupOptions) => RealtimeTestServer;
|
|
45
|
-
declare const setupRealtimeTestClient: (options: TestSetupOptions__SingleClient, name: string, port: number) => RealtimeTestClient;
|
|
46
|
-
declare const singleClient: (options: TestSetupOptions__SingleClient) => RealtimeTestAPI__SingleClient;
|
|
47
|
-
declare const multiClient: <ClientNames extends string>(options: TestSetupOptions__MultiClient<ClientNames>) => RealtimeTestAPI__MultiClient<ClientNames>;
|
|
48
|
-
|
|
49
|
-
export { RealtimeTestAPI, RealtimeTestAPI__MultiClient, RealtimeTestAPI__SingleClient, RealtimeTestClient, RealtimeTestServer, RealtimeTestTools, TestSetupOptions, TestSetupOptions__MultiClient, TestSetupOptions__SingleClient, multiClient, setupRealtimeTestClient, setupRealtimeTestServer, singleClient };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { RenderResult } from '@testing-library/react';
|
|
2
|
-
import * as AtomIO from 'atom.io';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import * as SocketIO from 'socket.io';
|
|
5
|
-
|
|
6
|
-
type TestSetupOptions = {
|
|
7
|
-
server: (tools: {
|
|
8
|
-
socket: SocketIO.Socket;
|
|
9
|
-
silo: AtomIO.Silo;
|
|
10
|
-
}) => void;
|
|
11
|
-
};
|
|
12
|
-
type TestSetupOptions__SingleClient = TestSetupOptions & {
|
|
13
|
-
client: React.FC;
|
|
14
|
-
};
|
|
15
|
-
type TestSetupOptions__MultiClient<ClientNames extends string> = TestSetupOptions & {
|
|
16
|
-
clients: {
|
|
17
|
-
[K in ClientNames]: React.FC;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
type RealtimeTestTools = {
|
|
21
|
-
name: string;
|
|
22
|
-
silo: AtomIO.Silo;
|
|
23
|
-
dispose: () => void;
|
|
24
|
-
};
|
|
25
|
-
type RealtimeTestClient = RealtimeTestTools & {
|
|
26
|
-
renderResult: RenderResult;
|
|
27
|
-
prettyPrint: () => void;
|
|
28
|
-
reconnect: () => void;
|
|
29
|
-
disconnect: () => void;
|
|
30
|
-
};
|
|
31
|
-
type RealtimeTestServer = RealtimeTestTools & {
|
|
32
|
-
port: number;
|
|
33
|
-
};
|
|
34
|
-
type RealtimeTestAPI = {
|
|
35
|
-
server: RealtimeTestServer;
|
|
36
|
-
teardown: () => void;
|
|
37
|
-
};
|
|
38
|
-
type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {
|
|
39
|
-
client: RealtimeTestClient;
|
|
40
|
-
};
|
|
41
|
-
type RealtimeTestAPI__MultiClient<ClientNames extends string> = RealtimeTestAPI & {
|
|
42
|
-
clients: Record<ClientNames, RealtimeTestClient>;
|
|
43
|
-
};
|
|
44
|
-
declare const setupRealtimeTestServer: (options: TestSetupOptions) => RealtimeTestServer;
|
|
45
|
-
declare const setupRealtimeTestClient: (options: TestSetupOptions__SingleClient, name: string, port: number) => RealtimeTestClient;
|
|
46
|
-
declare const singleClient: (options: TestSetupOptions__SingleClient) => RealtimeTestAPI__SingleClient;
|
|
47
|
-
declare const multiClient: <ClientNames extends string>(options: TestSetupOptions__MultiClient<ClientNames>) => RealtimeTestAPI__MultiClient<ClientNames>;
|
|
48
|
-
|
|
49
|
-
export { RealtimeTestAPI, RealtimeTestAPI__MultiClient, RealtimeTestAPI__SingleClient, RealtimeTestClient, RealtimeTestServer, RealtimeTestTools, TestSetupOptions, TestSetupOptions__MultiClient, TestSetupOptions__SingleClient, multiClient, setupRealtimeTestClient, setupRealtimeTestServer, singleClient };
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __export = (target, all) => {
|
|
25
|
-
for (var name in all)
|
|
26
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
-
};
|
|
28
|
-
var __copyProps = (to, from, except, desc) => {
|
|
29
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
-
for (let key of __getOwnPropNames(from))
|
|
31
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
-
}
|
|
34
|
-
return to;
|
|
35
|
-
};
|
|
36
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
-
mod
|
|
43
|
-
));
|
|
44
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
-
|
|
46
|
-
// ../src/realtime-testing/index.ts
|
|
47
|
-
var realtime_testing_exports = {};
|
|
48
|
-
__export(realtime_testing_exports, {
|
|
49
|
-
multiClient: () => multiClient,
|
|
50
|
-
setupRealtimeTestClient: () => setupRealtimeTestClient,
|
|
51
|
-
setupRealtimeTestServer: () => setupRealtimeTestServer,
|
|
52
|
-
singleClient: () => singleClient
|
|
53
|
-
});
|
|
54
|
-
module.exports = __toCommonJS(realtime_testing_exports);
|
|
55
|
-
|
|
56
|
-
// ../src/realtime-testing/setup-realtime-test.tsx
|
|
57
|
-
var http = __toESM(require("http"));
|
|
58
|
-
var import_react = require("@testing-library/react");
|
|
59
|
-
var AtomIO = __toESM(require("atom.io"));
|
|
60
|
-
var AR = __toESM(require("atom.io/react"));
|
|
61
|
-
var RTC = __toESM(require("atom.io/realtime-react"));
|
|
62
|
-
var RR = __toESM(require("fp-ts/ReadonlyRecord"));
|
|
63
|
-
var Happy = __toESM(require("happy-dom"));
|
|
64
|
-
var SocketIO = __toESM(require("socket.io"));
|
|
65
|
-
var import_socket = require("socket.io-client");
|
|
66
|
-
var import_jsx_dev_runtime = require("react/jsx-dev-runtime");
|
|
67
|
-
var setupRealtimeTestServer = (options) => {
|
|
68
|
-
const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
|
|
69
|
-
const address = httpServer.listen().address();
|
|
70
|
-
const port = typeof address === `string` ? 80 : address === null ? null : address.port;
|
|
71
|
-
if (port === null)
|
|
72
|
-
throw new Error(`Could not determine port for test server`);
|
|
73
|
-
const server = new SocketIO.Server(httpServer);
|
|
74
|
-
const silo2 = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
75
|
-
server.on(`connection`, (socket) => {
|
|
76
|
-
options.server({ socket, silo: silo2 });
|
|
77
|
-
});
|
|
78
|
-
const dispose = () => {
|
|
79
|
-
server.close();
|
|
80
|
-
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
81
|
-
};
|
|
82
|
-
return {
|
|
83
|
-
name: `SERVER`,
|
|
84
|
-
silo: silo2,
|
|
85
|
-
dispose,
|
|
86
|
-
port
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
var setupRealtimeTestClient = (options, name, port) => {
|
|
90
|
-
const socket = (0, import_socket.io)(`http://localhost:${port}/`);
|
|
91
|
-
const silo2 = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
92
|
-
const { document } = new Happy.Window();
|
|
93
|
-
document.body.innerHTML = `<div id="app"></div>`;
|
|
94
|
-
const renderResult = (0, import_react.render)(
|
|
95
|
-
/* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(AR.StoreProvider, { store: silo2.store, children: /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(RTC.RealtimeProvider, { socket, children: /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(options.client, {}, void 0, false, {
|
|
96
|
-
fileName: "../src/realtime-testing/setup-realtime-test.tsx",
|
|
97
|
-
lineNumber: 94,
|
|
98
|
-
columnNumber: 5
|
|
99
|
-
}, this) }, void 0, false, {
|
|
100
|
-
fileName: "../src/realtime-testing/setup-realtime-test.tsx",
|
|
101
|
-
lineNumber: 93,
|
|
102
|
-
columnNumber: 4
|
|
103
|
-
}, this) }, void 0, false, {
|
|
104
|
-
fileName: "../src/realtime-testing/setup-realtime-test.tsx",
|
|
105
|
-
lineNumber: 92,
|
|
106
|
-
columnNumber: 3
|
|
107
|
-
}, this),
|
|
108
|
-
{
|
|
109
|
-
container: document.querySelector(`#app`)
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
const prettyPrint = () => console.log((0, import_react.prettyDOM)(renderResult.container));
|
|
113
|
-
const disconnect = () => socket.disconnect();
|
|
114
|
-
const reconnect = () => socket.connect();
|
|
115
|
-
const dispose = () => {
|
|
116
|
-
socket.disconnect();
|
|
117
|
-
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
118
|
-
};
|
|
119
|
-
return {
|
|
120
|
-
name,
|
|
121
|
-
silo: silo2,
|
|
122
|
-
renderResult,
|
|
123
|
-
prettyPrint,
|
|
124
|
-
disconnect,
|
|
125
|
-
reconnect,
|
|
126
|
-
dispose
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
var singleClient = (options) => {
|
|
130
|
-
const server = setupRealtimeTestServer(options);
|
|
131
|
-
const client = setupRealtimeTestClient(options, `CLIENT`, server.port);
|
|
132
|
-
return {
|
|
133
|
-
client,
|
|
134
|
-
server,
|
|
135
|
-
teardown: () => {
|
|
136
|
-
client.dispose();
|
|
137
|
-
server.dispose();
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
var multiClient = (options) => {
|
|
142
|
-
const server = setupRealtimeTestServer(options);
|
|
143
|
-
const clients = RR.toEntries(options.clients).reduce(
|
|
144
|
-
(clients2, [name, client]) => __spreadProps(__spreadValues({}, clients2), {
|
|
145
|
-
[name]: setupRealtimeTestClient(__spreadProps(__spreadValues({}, options), { client }), name, server.port)
|
|
146
|
-
}),
|
|
147
|
-
{}
|
|
148
|
-
);
|
|
149
|
-
return {
|
|
150
|
-
clients,
|
|
151
|
-
server,
|
|
152
|
-
teardown: () => {
|
|
153
|
-
RR.toEntries(clients).forEach(([, client]) => client.dispose());
|
|
154
|
-
server.dispose();
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
-
0 && (module.exports = {
|
|
160
|
-
multiClient,
|
|
161
|
-
setupRealtimeTestClient,
|
|
162
|
-
setupRealtimeTestServer,
|
|
163
|
-
singleClient
|
|
164
|
-
});
|
|
165
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/realtime-testing/index.ts","../../src/realtime-testing/setup-realtime-test.tsx"],"sourcesContent":["export * from \"./setup-realtime-test\"\n","import * as http from \"http\"\n\nimport { prettyDOM, render, type RenderResult } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport * as AR from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-react\"\nimport * as RR from \"fp-ts/ReadonlyRecord\"\nimport * as Happy from \"happy-dom\"\nimport * as React from \"react\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nexport type TestSetupOptions = {\n\tserver: (tools: { socket: SocketIO.Socket; silo: AtomIO.Silo }) => void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n\tdispose: () => void\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\treconnect: () => void\n\tdisconnect: () => void\n}\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => void\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClient\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClient>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen().address()\n\tconst port =\n\t\ttypeof address === `string` ? 80 : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\tconst server = new SocketIO.Server(httpServer)\n\tconst silo = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\toptions.server({ socket, silo })\n\t})\n\n\tconst dispose = () => {\n\t\tserver.close()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClient => {\n\tconst socket: ClientSocket = io(`http://localhost:${port}/`)\n\tconst silo = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tconst { document } = new Happy.Window()\n\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\tconst renderResult = render(\n\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t<RTC.RealtimeProvider socket={socket}>\n\t\t\t\t<options.client />\n\t\t\t</RTC.RealtimeProvider>\n\t\t</AR.StoreProvider>,\n\t\t{\n\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t},\n\t)\n\n\tconst prettyPrint = () => console.log(prettyDOM(renderResult.container))\n\n\tconst disconnect = () => socket.disconnect()\n\tconst reconnect = () => socket.connect()\n\n\tconst dispose = () => {\n\t\tsocket.disconnect()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname,\n\t\tsilo,\n\t\trenderResult,\n\t\tprettyPrint,\n\t\tdisconnect,\n\t\treconnect,\n\t\tdispose,\n\t}\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tclient.dispose()\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = RR.toEntries(options.clients).reduce(\n\t\t(clients, [name, client]) => ({\n\t\t\t...clients,\n\t\t\t[name]: setupRealtimeTestClient({ ...options, client }, name, server.port),\n\t\t}),\n\t\t{} as Record<ClientNames, RealtimeTestClient>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tRR.toEntries(clients).forEach(([, client]) => client.dispose())\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n"],"mappings":"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","names":["silo","clients"]}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
|
-
// ../src/realtime-testing/setup-realtime-test.tsx
|
|
22
|
-
import * as http from "http";
|
|
23
|
-
import { prettyDOM, render } from "@testing-library/react";
|
|
24
|
-
import * as AtomIO from "atom.io";
|
|
25
|
-
import * as AR from "atom.io/react";
|
|
26
|
-
import * as RTC from "atom.io/realtime-react";
|
|
27
|
-
import * as RR from "fp-ts/ReadonlyRecord";
|
|
28
|
-
import * as Happy from "happy-dom";
|
|
29
|
-
import * as SocketIO from "socket.io";
|
|
30
|
-
import { io } from "socket.io-client";
|
|
31
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
32
|
-
var setupRealtimeTestServer = (options) => {
|
|
33
|
-
const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
|
|
34
|
-
const address = httpServer.listen().address();
|
|
35
|
-
const port = typeof address === `string` ? 80 : address === null ? null : address.port;
|
|
36
|
-
if (port === null)
|
|
37
|
-
throw new Error(`Could not determine port for test server`);
|
|
38
|
-
const server = new SocketIO.Server(httpServer);
|
|
39
|
-
const silo2 = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
40
|
-
server.on(`connection`, (socket) => {
|
|
41
|
-
options.server({ socket, silo: silo2 });
|
|
42
|
-
});
|
|
43
|
-
const dispose = () => {
|
|
44
|
-
server.close();
|
|
45
|
-
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
46
|
-
};
|
|
47
|
-
return {
|
|
48
|
-
name: `SERVER`,
|
|
49
|
-
silo: silo2,
|
|
50
|
-
dispose,
|
|
51
|
-
port
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
var setupRealtimeTestClient = (options, name, port) => {
|
|
55
|
-
const socket = io(`http://localhost:${port}/`);
|
|
56
|
-
const silo2 = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
57
|
-
const { document } = new Happy.Window();
|
|
58
|
-
document.body.innerHTML = `<div id="app"></div>`;
|
|
59
|
-
const renderResult = render(
|
|
60
|
-
/* @__PURE__ */ jsxDEV(AR.StoreProvider, { store: silo2.store, children: /* @__PURE__ */ jsxDEV(RTC.RealtimeProvider, { socket, children: /* @__PURE__ */ jsxDEV(options.client, {}, void 0, false, {
|
|
61
|
-
fileName: "../src/realtime-testing/setup-realtime-test.tsx",
|
|
62
|
-
lineNumber: 94,
|
|
63
|
-
columnNumber: 5
|
|
64
|
-
}, this) }, void 0, false, {
|
|
65
|
-
fileName: "../src/realtime-testing/setup-realtime-test.tsx",
|
|
66
|
-
lineNumber: 93,
|
|
67
|
-
columnNumber: 4
|
|
68
|
-
}, this) }, void 0, false, {
|
|
69
|
-
fileName: "../src/realtime-testing/setup-realtime-test.tsx",
|
|
70
|
-
lineNumber: 92,
|
|
71
|
-
columnNumber: 3
|
|
72
|
-
}, this),
|
|
73
|
-
{
|
|
74
|
-
container: document.querySelector(`#app`)
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
const prettyPrint = () => console.log(prettyDOM(renderResult.container));
|
|
78
|
-
const disconnect = () => socket.disconnect();
|
|
79
|
-
const reconnect = () => socket.connect();
|
|
80
|
-
const dispose = () => {
|
|
81
|
-
socket.disconnect();
|
|
82
|
-
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
name,
|
|
86
|
-
silo: silo2,
|
|
87
|
-
renderResult,
|
|
88
|
-
prettyPrint,
|
|
89
|
-
disconnect,
|
|
90
|
-
reconnect,
|
|
91
|
-
dispose
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
var singleClient = (options) => {
|
|
95
|
-
const server = setupRealtimeTestServer(options);
|
|
96
|
-
const client = setupRealtimeTestClient(options, `CLIENT`, server.port);
|
|
97
|
-
return {
|
|
98
|
-
client,
|
|
99
|
-
server,
|
|
100
|
-
teardown: () => {
|
|
101
|
-
client.dispose();
|
|
102
|
-
server.dispose();
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
var multiClient = (options) => {
|
|
107
|
-
const server = setupRealtimeTestServer(options);
|
|
108
|
-
const clients = RR.toEntries(options.clients).reduce(
|
|
109
|
-
(clients2, [name, client]) => __spreadProps(__spreadValues({}, clients2), {
|
|
110
|
-
[name]: setupRealtimeTestClient(__spreadProps(__spreadValues({}, options), { client }), name, server.port)
|
|
111
|
-
}),
|
|
112
|
-
{}
|
|
113
|
-
);
|
|
114
|
-
return {
|
|
115
|
-
clients,
|
|
116
|
-
server,
|
|
117
|
-
teardown: () => {
|
|
118
|
-
RR.toEntries(clients).forEach(([, client]) => client.dispose());
|
|
119
|
-
server.dispose();
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
export {
|
|
124
|
-
multiClient,
|
|
125
|
-
setupRealtimeTestClient,
|
|
126
|
-
setupRealtimeTestServer,
|
|
127
|
-
singleClient
|
|
128
|
-
};
|
|
129
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/realtime-testing/setup-realtime-test.tsx"],"sourcesContent":["import * as http from \"http\"\n\nimport { prettyDOM, render, type RenderResult } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport * as AR from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-react\"\nimport * as RR from \"fp-ts/ReadonlyRecord\"\nimport * as Happy from \"happy-dom\"\nimport * as React from \"react\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nexport type TestSetupOptions = {\n\tserver: (tools: { socket: SocketIO.Socket; silo: AtomIO.Silo }) => void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n\tdispose: () => void\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\treconnect: () => void\n\tdisconnect: () => void\n}\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => void\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClient\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClient>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen().address()\n\tconst port =\n\t\ttypeof address === `string` ? 80 : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\tconst server = new SocketIO.Server(httpServer)\n\tconst silo = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\toptions.server({ socket, silo })\n\t})\n\n\tconst dispose = () => {\n\t\tserver.close()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClient => {\n\tconst socket: ClientSocket = io(`http://localhost:${port}/`)\n\tconst silo = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tconst { document } = new Happy.Window()\n\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\tconst renderResult = render(\n\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t<RTC.RealtimeProvider socket={socket}>\n\t\t\t\t<options.client />\n\t\t\t</RTC.RealtimeProvider>\n\t\t</AR.StoreProvider>,\n\t\t{\n\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t},\n\t)\n\n\tconst prettyPrint = () => console.log(prettyDOM(renderResult.container))\n\n\tconst disconnect = () => socket.disconnect()\n\tconst reconnect = () => socket.connect()\n\n\tconst dispose = () => {\n\t\tsocket.disconnect()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname,\n\t\tsilo,\n\t\trenderResult,\n\t\tprettyPrint,\n\t\tdisconnect,\n\t\treconnect,\n\t\tdispose,\n\t}\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tclient.dispose()\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = RR.toEntries(options.clients).reduce(\n\t\t(clients, [name, client]) => ({\n\t\t\t...clients,\n\t\t\t[name]: setupRealtimeTestClient({ ...options, client }, name, server.port),\n\t\t}),\n\t\t{} as Record<ClientNames, RealtimeTestClient>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tRR.toEntries(clients).forEach(([, client]) => client.dispose())\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n"],"mappings":"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","names":["silo","clients"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AtomTokenIndex, SelectorTokenIndex } from "./meta-state"
|
|
2
|
-
import { attachMetaAtoms, attachMetaSelectors } from "./meta-state"
|
|
3
|
-
import type { ReadonlySelectorToken } from "../.."
|
|
4
|
-
import type { Store } from "../store"
|
|
5
|
-
import { IMPLICIT } from "../store"
|
|
6
|
-
|
|
7
|
-
export const attachMetaState = (
|
|
8
|
-
store: Store = IMPLICIT.STORE,
|
|
9
|
-
): {
|
|
10
|
-
atomTokenIndexState: ReadonlySelectorToken<AtomTokenIndex>
|
|
11
|
-
selectorTokenIndexState: ReadonlySelectorToken<SelectorTokenIndex>
|
|
12
|
-
} => {
|
|
13
|
-
return {
|
|
14
|
-
atomTokenIndexState: attachMetaAtoms(store),
|
|
15
|
-
selectorTokenIndexState: attachMetaSelectors(store),
|
|
16
|
-
}
|
|
17
|
-
}
|