floppy-disk 3.7.1-beta.1 → 3.7.1
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/esm/react/create-stream.d.mts +2 -2
- package/esm/react.mjs +21 -16
- package/package.json +1 -4
- package/react/create-stream.d.ts +2 -2
- package/react.js +21 -16
|
@@ -43,8 +43,8 @@ export type StreamState<TData, TError> = ({
|
|
|
43
43
|
}>) | ({
|
|
44
44
|
connectionState: "CONNECTING";
|
|
45
45
|
connectingAt: number;
|
|
46
|
-
connectedAt:
|
|
47
|
-
disconnectedAt:
|
|
46
|
+
connectedAt: undefined;
|
|
47
|
+
disconnectedAt: undefined;
|
|
48
48
|
} & StreamDataState<TData, TError>) | ({
|
|
49
49
|
connectionState: "CONNECTED";
|
|
50
50
|
connectingAt: number;
|
package/esm/react.mjs
CHANGED
|
@@ -785,6 +785,19 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
785
785
|
const connections = /* @__PURE__ */ new WeakMap();
|
|
786
786
|
const disconnectFns = /* @__PURE__ */ new WeakMap();
|
|
787
787
|
const disconnectTimeoutIds = /* @__PURE__ */ new WeakMap();
|
|
788
|
+
const clearAllTimeouts = (store) => {
|
|
789
|
+
const gcTimeoutId = gcTimeoutIds.get(store);
|
|
790
|
+
if (gcTimeoutId) {
|
|
791
|
+
clearTimeout(gcTimeoutId);
|
|
792
|
+
gcTimeoutIds.delete(store);
|
|
793
|
+
}
|
|
794
|
+
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
795
|
+
if (disconnectTimeoutIds_) {
|
|
796
|
+
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
797
|
+
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
798
|
+
clearTimeout(disconnectTimeoutIds_.offline);
|
|
799
|
+
}
|
|
800
|
+
};
|
|
788
801
|
const gcTimeoutIds = /* @__PURE__ */ new WeakMap();
|
|
789
802
|
const configureStoreEvents = () => ({
|
|
790
803
|
...options,
|
|
@@ -827,12 +840,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
827
840
|
if (store.getSubscriberCount() && showLog) {
|
|
828
841
|
console.log("Stream disconnected while there is subscriber");
|
|
829
842
|
}
|
|
830
|
-
|
|
831
|
-
if (disconnectTimeoutIds_) {
|
|
832
|
-
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
833
|
-
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
834
|
-
clearTimeout(disconnectTimeoutIds_.offline);
|
|
835
|
-
}
|
|
843
|
+
clearAllTimeouts(store);
|
|
836
844
|
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
837
845
|
if (store.getState().connectionState !== "INITIAL") {
|
|
838
846
|
store.setState({
|
|
@@ -845,8 +853,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
845
853
|
gcTimeoutIds.set(
|
|
846
854
|
store,
|
|
847
855
|
setTimeout(() => {
|
|
848
|
-
if (store.getSubscriberCount()) store.
|
|
849
|
-
else store.delete();
|
|
856
|
+
if (store.getSubscriberCount() === 0) store.delete();
|
|
850
857
|
}, gcTime)
|
|
851
858
|
);
|
|
852
859
|
};
|
|
@@ -867,12 +874,15 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
867
874
|
store.connection.get = () => connections.get(store);
|
|
868
875
|
store.connection.reconnect = () => {
|
|
869
876
|
var _a;
|
|
877
|
+
clearAllTimeouts(store);
|
|
870
878
|
const { connectionState } = store.getState();
|
|
871
879
|
if (connectionState === "CONNECTING") return;
|
|
872
880
|
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
873
881
|
store.setState({
|
|
874
882
|
connectionState: "CONNECTING",
|
|
875
|
-
connectingAt: Date.now()
|
|
883
|
+
connectingAt: Date.now(),
|
|
884
|
+
connectedAt: void 0,
|
|
885
|
+
disconnectedAt: void 0
|
|
876
886
|
});
|
|
877
887
|
const connection = connect(variable, {
|
|
878
888
|
connected: () => {
|
|
@@ -930,6 +940,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
930
940
|
);
|
|
931
941
|
return false;
|
|
932
942
|
}
|
|
943
|
+
clearAllTimeouts(store);
|
|
933
944
|
store.setState(initialState);
|
|
934
945
|
return stores.delete(variableHash);
|
|
935
946
|
};
|
|
@@ -946,13 +957,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
946
957
|
});
|
|
947
958
|
};
|
|
948
959
|
const triggerReconnect = (store, trigger) => {
|
|
949
|
-
|
|
950
|
-
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
951
|
-
if (disconnectTimeoutIds_) {
|
|
952
|
-
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
953
|
-
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
954
|
-
clearTimeout(disconnectTimeoutIds_.offline);
|
|
955
|
-
}
|
|
960
|
+
clearAllTimeouts(store);
|
|
956
961
|
const { connectionState } = store.getState();
|
|
957
962
|
if (connectionState === "INITIAL" || connectionState === "DISCONNECTED") {
|
|
958
963
|
return store.connection.reconnect();
|
package/package.json
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
"name": "floppy-disk",
|
|
3
3
|
"description": "Lightweight unified state management for sync and async data.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "3.7.1
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"tag": "beta"
|
|
8
|
-
},
|
|
5
|
+
"version": "3.7.1",
|
|
9
6
|
"keywords": [
|
|
10
7
|
"utilities",
|
|
11
8
|
"store",
|
package/react/create-stream.d.ts
CHANGED
|
@@ -43,8 +43,8 @@ export type StreamState<TData, TError> = ({
|
|
|
43
43
|
}>) | ({
|
|
44
44
|
connectionState: "CONNECTING";
|
|
45
45
|
connectingAt: number;
|
|
46
|
-
connectedAt:
|
|
47
|
-
disconnectedAt:
|
|
46
|
+
connectedAt: undefined;
|
|
47
|
+
disconnectedAt: undefined;
|
|
48
48
|
} & StreamDataState<TData, TError>) | ({
|
|
49
49
|
connectionState: "CONNECTED";
|
|
50
50
|
connectingAt: number;
|
package/react.js
CHANGED
|
@@ -787,6 +787,19 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
787
787
|
const connections = /* @__PURE__ */ new WeakMap();
|
|
788
788
|
const disconnectFns = /* @__PURE__ */ new WeakMap();
|
|
789
789
|
const disconnectTimeoutIds = /* @__PURE__ */ new WeakMap();
|
|
790
|
+
const clearAllTimeouts = (store) => {
|
|
791
|
+
const gcTimeoutId = gcTimeoutIds.get(store);
|
|
792
|
+
if (gcTimeoutId) {
|
|
793
|
+
clearTimeout(gcTimeoutId);
|
|
794
|
+
gcTimeoutIds.delete(store);
|
|
795
|
+
}
|
|
796
|
+
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
797
|
+
if (disconnectTimeoutIds_) {
|
|
798
|
+
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
799
|
+
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
800
|
+
clearTimeout(disconnectTimeoutIds_.offline);
|
|
801
|
+
}
|
|
802
|
+
};
|
|
790
803
|
const gcTimeoutIds = /* @__PURE__ */ new WeakMap();
|
|
791
804
|
const configureStoreEvents = () => ({
|
|
792
805
|
...options,
|
|
@@ -829,12 +842,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
829
842
|
if (store.getSubscriberCount() && showLog) {
|
|
830
843
|
console.log("Stream disconnected while there is subscriber");
|
|
831
844
|
}
|
|
832
|
-
|
|
833
|
-
if (disconnectTimeoutIds_) {
|
|
834
|
-
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
835
|
-
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
836
|
-
clearTimeout(disconnectTimeoutIds_.offline);
|
|
837
|
-
}
|
|
845
|
+
clearAllTimeouts(store);
|
|
838
846
|
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
839
847
|
if (store.getState().connectionState !== "INITIAL") {
|
|
840
848
|
store.setState({
|
|
@@ -847,8 +855,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
847
855
|
gcTimeoutIds.set(
|
|
848
856
|
store,
|
|
849
857
|
setTimeout(() => {
|
|
850
|
-
if (store.getSubscriberCount()) store.
|
|
851
|
-
else store.delete();
|
|
858
|
+
if (store.getSubscriberCount() === 0) store.delete();
|
|
852
859
|
}, gcTime)
|
|
853
860
|
);
|
|
854
861
|
};
|
|
@@ -869,12 +876,15 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
869
876
|
store.connection.get = () => connections.get(store);
|
|
870
877
|
store.connection.reconnect = () => {
|
|
871
878
|
var _a;
|
|
879
|
+
clearAllTimeouts(store);
|
|
872
880
|
const { connectionState } = store.getState();
|
|
873
881
|
if (connectionState === "CONNECTING") return;
|
|
874
882
|
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
875
883
|
store.setState({
|
|
876
884
|
connectionState: "CONNECTING",
|
|
877
|
-
connectingAt: Date.now()
|
|
885
|
+
connectingAt: Date.now(),
|
|
886
|
+
connectedAt: void 0,
|
|
887
|
+
disconnectedAt: void 0
|
|
878
888
|
});
|
|
879
889
|
const connection = connect(variable, {
|
|
880
890
|
connected: () => {
|
|
@@ -932,6 +942,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
932
942
|
);
|
|
933
943
|
return false;
|
|
934
944
|
}
|
|
945
|
+
clearAllTimeouts(store);
|
|
935
946
|
store.setState(initialState);
|
|
936
947
|
return stores.delete(variableHash);
|
|
937
948
|
};
|
|
@@ -948,13 +959,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
948
959
|
});
|
|
949
960
|
};
|
|
950
961
|
const triggerReconnect = (store, trigger) => {
|
|
951
|
-
|
|
952
|
-
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
953
|
-
if (disconnectTimeoutIds_) {
|
|
954
|
-
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
955
|
-
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
956
|
-
clearTimeout(disconnectTimeoutIds_.offline);
|
|
957
|
-
}
|
|
962
|
+
clearAllTimeouts(store);
|
|
958
963
|
const { connectionState } = store.getState();
|
|
959
964
|
if (connectionState === "INITIAL" || connectionState === "DISCONNECTED") {
|
|
960
965
|
return store.connection.reconnect();
|