floppy-disk 3.7.0-beta.2 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/react.mjs +29 -30
- package/package.json +1 -4
- package/react.js +29 -30
package/esm/react.mjs
CHANGED
|
@@ -822,6 +822,33 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
822
822
|
}
|
|
823
823
|
}
|
|
824
824
|
});
|
|
825
|
+
const disconnectAndSetState = (store, showLog = false) => {
|
|
826
|
+
var _a;
|
|
827
|
+
if (store.getSubscriberCount() && showLog) {
|
|
828
|
+
console.log("Stream disconnected while there is subscriber");
|
|
829
|
+
}
|
|
830
|
+
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
831
|
+
if (disconnectTimeoutIds_) {
|
|
832
|
+
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
833
|
+
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
834
|
+
clearTimeout(disconnectTimeoutIds_.offline);
|
|
835
|
+
}
|
|
836
|
+
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
837
|
+
if (store.getState().connectionState !== "INITIAL") {
|
|
838
|
+
store.setState({
|
|
839
|
+
connectionState: "DISCONNECTED",
|
|
840
|
+
disconnectedAt: Date.now()
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
connections.delete(store);
|
|
844
|
+
disconnectFns.delete(store);
|
|
845
|
+
clearDataTimeoutIds.set(
|
|
846
|
+
store,
|
|
847
|
+
setTimeout(() => {
|
|
848
|
+
store.data.reset();
|
|
849
|
+
}, gcTime)
|
|
850
|
+
);
|
|
851
|
+
};
|
|
825
852
|
const getStore = (variable = {}) => {
|
|
826
853
|
const variableHash = getHash(variable);
|
|
827
854
|
let store;
|
|
@@ -882,33 +909,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
882
909
|
connections.set(store, connection);
|
|
883
910
|
disconnectFns.set(store, () => disconnect(connection));
|
|
884
911
|
};
|
|
885
|
-
store.connection.disconnect = () =>
|
|
886
|
-
var _a;
|
|
887
|
-
if (store.getSubscriberCount()) {
|
|
888
|
-
console.warn("Stream disconnected while there is subscriber");
|
|
889
|
-
}
|
|
890
|
-
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
891
|
-
if (disconnectTimeoutIds_) {
|
|
892
|
-
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
893
|
-
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
894
|
-
clearTimeout(disconnectTimeoutIds_.offline);
|
|
895
|
-
}
|
|
896
|
-
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
897
|
-
if (store.getState().connectionState !== "INITIAL") {
|
|
898
|
-
store.setState({
|
|
899
|
-
connectionState: "DISCONNECTED",
|
|
900
|
-
disconnectedAt: Date.now()
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
connections.delete(store);
|
|
904
|
-
disconnectFns.delete(store);
|
|
905
|
-
clearDataTimeoutIds.set(
|
|
906
|
-
store,
|
|
907
|
-
setTimeout(() => {
|
|
908
|
-
store.data.reset();
|
|
909
|
-
}, gcTime)
|
|
910
|
-
);
|
|
911
|
-
};
|
|
912
|
+
store.connection.disconnect = () => disconnectAndSetState(store, true);
|
|
912
913
|
store.data = {};
|
|
913
914
|
store.data.reset = () => {
|
|
914
915
|
store.setState({
|
|
@@ -936,12 +937,10 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
936
937
|
clearTimeout(disconnectTimeoutIds_.offline);
|
|
937
938
|
}
|
|
938
939
|
const { connectionState } = store.getState();
|
|
939
|
-
console.info("triggerReconnect", connectionState);
|
|
940
940
|
if (connectionState === "INITIAL" || connectionState === "DISCONNECTED") {
|
|
941
941
|
return store.connection.reconnect();
|
|
942
942
|
}
|
|
943
943
|
const shouldReconnect = reconnectOn(trigger, store.getState());
|
|
944
|
-
console.log({ shouldReconnect });
|
|
945
944
|
if (shouldReconnect) store.connection.reconnect();
|
|
946
945
|
};
|
|
947
946
|
const triggerDisconnect = (store, trigger) => {
|
|
@@ -950,7 +949,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
950
949
|
if (!disconnectTimeoutIds.has(store)) disconnectTimeoutIds.set(store, {});
|
|
951
950
|
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
952
951
|
disconnectTimeoutIds_[trigger] = setTimeout(() => {
|
|
953
|
-
store
|
|
952
|
+
disconnectAndSetState(store);
|
|
954
953
|
}, disconnectDelay);
|
|
955
954
|
};
|
|
956
955
|
const triggers = {
|
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.0
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"tag": "beta"
|
|
8
|
-
},
|
|
5
|
+
"version": "3.7.0",
|
|
9
6
|
"keywords": [
|
|
10
7
|
"utilities",
|
|
11
8
|
"store",
|
package/react.js
CHANGED
|
@@ -824,6 +824,33 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
824
824
|
}
|
|
825
825
|
}
|
|
826
826
|
});
|
|
827
|
+
const disconnectAndSetState = (store, showLog = false) => {
|
|
828
|
+
var _a;
|
|
829
|
+
if (store.getSubscriberCount() && showLog) {
|
|
830
|
+
console.log("Stream disconnected while there is subscriber");
|
|
831
|
+
}
|
|
832
|
+
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
833
|
+
if (disconnectTimeoutIds_) {
|
|
834
|
+
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
835
|
+
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
836
|
+
clearTimeout(disconnectTimeoutIds_.offline);
|
|
837
|
+
}
|
|
838
|
+
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
839
|
+
if (store.getState().connectionState !== "INITIAL") {
|
|
840
|
+
store.setState({
|
|
841
|
+
connectionState: "DISCONNECTED",
|
|
842
|
+
disconnectedAt: Date.now()
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
connections.delete(store);
|
|
846
|
+
disconnectFns.delete(store);
|
|
847
|
+
clearDataTimeoutIds.set(
|
|
848
|
+
store,
|
|
849
|
+
setTimeout(() => {
|
|
850
|
+
store.data.reset();
|
|
851
|
+
}, gcTime)
|
|
852
|
+
);
|
|
853
|
+
};
|
|
827
854
|
const getStore = (variable = {}) => {
|
|
828
855
|
const variableHash = vanilla.getHash(variable);
|
|
829
856
|
let store;
|
|
@@ -884,33 +911,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
884
911
|
connections.set(store, connection);
|
|
885
912
|
disconnectFns.set(store, () => disconnect(connection));
|
|
886
913
|
};
|
|
887
|
-
store.connection.disconnect = () =>
|
|
888
|
-
var _a;
|
|
889
|
-
if (store.getSubscriberCount()) {
|
|
890
|
-
console.warn("Stream disconnected while there is subscriber");
|
|
891
|
-
}
|
|
892
|
-
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
893
|
-
if (disconnectTimeoutIds_) {
|
|
894
|
-
clearTimeout(disconnectTimeoutIds_["last-unsubscribe"]);
|
|
895
|
-
clearTimeout(disconnectTimeoutIds_["document-hidden"]);
|
|
896
|
-
clearTimeout(disconnectTimeoutIds_.offline);
|
|
897
|
-
}
|
|
898
|
-
(_a = disconnectFns.get(store)) == null ? void 0 : _a();
|
|
899
|
-
if (store.getState().connectionState !== "INITIAL") {
|
|
900
|
-
store.setState({
|
|
901
|
-
connectionState: "DISCONNECTED",
|
|
902
|
-
disconnectedAt: Date.now()
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
connections.delete(store);
|
|
906
|
-
disconnectFns.delete(store);
|
|
907
|
-
clearDataTimeoutIds.set(
|
|
908
|
-
store,
|
|
909
|
-
setTimeout(() => {
|
|
910
|
-
store.data.reset();
|
|
911
|
-
}, gcTime)
|
|
912
|
-
);
|
|
913
|
-
};
|
|
914
|
+
store.connection.disconnect = () => disconnectAndSetState(store, true);
|
|
914
915
|
store.data = {};
|
|
915
916
|
store.data.reset = () => {
|
|
916
917
|
store.setState({
|
|
@@ -938,12 +939,10 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
938
939
|
clearTimeout(disconnectTimeoutIds_.offline);
|
|
939
940
|
}
|
|
940
941
|
const { connectionState } = store.getState();
|
|
941
|
-
console.info("triggerReconnect", connectionState);
|
|
942
942
|
if (connectionState === "INITIAL" || connectionState === "DISCONNECTED") {
|
|
943
943
|
return store.connection.reconnect();
|
|
944
944
|
}
|
|
945
945
|
const shouldReconnect = reconnectOn(trigger, store.getState());
|
|
946
|
-
console.log({ shouldReconnect });
|
|
947
946
|
if (shouldReconnect) store.connection.reconnect();
|
|
948
947
|
};
|
|
949
948
|
const triggerDisconnect = (store, trigger) => {
|
|
@@ -952,7 +951,7 @@ const experimental_createStream = (connect, disconnect, options = {}) => {
|
|
|
952
951
|
if (!disconnectTimeoutIds.has(store)) disconnectTimeoutIds.set(store, {});
|
|
953
952
|
const disconnectTimeoutIds_ = disconnectTimeoutIds.get(store);
|
|
954
953
|
disconnectTimeoutIds_[trigger] = setTimeout(() => {
|
|
955
|
-
store
|
|
954
|
+
disconnectAndSetState(store);
|
|
956
955
|
}, disconnectDelay);
|
|
957
956
|
};
|
|
958
957
|
const triggers = {
|