atom.io 0.6.1 → 0.6.2
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/timeline.ts +1 -1
- package/json/dist/index.d.mts +0 -18
- package/json/dist/index.d.ts +0 -18
- package/json/dist/index.js +0 -51
- package/json/dist/index.js.map +0 -1
- package/json/dist/index.mjs +0 -15
- package/json/dist/index.mjs.map +0 -1
- package/react/dist/index.d.mts +0 -24
- package/react/dist/index.d.ts +0 -24
- package/react/dist/index.js +0 -83
- package/react/dist/index.js.map +0 -1
- package/react/dist/index.mjs +0 -41
- package/react/dist/index.mjs.map +0 -1
- package/react-devtools/dist/index.css +0 -26
- package/react-devtools/dist/index.css.map +0 -1
- package/react-devtools/dist/index.d.mts +0 -15
- package/react-devtools/dist/index.d.ts +0 -15
- package/react-devtools/dist/index.js +0 -1582
- package/react-devtools/dist/index.js.map +0 -1
- package/react-devtools/dist/index.mjs +0 -1554
- package/react-devtools/dist/index.mjs.map +0 -1
- package/realtime/dist/index.d.mts +0 -27
- package/realtime/dist/index.d.ts +0 -27
- package/realtime/dist/index.js +0 -191
- package/realtime/dist/index.js.map +0 -1
- package/realtime/dist/index.mjs +0 -152
- package/realtime/dist/index.mjs.map +0 -1
- package/realtime-react/dist/index.d.mts +0 -45
- package/realtime-react/dist/index.d.ts +0 -45
- package/realtime-react/dist/index.js +0 -213
- package/realtime-react/dist/index.js.map +0 -1
- package/realtime-react/dist/index.mjs +0 -168
- package/realtime-react/dist/index.mjs.map +0 -1
package/realtime/dist/index.mjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// ../src/realtime/hook-composition/expose-single.ts
|
|
2
|
-
import * as AtomIO from "atom.io";
|
|
3
|
-
var useExposeSingle = ({ socket, store }) => {
|
|
4
|
-
return function exposeSingle(token) {
|
|
5
|
-
let unsubscribeFromStateUpdates = null;
|
|
6
|
-
const fillUnsubRequest = () => {
|
|
7
|
-
socket.off(`unsub:${token.key}`, fillUnsubRequest);
|
|
8
|
-
unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
|
|
9
|
-
unsubscribeFromStateUpdates = null;
|
|
10
|
-
};
|
|
11
|
-
const fillSubRequest = () => {
|
|
12
|
-
socket.emit(`serve:${token.key}`, AtomIO.getState(token, store));
|
|
13
|
-
unsubscribeFromStateUpdates = AtomIO.subscribe(
|
|
14
|
-
token,
|
|
15
|
-
({ newValue }) => {
|
|
16
|
-
socket.emit(`serve:${token.key}`, newValue);
|
|
17
|
-
},
|
|
18
|
-
store
|
|
19
|
-
);
|
|
20
|
-
socket.on(`unsub:${token.key}`, fillUnsubRequest);
|
|
21
|
-
};
|
|
22
|
-
socket.on(`sub:${token.key}`, fillSubRequest);
|
|
23
|
-
return () => {
|
|
24
|
-
socket.off(`sub:${token.key}`, fillSubRequest);
|
|
25
|
-
unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// ../../anvl/src/json/index.ts
|
|
31
|
-
import { pipe } from "fp-ts/function";
|
|
32
|
-
var parseJson = (str) => JSON.parse(str);
|
|
33
|
-
|
|
34
|
-
// ../src/realtime/hook-composition/expose-family.ts
|
|
35
|
-
import * as AtomIO2 from "atom.io";
|
|
36
|
-
var subscribeToTokenCreation = (family, handleTokenCreation) => {
|
|
37
|
-
const subscription = family.type === `atom_family` ? family.subject.subscribe(handleTokenCreation) : family.subject.subscribe(handleTokenCreation);
|
|
38
|
-
return () => subscription.unsubscribe();
|
|
39
|
-
};
|
|
40
|
-
var useExposeFamily = ({ socket, store }) => {
|
|
41
|
-
return function exposeFamily(family, index) {
|
|
42
|
-
const unsubSingleCallbacksByKey = /* @__PURE__ */ new Map();
|
|
43
|
-
const unsubFamilyCallbacksByKey = /* @__PURE__ */ new Map();
|
|
44
|
-
const fillFamilyUnsubRequest = () => {
|
|
45
|
-
unsubFamilyCallbacksByKey.forEach((unsub) => unsub());
|
|
46
|
-
unsubFamilyCallbacksByKey.clear();
|
|
47
|
-
socket.off(`unsub:${family.key}`, fillFamilyUnsubRequest);
|
|
48
|
-
};
|
|
49
|
-
const fillSingleUnsubRequest = (key) => {
|
|
50
|
-
socket.off(`unsub:${key}`, fillSingleUnsubRequest);
|
|
51
|
-
const unsub = unsubSingleCallbacksByKey.get(key);
|
|
52
|
-
if (unsub) {
|
|
53
|
-
unsub();
|
|
54
|
-
unsubSingleCallbacksByKey.delete(key);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const fillSubRequest = (subKey) => {
|
|
58
|
-
if (subKey === void 0) {
|
|
59
|
-
const keys = AtomIO2.getState(index, store);
|
|
60
|
-
keys.forEach((key) => {
|
|
61
|
-
var _a;
|
|
62
|
-
const token = family(key);
|
|
63
|
-
socket.emit(
|
|
64
|
-
`serve:${family.key}`,
|
|
65
|
-
parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
|
|
66
|
-
AtomIO2.getState(token, store)
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
const unsubscribeFromTokenCreation = subscribeToTokenCreation(
|
|
70
|
-
family,
|
|
71
|
-
(token) => {
|
|
72
|
-
const unsub = AtomIO2.subscribe(
|
|
73
|
-
token,
|
|
74
|
-
({ newValue }) => {
|
|
75
|
-
var _a;
|
|
76
|
-
socket.emit(
|
|
77
|
-
`serve:${family.key}`,
|
|
78
|
-
parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
|
|
79
|
-
newValue
|
|
80
|
-
);
|
|
81
|
-
},
|
|
82
|
-
store
|
|
83
|
-
);
|
|
84
|
-
unsubFamilyCallbacksByKey.set(token.key, unsub);
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
unsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation);
|
|
88
|
-
socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest);
|
|
89
|
-
} else {
|
|
90
|
-
const token = family(subKey);
|
|
91
|
-
socket.emit(`serve:${token.key}`, AtomIO2.getState(token, store));
|
|
92
|
-
const unsubscribe = AtomIO2.subscribe(
|
|
93
|
-
token,
|
|
94
|
-
({ newValue }) => {
|
|
95
|
-
socket.emit(`serve:${token.key}`, newValue);
|
|
96
|
-
},
|
|
97
|
-
store
|
|
98
|
-
);
|
|
99
|
-
unsubSingleCallbacksByKey.set(token.key, unsubscribe);
|
|
100
|
-
socket.on(`unsub:${token.key}`, () => {
|
|
101
|
-
fillSingleUnsubRequest(token.key);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
socket.on(`sub:${family.key}`, fillSubRequest);
|
|
106
|
-
return () => {
|
|
107
|
-
socket.off(`sub:${family.key}`, fillSubRequest);
|
|
108
|
-
unsubFamilyCallbacksByKey.forEach((unsub) => unsub());
|
|
109
|
-
unsubSingleCallbacksByKey.forEach((unsub) => unsub());
|
|
110
|
-
unsubFamilyCallbacksByKey.clear();
|
|
111
|
-
unsubSingleCallbacksByKey.clear();
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// ../src/realtime/hook-composition/receive-transaction.ts
|
|
117
|
-
import * as AtomIO3 from "atom.io";
|
|
118
|
-
var useReceiveTransaction = ({ socket, store }) => {
|
|
119
|
-
return function receiveTransaction(tx) {
|
|
120
|
-
const fillTransactionRequest = (update) => AtomIO3.runTransaction(tx, store)(...update.params);
|
|
121
|
-
socket.on(`tx:${tx.key}`, fillTransactionRequest);
|
|
122
|
-
return () => socket.off(`tx:${tx.key}`, fillTransactionRequest);
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// ../src/realtime/hook-composition/receive-state.ts
|
|
127
|
-
import * as AtomIO4 from "atom.io";
|
|
128
|
-
var useReceiveState = ({ socket, store }) => {
|
|
129
|
-
return function receiveState(token) {
|
|
130
|
-
const publish = (newValue) => AtomIO4.setState(token, newValue, store);
|
|
131
|
-
const fillPubUnclaim = () => {
|
|
132
|
-
socket.off(`pub:${token.key}`, publish);
|
|
133
|
-
socket.off(`unclaim:${token.key}`, fillPubUnclaim);
|
|
134
|
-
};
|
|
135
|
-
const fillPubClaim = () => {
|
|
136
|
-
socket.on(`pub:${token.key}`, publish);
|
|
137
|
-
socket.on(`unclaim:${token.key}`, fillPubUnclaim);
|
|
138
|
-
};
|
|
139
|
-
socket.on(`claim:${token.key}`, fillPubClaim);
|
|
140
|
-
return () => {
|
|
141
|
-
socket.off(`claim:${token.key}`, fillPubClaim);
|
|
142
|
-
socket.off(`pub:${token.key}`, publish);
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
export {
|
|
147
|
-
useExposeFamily,
|
|
148
|
-
useExposeSingle,
|
|
149
|
-
useReceiveState,
|
|
150
|
-
useReceiveTransaction
|
|
151
|
-
};
|
|
152
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/realtime/hook-composition/expose-single.ts","../../../anvl/src/json/index.ts","../../src/realtime/hook-composition/expose-family.ts","../../src/realtime/hook-composition/receive-transaction.ts","../../src/realtime/hook-composition/receive-state.ts"],"sourcesContent":["import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeSingle = ({ socket, store }: ServerConfig) => {\n return function exposeSingle<J extends Json>(\n token: AtomIO.StateToken<J>\n ): () => void {\n let unsubscribeFromStateUpdates: (() => void) | null = null\n\n const fillUnsubRequest = () => {\n socket.off(`unsub:${token.key}`, fillUnsubRequest)\n unsubscribeFromStateUpdates?.()\n unsubscribeFromStateUpdates = null\n }\n\n const fillSubRequest = () => {\n socket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n unsubscribeFromStateUpdates = AtomIO.subscribe(\n token,\n ({ newValue }) => {\n socket.emit(`serve:${token.key}`, newValue)\n },\n store\n )\n socket.on(`unsub:${token.key}`, fillUnsubRequest)\n }\n\n socket.on(`sub:${token.key}`, fillSubRequest)\n\n return () => {\n socket.off(`sub:${token.key}`, fillSubRequest)\n unsubscribeFromStateUpdates?.()\n }\n }\n}\n","import { pipe } from \"fp-ts/function\"\n\nexport * from \"./refine\"\nexport * from \"./json-interface\"\n\nexport const serializeSet = <T>(set: Set<T>): string =>\n pipe(set, Array.from, JSON.stringify)\n\nexport const deserializeSet = <T>(str: string): Set<T> =>\n pipe(str, JSON.parse, Array.from, (a) => new Set(a as T[]))\n\nexport type Primitive = boolean | number | string | null\n\nexport type Serializable =\n | Primitive\n | Readonly<{ [key: string]: Serializable }>\n | ReadonlyArray<Serializable>\n\nexport type JsonObj<\n Key extends string = string,\n Value extends Serializable = Serializable\n> = Record<Key, Value>\n\nexport type JsonArr<Element extends Serializable = Serializable> =\n ReadonlyArray<Element>\n\nexport type Json = JsonArr | JsonObj | Primitive\n\nexport const parseJson = <J extends Json, S extends Stringified<J> | string>(\n str: S | string\n): S extends Stringified<J> ? J : Json => JSON.parse(str)\n\nexport type Stringified<J extends Json> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json>(json: J): Stringified<J> =>\n JSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n `array`,\n `boolean`,\n `null`,\n `number`,\n `object`,\n `string`,\n] as const\n\nexport type JsonTypeName = (typeof JSON_TYPE_NAMES)[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json> {\n array: JsonArr\n boolean: boolean\n null: null\n number: number\n object: JsonObj\n string: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n array: [],\n boolean: false,\n null: null,\n number: 0,\n object: {},\n string: ``,\n}\n","import type { Json } from \"anvl/json\"\nimport { parseJson } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\nconst subscribeToTokenCreation = <T>(\n family: AtomIO.AtomFamily<T> | AtomIO.SelectorFamily<T>,\n handleTokenCreation: (token: AtomIO.StateToken<T>) => void\n): (() => void) => {\n const subscription =\n family.type === `atom_family`\n ? family.subject.subscribe(handleTokenCreation)\n : family.subject.subscribe(handleTokenCreation)\n return () => subscription.unsubscribe()\n}\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeFamily = ({ socket, store }: ServerConfig) => {\n return function exposeFamily<J extends Json>(\n family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n index: AtomIO.StateToken<Set<string>>\n ): () => void {\n const unsubSingleCallbacksByKey = new Map<string, () => void>()\n const unsubFamilyCallbacksByKey = new Map<string, () => void>()\n\n const fillFamilyUnsubRequest = () => {\n unsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n unsubFamilyCallbacksByKey.clear()\n socket.off(`unsub:${family.key}`, fillFamilyUnsubRequest)\n }\n\n const fillSingleUnsubRequest = (key: string) => {\n socket.off(`unsub:${key}`, fillSingleUnsubRequest)\n const unsub = unsubSingleCallbacksByKey.get(key)\n if (unsub) {\n unsub()\n unsubSingleCallbacksByKey.delete(key)\n }\n }\n\n const fillSubRequest = (subKey?: AtomIO.Serializable) => {\n if (subKey === undefined) {\n const keys = AtomIO.getState(index, store)\n keys.forEach((key) => {\n const token = family(key)\n socket.emit(\n `serve:${family.key}`,\n parseJson(token.family?.subKey || `null`),\n AtomIO.getState(token, store)\n )\n })\n\n const unsubscribeFromTokenCreation = subscribeToTokenCreation(\n family,\n (token) => {\n const unsub = AtomIO.subscribe(\n token,\n ({ newValue }) => {\n socket.emit(\n `serve:${family.key}`,\n parseJson(token.family?.subKey || `null`),\n newValue\n )\n },\n store\n )\n unsubFamilyCallbacksByKey.set(token.key, unsub)\n }\n )\n unsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation)\n\n socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest)\n } else {\n const token = family(subKey)\n socket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n const unsubscribe = AtomIO.subscribe(\n token,\n ({ newValue }) => {\n socket.emit(`serve:${token.key}`, newValue)\n },\n store\n )\n unsubSingleCallbacksByKey.set(token.key, unsubscribe)\n socket.on(`unsub:${token.key}`, () => {\n fillSingleUnsubRequest(token.key)\n })\n }\n }\n\n socket.on(`sub:${family.key}`, fillSubRequest)\n\n return () => {\n socket.off(`sub:${family.key}`, fillSubRequest)\n unsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n unsubSingleCallbacksByKey.forEach((unsub) => unsub())\n unsubFamilyCallbacksByKey.clear()\n unsubSingleCallbacksByKey.clear()\n }\n }\n}\n","import * as AtomIO from \"atom.io\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\n\nimport type { ServerConfig } from \".\"\n\nexport const useReceiveTransaction = ({ socket, store }: ServerConfig) => {\n return function receiveTransaction<ƒ extends ƒn>(\n tx: AtomIO.TransactionToken<ƒ>\n ): () => void {\n const fillTransactionRequest = (update: AtomIO.TransactionUpdate<ƒ>) =>\n AtomIO.runTransaction<ƒ>(tx, store)(...update.params)\n\n socket.on(`tx:${tx.key}`, fillTransactionRequest)\n\n return () => socket.off(`tx:${tx.key}`, fillTransactionRequest)\n }\n}\n","import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useReceiveState = ({ socket, store }: ServerConfig) => {\n return function receiveState<J extends Json>(\n token: AtomIO.StateToken<J>\n ): () => void {\n const publish = (newValue: J) => AtomIO.setState(token, newValue, store)\n\n const fillPubUnclaim = () => {\n socket.off(`pub:${token.key}`, publish)\n socket.off(`unclaim:${token.key}`, fillPubUnclaim)\n }\n const fillPubClaim = () => {\n socket.on(`pub:${token.key}`, publish)\n socket.on(`unclaim:${token.key}`, fillPubUnclaim)\n }\n\n socket.on(`claim:${token.key}`, fillPubClaim)\n\n return () => {\n socket.off(`claim:${token.key}`, fillPubClaim)\n socket.off(`pub:${token.key}`, publish)\n }\n }\n}\n"],"mappings":";AACA,YAAY,YAAY;AAKjB,IAAM,kBAAkB,CAAC,EAAE,QAAQ,MAAM,MAAoB;AAClE,SAAO,SAAS,aACd,OACY;AACZ,QAAI,8BAAmD;AAEvD,UAAM,mBAAmB,MAAM;AAC7B,aAAO,IAAI,SAAS,MAAM,GAAG,IAAI,gBAAgB;AACjD;AACA,oCAA8B;AAAA,IAChC;AAEA,UAAM,iBAAiB,MAAM;AAC3B,aAAO,KAAK,SAAS,MAAM,GAAG,IAAW,gBAAS,OAAO,KAAK,CAAC;AAC/D,oCAAqC;AAAA,QACnC;AAAA,QACA,CAAC,EAAE,SAAS,MAAM;AAChB,iBAAO,KAAK,SAAS,MAAM,GAAG,IAAI,QAAQ;AAAA,QAC5C;AAAA,QACA;AAAA,MACF;AACA,aAAO,GAAG,SAAS,MAAM,GAAG,IAAI,gBAAgB;AAAA,IAClD;AAEA,WAAO,GAAG,OAAO,MAAM,GAAG,IAAI,cAAc;AAE5C,WAAO,MAAM;AACX,aAAO,IAAI,OAAO,MAAM,GAAG,IAAI,cAAc;AAC7C;AAAA,IACF;AAAA,EACF;AACF;;;ACrCA,SAAS,YAAY;AA4Bd,IAAM,YAAY,CACvB,QACwC,KAAK,MAAM,GAAG;;;AC5BxD,YAAYA,aAAY;AAIxB,IAAM,2BAA2B,CAC/B,QACA,wBACiB;AACjB,QAAM,eACJ,OAAO,SAAS,gBACZ,OAAO,QAAQ,UAAU,mBAAmB,IAC5C,OAAO,QAAQ,UAAU,mBAAmB;AAClD,SAAO,MAAM,aAAa,YAAY;AACxC;AAGO,IAAM,kBAAkB,CAAC,EAAE,QAAQ,MAAM,MAAoB;AAClE,SAAO,SAAS,aACd,QACA,OACY;AACZ,UAAM,4BAA4B,oBAAI,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ACA,UAAM,eAAe,MAAM;AACzB,aAAO,GAAG,OAAO,MAAM,GAAG,IAAI,OAAO;AACrC,aAAO,GAAG,WAAW,MAAM,GAAG,IAAI,cAAc;AAAA,IAClD;AAEA,WAAO,GAAG,SAAS,MAAM,GAAG,IAAI,YAAY;AAE5C,WAAO,MAAM;AACX,aAAO,IAAI,SAAS,MAAM,GAAG,IAAI,YAAY;AAC7C,aAAO,IAAI,OAAO,MAAM,GAAG,IAAI,OAAO;AAAA,IACxC;AAAA,EACF;AACF;","names":["AtomIO","AtomIO","AtomIO"]}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import * as AtomIO from 'atom.io';
|
|
4
|
-
|
|
5
|
-
declare const RealtimeContext: React.Context<{
|
|
6
|
-
socket: Socket;
|
|
7
|
-
}>;
|
|
8
|
-
declare const RealtimeProvider: React.FC<{
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
socket: Socket;
|
|
11
|
-
}>;
|
|
12
|
-
|
|
13
|
-
type ƒn = (...parameters: any[]) => any;
|
|
14
|
-
|
|
15
|
-
type Primitive = boolean | number | string | null;
|
|
16
|
-
type Serializable = Primitive | Readonly<{
|
|
17
|
-
[key: string]: Serializable;
|
|
18
|
-
}> | ReadonlyArray<Serializable>;
|
|
19
|
-
type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
20
|
-
type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
21
|
-
type Json = JsonArr | JsonObj | Primitive;
|
|
22
|
-
|
|
23
|
-
declare function usePull<J extends Json>(token: AtomIO.StateToken<J>): void;
|
|
24
|
-
|
|
25
|
-
declare function usePullFamily<J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>): void;
|
|
26
|
-
|
|
27
|
-
declare function usePullFamilyMember<J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: AtomIO.Serializable): void;
|
|
28
|
-
|
|
29
|
-
declare function usePush<J extends Json>(token: AtomIO.StateToken<J>): void;
|
|
30
|
-
|
|
31
|
-
declare function useServerAction<ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
32
|
-
|
|
33
|
-
type RealtimeHooks = {
|
|
34
|
-
usePull: <J extends Json>(token: AtomIO.StateToken<J>) => void;
|
|
35
|
-
usePullFamily: <J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>) => void;
|
|
36
|
-
usePullFamilyMember: <J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: string) => void;
|
|
37
|
-
usePush: <J extends Json>(token: AtomIO.StateToken<J>) => void;
|
|
38
|
-
useServerAction: <ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
39
|
-
};
|
|
40
|
-
declare const realtimeHooks: RealtimeHooks;
|
|
41
|
-
|
|
42
|
-
declare const myIdState__INTERNAL: AtomIO.AtomToken<string | null>;
|
|
43
|
-
declare const myIdState: AtomIO.ReadonlySelectorToken<string | null>;
|
|
44
|
-
|
|
45
|
-
export { RealtimeContext, RealtimeHooks, RealtimeProvider, myIdState, myIdState__INTERNAL, realtimeHooks, usePull, usePullFamily, usePullFamilyMember, usePush, useServerAction };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import * as AtomIO from 'atom.io';
|
|
4
|
-
|
|
5
|
-
declare const RealtimeContext: React.Context<{
|
|
6
|
-
socket: Socket;
|
|
7
|
-
}>;
|
|
8
|
-
declare const RealtimeProvider: React.FC<{
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
socket: Socket;
|
|
11
|
-
}>;
|
|
12
|
-
|
|
13
|
-
type ƒn = (...parameters: any[]) => any;
|
|
14
|
-
|
|
15
|
-
type Primitive = boolean | number | string | null;
|
|
16
|
-
type Serializable = Primitive | Readonly<{
|
|
17
|
-
[key: string]: Serializable;
|
|
18
|
-
}> | ReadonlyArray<Serializable>;
|
|
19
|
-
type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
20
|
-
type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
21
|
-
type Json = JsonArr | JsonObj | Primitive;
|
|
22
|
-
|
|
23
|
-
declare function usePull<J extends Json>(token: AtomIO.StateToken<J>): void;
|
|
24
|
-
|
|
25
|
-
declare function usePullFamily<J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>): void;
|
|
26
|
-
|
|
27
|
-
declare function usePullFamilyMember<J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: AtomIO.Serializable): void;
|
|
28
|
-
|
|
29
|
-
declare function usePush<J extends Json>(token: AtomIO.StateToken<J>): void;
|
|
30
|
-
|
|
31
|
-
declare function useServerAction<ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
32
|
-
|
|
33
|
-
type RealtimeHooks = {
|
|
34
|
-
usePull: <J extends Json>(token: AtomIO.StateToken<J>) => void;
|
|
35
|
-
usePullFamily: <J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>) => void;
|
|
36
|
-
usePullFamilyMember: <J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: string) => void;
|
|
37
|
-
usePush: <J extends Json>(token: AtomIO.StateToken<J>) => void;
|
|
38
|
-
useServerAction: <ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
39
|
-
};
|
|
40
|
-
declare const realtimeHooks: RealtimeHooks;
|
|
41
|
-
|
|
42
|
-
declare const myIdState__INTERNAL: AtomIO.AtomToken<string | null>;
|
|
43
|
-
declare const myIdState: AtomIO.ReadonlySelectorToken<string | null>;
|
|
44
|
-
|
|
45
|
-
export { RealtimeContext, RealtimeHooks, RealtimeProvider, myIdState, myIdState__INTERNAL, realtimeHooks, usePull, usePullFamily, usePullFamilyMember, usePush, useServerAction };
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// ../src/realtime-react/index.ts
|
|
30
|
-
var realtime_react_exports = {};
|
|
31
|
-
__export(realtime_react_exports, {
|
|
32
|
-
RealtimeContext: () => RealtimeContext,
|
|
33
|
-
RealtimeProvider: () => RealtimeProvider,
|
|
34
|
-
myIdState: () => myIdState,
|
|
35
|
-
myIdState__INTERNAL: () => myIdState__INTERNAL,
|
|
36
|
-
realtimeHooks: () => realtimeHooks,
|
|
37
|
-
usePull: () => usePull,
|
|
38
|
-
usePullFamily: () => usePullFamily,
|
|
39
|
-
usePullFamilyMember: () => usePullFamilyMember,
|
|
40
|
-
usePush: () => usePush,
|
|
41
|
-
useServerAction: () => useServerAction
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(realtime_react_exports);
|
|
44
|
-
|
|
45
|
-
// ../src/realtime-react/realtime-context.tsx
|
|
46
|
-
var React = __toESM(require("react"));
|
|
47
|
-
var AR = __toESM(require("atom.io/react"));
|
|
48
|
-
var import_socket = require("socket.io-client");
|
|
49
|
-
|
|
50
|
-
// ../src/realtime-react/realtime-state.ts
|
|
51
|
-
var AtomIO = __toESM(require("atom.io"));
|
|
52
|
-
var myIdState__INTERNAL = AtomIO.atom({
|
|
53
|
-
key: `myId__INTERNAL`,
|
|
54
|
-
default: null
|
|
55
|
-
});
|
|
56
|
-
var myIdState = AtomIO.selector({
|
|
57
|
-
key: `myId`,
|
|
58
|
-
get: ({ get }) => get(myIdState__INTERNAL)
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// ../src/realtime-react/realtime-context.tsx
|
|
62
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
63
|
-
var RealtimeContext = React.createContext({
|
|
64
|
-
socket: (0, import_socket.io)()
|
|
65
|
-
});
|
|
66
|
-
var RealtimeProvider = ({ children, socket }) => {
|
|
67
|
-
const setMyId = AR.useI(myIdState__INTERNAL);
|
|
68
|
-
React.useEffect(() => {
|
|
69
|
-
socket.on(`connect`, () => {
|
|
70
|
-
setMyId(socket.id);
|
|
71
|
-
});
|
|
72
|
-
socket.on(`disconnect`, () => {
|
|
73
|
-
setMyId(null);
|
|
74
|
-
});
|
|
75
|
-
}, [socket, setMyId]);
|
|
76
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RealtimeContext.Provider, { value: { socket }, children });
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// ../src/realtime-react/use-pull.ts
|
|
80
|
-
var React3 = __toESM(require("react"));
|
|
81
|
-
var AtomIO3 = __toESM(require("atom.io"));
|
|
82
|
-
|
|
83
|
-
// ../src/react/store-context.tsx
|
|
84
|
-
var React2 = __toESM(require("react"));
|
|
85
|
-
var AtomIO2 = __toESM(require("atom.io"));
|
|
86
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
87
|
-
var StoreContext = React2.createContext(
|
|
88
|
-
AtomIO2.__INTERNAL__.IMPLICIT.STORE
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
// ../src/realtime-react/use-pull.ts
|
|
92
|
-
function usePull(token) {
|
|
93
|
-
const { socket } = React3.useContext(RealtimeContext);
|
|
94
|
-
const store = React3.useContext(StoreContext);
|
|
95
|
-
React3.useEffect(() => {
|
|
96
|
-
socket.on(`serve:${token.key}`, (data) => {
|
|
97
|
-
AtomIO3.setState(token, data, store);
|
|
98
|
-
});
|
|
99
|
-
socket.emit(`sub:${token.key}`);
|
|
100
|
-
return () => {
|
|
101
|
-
socket.off(`serve:${token.key}`);
|
|
102
|
-
socket.emit(`unsub:${token.key}`);
|
|
103
|
-
};
|
|
104
|
-
}, [token.key]);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ../src/realtime-react/use-pull-family.ts
|
|
108
|
-
var React4 = __toESM(require("react"));
|
|
109
|
-
var AtomIO4 = __toESM(require("atom.io"));
|
|
110
|
-
function usePullFamily(family) {
|
|
111
|
-
const { socket } = React4.useContext(RealtimeContext);
|
|
112
|
-
const store = React4.useContext(StoreContext);
|
|
113
|
-
React4.useEffect(() => {
|
|
114
|
-
socket.on(`serve:${family.key}`, (key, data) => {
|
|
115
|
-
AtomIO4.setState(family(key), data, store);
|
|
116
|
-
});
|
|
117
|
-
socket == null ? void 0 : socket.emit(`sub:${family.key}`);
|
|
118
|
-
return () => {
|
|
119
|
-
socket == null ? void 0 : socket.off(`serve:${family.key}`);
|
|
120
|
-
socket == null ? void 0 : socket.emit(`unsub:${family.key}`);
|
|
121
|
-
};
|
|
122
|
-
}, [family.key]);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ../src/realtime-react/use-pull-family-member.ts
|
|
126
|
-
var React5 = __toESM(require("react"));
|
|
127
|
-
var AtomIO5 = __toESM(require("atom.io"));
|
|
128
|
-
function usePullFamilyMember(family, subKey) {
|
|
129
|
-
const token = family(subKey);
|
|
130
|
-
const { socket } = React5.useContext(RealtimeContext);
|
|
131
|
-
const store = React5.useContext(StoreContext);
|
|
132
|
-
React5.useEffect(() => {
|
|
133
|
-
socket == null ? void 0 : socket.on(`serve:${token.key}`, (data) => {
|
|
134
|
-
AtomIO5.setState(family(subKey), data, store);
|
|
135
|
-
});
|
|
136
|
-
socket == null ? void 0 : socket.emit(`sub:${family.key}`, subKey);
|
|
137
|
-
return () => {
|
|
138
|
-
socket == null ? void 0 : socket.off(`serve:${token.key}`);
|
|
139
|
-
socket == null ? void 0 : socket.emit(`unsub:${token.key}`);
|
|
140
|
-
};
|
|
141
|
-
}, [family.key]);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// ../src/realtime-react/use-push.ts
|
|
145
|
-
var React6 = __toESM(require("react"));
|
|
146
|
-
var AtomIO6 = __toESM(require("atom.io"));
|
|
147
|
-
function usePush(token) {
|
|
148
|
-
const { socket } = React6.useContext(RealtimeContext);
|
|
149
|
-
const store = React6.useContext(StoreContext);
|
|
150
|
-
React6.useEffect(() => {
|
|
151
|
-
socket.emit(`claim:${token.key}`);
|
|
152
|
-
AtomIO6.subscribe(
|
|
153
|
-
token,
|
|
154
|
-
({ newValue }) => {
|
|
155
|
-
socket.emit(`pub:${token.key}`, newValue);
|
|
156
|
-
},
|
|
157
|
-
store
|
|
158
|
-
);
|
|
159
|
-
return () => {
|
|
160
|
-
socket.emit(`unclaim:${token.key}`);
|
|
161
|
-
};
|
|
162
|
-
}, [token.key]);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// ../src/realtime-react/use-server-action.ts
|
|
166
|
-
var React7 = __toESM(require("react"));
|
|
167
|
-
var AtomIO7 = __toESM(require("atom.io"));
|
|
168
|
-
var import_react5 = require("atom.io/react");
|
|
169
|
-
var TX_SUBS = /* @__PURE__ */ new Map();
|
|
170
|
-
function useServerAction(token) {
|
|
171
|
-
const store = React7.useContext(import_react5.StoreContext);
|
|
172
|
-
const { socket } = React7.useContext(RealtimeContext);
|
|
173
|
-
React7.useEffect(() => {
|
|
174
|
-
var _a;
|
|
175
|
-
const count = (_a = TX_SUBS.get(token.key)) != null ? _a : 0;
|
|
176
|
-
TX_SUBS.set(token.key, count + 1);
|
|
177
|
-
const unsubscribe = count === 0 ? AtomIO7.subscribeToTransaction(
|
|
178
|
-
token,
|
|
179
|
-
(update) => socket.emit(`tx:${token.key}`, update),
|
|
180
|
-
store
|
|
181
|
-
) : () => null;
|
|
182
|
-
return () => {
|
|
183
|
-
var _a2;
|
|
184
|
-
const newCount = (_a2 = TX_SUBS.get(token.key)) != null ? _a2 : 0;
|
|
185
|
-
TX_SUBS.set(token.key, newCount - 1);
|
|
186
|
-
unsubscribe();
|
|
187
|
-
};
|
|
188
|
-
}, [token.key]);
|
|
189
|
-
return AtomIO7.runTransaction(token, store);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// ../src/realtime-react/realtime-hooks.ts
|
|
193
|
-
var realtimeHooks = {
|
|
194
|
-
usePull,
|
|
195
|
-
usePullFamily,
|
|
196
|
-
usePullFamilyMember,
|
|
197
|
-
usePush,
|
|
198
|
-
useServerAction
|
|
199
|
-
};
|
|
200
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
-
0 && (module.exports = {
|
|
202
|
-
RealtimeContext,
|
|
203
|
-
RealtimeProvider,
|
|
204
|
-
myIdState,
|
|
205
|
-
myIdState__INTERNAL,
|
|
206
|
-
realtimeHooks,
|
|
207
|
-
usePull,
|
|
208
|
-
usePullFamily,
|
|
209
|
-
usePullFamilyMember,
|
|
210
|
-
usePush,
|
|
211
|
-
useServerAction
|
|
212
|
-
});
|
|
213
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/realtime-react/index.ts","../../src/realtime-react/realtime-context.tsx","../../src/realtime-react/realtime-state.ts","../../src/realtime-react/use-pull.ts","../../src/react/store-context.tsx","../../src/realtime-react/use-pull-family.ts","../../src/realtime-react/use-pull-family-member.ts","../../src/realtime-react/use-push.ts","../../src/realtime-react/use-server-action.ts","../../src/realtime-react/realtime-hooks.ts"],"sourcesContent":["export * from \"./realtime-context\"\nexport * from \"./realtime-hooks\"\nexport * from \"./realtime-state\"\n","import * as React from \"react\"\n\nimport * as AR from \"atom.io/react\"\nimport type { Socket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nimport { myIdState__INTERNAL } from \"./realtime-state\"\n\nexport const RealtimeContext = React.createContext<{ socket: Socket }>({\n socket: io(),\n})\n\nexport const RealtimeProvider: React.FC<{\n children: React.ReactNode\n socket: Socket\n}> = ({ children, socket }) => {\n const setMyId = AR.useI(myIdState__INTERNAL)\n React.useEffect(() => {\n socket.on(`connect`, () => {\n setMyId(socket.id)\n })\n socket.on(`disconnect`, () => {\n setMyId(null)\n })\n }, [socket, setMyId])\n return (\n <RealtimeContext.Provider value={{ socket }}>\n {children}\n </RealtimeContext.Provider>\n )\n}\n","import * as AtomIO from \"atom.io\"\n\nexport const myIdState__INTERNAL = AtomIO.atom<string | null>({\n key: `myId__INTERNAL`,\n default: null,\n})\nexport const myIdState = AtomIO.selector<string | null>({\n key: `myId`,\n get: ({ get }) => get(myIdState__INTERNAL),\n})\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePull<J extends Json>(token: AtomIO.StateToken<J>): void {\n const { socket } = React.useContext(RealtimeContext)\n const store = React.useContext(StoreContext)\n React.useEffect(() => {\n socket.on(`serve:${token.key}`, (data: J) => {\n AtomIO.setState(token, data, store)\n })\n socket.emit(`sub:${token.key}`)\n return () => {\n socket.off(`serve:${token.key}`)\n socket.emit(`unsub:${token.key}`)\n }\n }, [token.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nexport const StoreContext = React.createContext<AtomIO.Store>(\n AtomIO.__INTERNAL__.IMPLICIT.STORE\n)\n\nexport const StoreProvider: React.FC<{\n children: React.ReactNode\n store?: AtomIO.Store\n}> = ({ children, store = AtomIO.__INTERNAL__.IMPLICIT.STORE }) => (\n <StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePullFamily<J extends Json>(\n family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>\n): void {\n const { socket } = React.useContext(RealtimeContext)\n const store = React.useContext(StoreContext)\n React.useEffect(() => {\n socket.on(`serve:${family.key}`, (key: Json, data: J) => {\n AtomIO.setState(family(key), data, store)\n })\n socket?.emit(`sub:${family.key}`)\n return () => {\n socket?.off(`serve:${family.key}`)\n socket?.emit(`unsub:${family.key}`)\n }\n }, [family.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePullFamilyMember<J extends Json>(\n family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n subKey: AtomIO.Serializable\n): void {\n const token = family(subKey)\n const { socket } = React.useContext(RealtimeContext)\n const store = React.useContext(StoreContext)\n React.useEffect(() => {\n socket?.on(`serve:${token.key}`, (data: J) => {\n AtomIO.setState(family(subKey), data, store)\n })\n socket?.emit(`sub:${family.key}`, subKey)\n return () => {\n socket?.off(`serve:${token.key}`)\n socket?.emit(`unsub:${token.key}`)\n }\n }, [family.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePush<J extends Json>(token: AtomIO.StateToken<J>): void {\n const { socket } = React.useContext(RealtimeContext)\n const store = React.useContext(StoreContext)\n React.useEffect(() => {\n socket.emit(`claim:${token.key}`)\n AtomIO.subscribe(\n token,\n ({ newValue }) => {\n socket.emit(`pub:${token.key}`, newValue)\n },\n store\n )\n return () => {\n socket.emit(`unclaim:${token.key}`)\n }\n }, [token.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\nimport { StoreContext } from \"atom.io/react\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nconst TX_SUBS = new Map<string, number>()\nexport function useServerAction<ƒ extends ƒn>(\n token: AtomIO.TransactionToken<ƒ>\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n const store = React.useContext(StoreContext)\n const { socket } = React.useContext(RealtimeContext)\n React.useEffect(() => {\n const count = TX_SUBS.get(token.key) ?? 0\n TX_SUBS.set(token.key, count + 1)\n const unsubscribe =\n count === 0\n ? AtomIO.subscribeToTransaction(\n token,\n (update) => socket.emit(`tx:${token.key}`, update),\n store\n )\n : () => null\n return () => {\n const newCount = TX_SUBS.get(token.key) ?? 0\n TX_SUBS.set(token.key, newCount - 1)\n unsubscribe()\n }\n }, [token.key])\n return AtomIO.runTransaction(token, store)\n}\n","import type * as AtomIO from \"atom.io\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { usePull } from \"./use-pull\"\nimport { usePullFamily } from \"./use-pull-family\"\nimport { usePullFamilyMember } from \"./use-pull-family-member\"\nimport { usePush } from \"./use-push\"\nimport { useServerAction } from \"./use-server-action\"\n\nexport type RealtimeHooks = {\n usePull: <J extends Json>(token: AtomIO.StateToken<J>) => void\n usePullFamily: <J extends Json>(\n family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>\n ) => void\n usePullFamilyMember: <J extends Json>(\n family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n subKey: string\n ) => void\n usePush: <J extends Json>(token: AtomIO.StateToken<J>) => void\n useServerAction: <ƒ extends ƒn>(\n token: AtomIO.TransactionToken<ƒ>\n ) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>\n}\n\nexport const realtimeHooks: RealtimeHooks = {\n usePull,\n usePullFamily,\n usePullFamilyMember,\n usePush,\n useServerAction,\n}\n\nexport * from \"./use-pull\"\nexport * from \"./use-pull-family\"\nexport * from \"./use-pull-family-member\"\nexport * from \"./use-push\"\nexport * from \"./use-server-action\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AAEvB,SAAoB;AAEpB,oBAAmB;;;ACJnB,aAAwB;AAEjB,IAAM,sBAA6B,YAAoB;AAAA,EAC5D,KAAK;AAAA,EACL,SAAS;AACX,CAAC;AACM,IAAM,YAAmB,gBAAwB;AAAA,EACtD,KAAK;AAAA,EACL,KAAK,CAAC,EAAE,IAAI,MAAM,IAAI,mBAAmB;AAC3C,CAAC;;;ADiBG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AAG,EAAE;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,GAAG,CAAC;AAChB;;;ACzBA,IAAAC,SAAuB;AAEvB,IAAAC,UAAwB;AACxB,IAAAC,gBAA6B;AAM7B,IAAM,UAAU,oBAAI,IAAoB;AACjC,SAAS,gBACd,OACiD;AACjD,QAAM,QAAc,kBAAW,0BAAY;AAC3C,QAAM,EAAE,OAAO,IAAU,kBAAW,eAAe;AACnD,EAAM,iBAAU,MAAM;AAfxB;AAgBI,UAAM,SAAQ,aAAQ,IAAI,MAAM,GAAG,MAArB,YAA0B;AACxC,YAAQ,IAAI,MAAM,KAAK,QAAQ,CAAC;AAChC,UAAM,cACJ,UAAU,IACC;AAAA,MACL;AAAA,MACA,CAAC,WAAW,OAAO,KAAK,MAAM,MAAM,GAAG,IAAI,MAAM;AAAA,MACjD;AAAA,IACF,IACA,MAAM;AACZ,WAAO,MAAM;AA1BjB,UAAAC;AA2BM,YAAM,YAAWA,MAAA,QAAQ,IAAI,MAAM,GAAG,MAArB,OAAAA,MAA0B;AAC3C,cAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnC,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,MAAM,GAAG,CAAC;AACd,SAAc,uBAAe,OAAO,KAAK;AAC3C;;;ACPO,IAAM,gBAA+B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":["React","AtomIO","React","AtomIO","import_jsx_runtime","React","AtomIO","React","AtomIO","React","AtomIO","React","AtomIO","import_react","_a"]}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
// ../src/realtime-react/realtime-context.tsx
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import * as AR from "atom.io/react";
|
|
4
|
-
import { io } from "socket.io-client";
|
|
5
|
-
|
|
6
|
-
// ../src/realtime-react/realtime-state.ts
|
|
7
|
-
import * as AtomIO from "atom.io";
|
|
8
|
-
var myIdState__INTERNAL = AtomIO.atom({
|
|
9
|
-
key: `myId__INTERNAL`,
|
|
10
|
-
default: null
|
|
11
|
-
});
|
|
12
|
-
var myIdState = AtomIO.selector({
|
|
13
|
-
key: `myId`,
|
|
14
|
-
get: ({ get }) => get(myIdState__INTERNAL)
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// ../src/realtime-react/realtime-context.tsx
|
|
18
|
-
import { jsx } from "react/jsx-runtime";
|
|
19
|
-
var RealtimeContext = React.createContext({
|
|
20
|
-
socket: io()
|
|
21
|
-
});
|
|
22
|
-
var RealtimeProvider = ({ children, socket }) => {
|
|
23
|
-
const setMyId = AR.useI(myIdState__INTERNAL);
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
socket.on(`connect`, () => {
|
|
26
|
-
setMyId(socket.id);
|
|
27
|
-
});
|
|
28
|
-
socket.on(`disconnect`, () => {
|
|
29
|
-
setMyId(null);
|
|
30
|
-
});
|
|
31
|
-
}, [socket, setMyId]);
|
|
32
|
-
return /* @__PURE__ */ jsx(RealtimeContext.Provider, { value: { socket }, children });
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// ../src/realtime-react/use-pull.ts
|
|
36
|
-
import * as React3 from "react";
|
|
37
|
-
import * as AtomIO3 from "atom.io";
|
|
38
|
-
|
|
39
|
-
// ../src/react/store-context.tsx
|
|
40
|
-
import * as React2 from "react";
|
|
41
|
-
import * as AtomIO2 from "atom.io";
|
|
42
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
43
|
-
var StoreContext = React2.createContext(
|
|
44
|
-
AtomIO2.__INTERNAL__.IMPLICIT.STORE
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
// ../src/realtime-react/use-pull.ts
|
|
48
|
-
function usePull(token) {
|
|
49
|
-
const { socket } = React3.useContext(RealtimeContext);
|
|
50
|
-
const store = React3.useContext(StoreContext);
|
|
51
|
-
React3.useEffect(() => {
|
|
52
|
-
socket.on(`serve:${token.key}`, (data) => {
|
|
53
|
-
AtomIO3.setState(token, data, store);
|
|
54
|
-
});
|
|
55
|
-
socket.emit(`sub:${token.key}`);
|
|
56
|
-
return () => {
|
|
57
|
-
socket.off(`serve:${token.key}`);
|
|
58
|
-
socket.emit(`unsub:${token.key}`);
|
|
59
|
-
};
|
|
60
|
-
}, [token.key]);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ../src/realtime-react/use-pull-family.ts
|
|
64
|
-
import * as React4 from "react";
|
|
65
|
-
import * as AtomIO4 from "atom.io";
|
|
66
|
-
function usePullFamily(family) {
|
|
67
|
-
const { socket } = React4.useContext(RealtimeContext);
|
|
68
|
-
const store = React4.useContext(StoreContext);
|
|
69
|
-
React4.useEffect(() => {
|
|
70
|
-
socket.on(`serve:${family.key}`, (key, data) => {
|
|
71
|
-
AtomIO4.setState(family(key), data, store);
|
|
72
|
-
});
|
|
73
|
-
socket == null ? void 0 : socket.emit(`sub:${family.key}`);
|
|
74
|
-
return () => {
|
|
75
|
-
socket == null ? void 0 : socket.off(`serve:${family.key}`);
|
|
76
|
-
socket == null ? void 0 : socket.emit(`unsub:${family.key}`);
|
|
77
|
-
};
|
|
78
|
-
}, [family.key]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// ../src/realtime-react/use-pull-family-member.ts
|
|
82
|
-
import * as React5 from "react";
|
|
83
|
-
import * as AtomIO5 from "atom.io";
|
|
84
|
-
function usePullFamilyMember(family, subKey) {
|
|
85
|
-
const token = family(subKey);
|
|
86
|
-
const { socket } = React5.useContext(RealtimeContext);
|
|
87
|
-
const store = React5.useContext(StoreContext);
|
|
88
|
-
React5.useEffect(() => {
|
|
89
|
-
socket == null ? void 0 : socket.on(`serve:${token.key}`, (data) => {
|
|
90
|
-
AtomIO5.setState(family(subKey), data, store);
|
|
91
|
-
});
|
|
92
|
-
socket == null ? void 0 : socket.emit(`sub:${family.key}`, subKey);
|
|
93
|
-
return () => {
|
|
94
|
-
socket == null ? void 0 : socket.off(`serve:${token.key}`);
|
|
95
|
-
socket == null ? void 0 : socket.emit(`unsub:${token.key}`);
|
|
96
|
-
};
|
|
97
|
-
}, [family.key]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ../src/realtime-react/use-push.ts
|
|
101
|
-
import * as React6 from "react";
|
|
102
|
-
import * as AtomIO6 from "atom.io";
|
|
103
|
-
function usePush(token) {
|
|
104
|
-
const { socket } = React6.useContext(RealtimeContext);
|
|
105
|
-
const store = React6.useContext(StoreContext);
|
|
106
|
-
React6.useEffect(() => {
|
|
107
|
-
socket.emit(`claim:${token.key}`);
|
|
108
|
-
AtomIO6.subscribe(
|
|
109
|
-
token,
|
|
110
|
-
({ newValue }) => {
|
|
111
|
-
socket.emit(`pub:${token.key}`, newValue);
|
|
112
|
-
},
|
|
113
|
-
store
|
|
114
|
-
);
|
|
115
|
-
return () => {
|
|
116
|
-
socket.emit(`unclaim:${token.key}`);
|
|
117
|
-
};
|
|
118
|
-
}, [token.key]);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ../src/realtime-react/use-server-action.ts
|
|
122
|
-
import * as React7 from "react";
|
|
123
|
-
import * as AtomIO7 from "atom.io";
|
|
124
|
-
import { StoreContext as StoreContext2 } from "atom.io/react";
|
|
125
|
-
var TX_SUBS = /* @__PURE__ */ new Map();
|
|
126
|
-
function useServerAction(token) {
|
|
127
|
-
const store = React7.useContext(StoreContext2);
|
|
128
|
-
const { socket } = React7.useContext(RealtimeContext);
|
|
129
|
-
React7.useEffect(() => {
|
|
130
|
-
var _a;
|
|
131
|
-
const count = (_a = TX_SUBS.get(token.key)) != null ? _a : 0;
|
|
132
|
-
TX_SUBS.set(token.key, count + 1);
|
|
133
|
-
const unsubscribe = count === 0 ? AtomIO7.subscribeToTransaction(
|
|
134
|
-
token,
|
|
135
|
-
(update) => socket.emit(`tx:${token.key}`, update),
|
|
136
|
-
store
|
|
137
|
-
) : () => null;
|
|
138
|
-
return () => {
|
|
139
|
-
var _a2;
|
|
140
|
-
const newCount = (_a2 = TX_SUBS.get(token.key)) != null ? _a2 : 0;
|
|
141
|
-
TX_SUBS.set(token.key, newCount - 1);
|
|
142
|
-
unsubscribe();
|
|
143
|
-
};
|
|
144
|
-
}, [token.key]);
|
|
145
|
-
return AtomIO7.runTransaction(token, store);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// ../src/realtime-react/realtime-hooks.ts
|
|
149
|
-
var realtimeHooks = {
|
|
150
|
-
usePull,
|
|
151
|
-
usePullFamily,
|
|
152
|
-
usePullFamilyMember,
|
|
153
|
-
usePush,
|
|
154
|
-
useServerAction
|
|
155
|
-
};
|
|
156
|
-
export {
|
|
157
|
-
RealtimeContext,
|
|
158
|
-
RealtimeProvider,
|
|
159
|
-
myIdState,
|
|
160
|
-
myIdState__INTERNAL,
|
|
161
|
-
realtimeHooks,
|
|
162
|
-
usePull,
|
|
163
|
-
usePullFamily,
|
|
164
|
-
usePullFamilyMember,
|
|
165
|
-
usePush,
|
|
166
|
-
useServerAction
|
|
167
|
-
};
|
|
168
|
-
//# sourceMappingURL=index.mjs.map
|