@legendapp/state 3.0.0-alpha.41 → 3.0.0-alpha.42
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/package.json +1 -1
- package/sync.js +40 -36
- package/sync.mjs +40 -36
package/package.json
CHANGED
package/sync.js
CHANGED
|
@@ -162,43 +162,47 @@ function createRetryTimeout(retryOptions, retryNum, fn) {
|
|
|
162
162
|
}
|
|
163
163
|
var mapRetryTimeouts = /* @__PURE__ */ new Map();
|
|
164
164
|
function runWithRetry(state, retryOptions, fn, onError) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (onError) {
|
|
181
|
-
onError(error, state);
|
|
182
|
-
}
|
|
183
|
-
if (!state.cancelRetry) {
|
|
184
|
-
const timeout = createRetryTimeout(retryOptions, state.retryNum, () => {
|
|
185
|
-
value = fn(state);
|
|
186
|
-
run();
|
|
187
|
-
});
|
|
188
|
-
if (timeout === false) {
|
|
189
|
-
state.cancelRetry = true;
|
|
190
|
-
reject(error);
|
|
191
|
-
} else {
|
|
192
|
-
mapRetryTimeouts.set(state.node, timeout);
|
|
193
|
-
timeoutRetry = timeout;
|
|
165
|
+
try {
|
|
166
|
+
let value = fn(state);
|
|
167
|
+
if (isPromise(value) && retryOptions) {
|
|
168
|
+
let timeoutRetry;
|
|
169
|
+
if (mapRetryTimeouts.has(state.node)) {
|
|
170
|
+
clearTimeout(mapRetryTimeouts.get(state.node));
|
|
171
|
+
}
|
|
172
|
+
return new Promise((resolve, reject) => {
|
|
173
|
+
const run = () => {
|
|
174
|
+
value.then((val) => {
|
|
175
|
+
resolve(val);
|
|
176
|
+
}).catch((error) => {
|
|
177
|
+
state.retryNum++;
|
|
178
|
+
if (timeoutRetry) {
|
|
179
|
+
clearTimeout(timeoutRetry);
|
|
194
180
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
181
|
+
if (onError) {
|
|
182
|
+
onError(error, state);
|
|
183
|
+
}
|
|
184
|
+
if (!state.cancelRetry) {
|
|
185
|
+
const timeout = createRetryTimeout(retryOptions, state.retryNum, () => {
|
|
186
|
+
value = fn(state);
|
|
187
|
+
run();
|
|
188
|
+
});
|
|
189
|
+
if (timeout === false) {
|
|
190
|
+
state.cancelRetry = true;
|
|
191
|
+
reject(error);
|
|
192
|
+
} else {
|
|
193
|
+
mapRetryTimeouts.set(state.node, timeout);
|
|
194
|
+
timeoutRetry = timeout;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
run();
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return value;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
return Promise.reject(error);
|
|
200
205
|
}
|
|
201
|
-
return value;
|
|
202
206
|
}
|
|
203
207
|
async function waitForSet(waitForSet2, changes, value, params = {}) {
|
|
204
208
|
const waitFn = state.isFunction(waitForSet2) ? waitForSet2({ changes, value, ...params }) : waitForSet2;
|
|
@@ -1051,7 +1055,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1051
1055
|
});
|
|
1052
1056
|
};
|
|
1053
1057
|
if (state.isPromise(got)) {
|
|
1054
|
-
got.then(handle);
|
|
1058
|
+
got.then(handle).catch(onError);
|
|
1055
1059
|
} else {
|
|
1056
1060
|
handle(got);
|
|
1057
1061
|
}
|
package/sync.mjs
CHANGED
|
@@ -160,43 +160,47 @@ function createRetryTimeout(retryOptions, retryNum, fn) {
|
|
|
160
160
|
}
|
|
161
161
|
var mapRetryTimeouts = /* @__PURE__ */ new Map();
|
|
162
162
|
function runWithRetry(state, retryOptions, fn, onError) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (onError) {
|
|
179
|
-
onError(error, state);
|
|
180
|
-
}
|
|
181
|
-
if (!state.cancelRetry) {
|
|
182
|
-
const timeout = createRetryTimeout(retryOptions, state.retryNum, () => {
|
|
183
|
-
value = fn(state);
|
|
184
|
-
run();
|
|
185
|
-
});
|
|
186
|
-
if (timeout === false) {
|
|
187
|
-
state.cancelRetry = true;
|
|
188
|
-
reject(error);
|
|
189
|
-
} else {
|
|
190
|
-
mapRetryTimeouts.set(state.node, timeout);
|
|
191
|
-
timeoutRetry = timeout;
|
|
163
|
+
try {
|
|
164
|
+
let value = fn(state);
|
|
165
|
+
if (isPromise(value) && retryOptions) {
|
|
166
|
+
let timeoutRetry;
|
|
167
|
+
if (mapRetryTimeouts.has(state.node)) {
|
|
168
|
+
clearTimeout(mapRetryTimeouts.get(state.node));
|
|
169
|
+
}
|
|
170
|
+
return new Promise((resolve, reject) => {
|
|
171
|
+
const run = () => {
|
|
172
|
+
value.then((val) => {
|
|
173
|
+
resolve(val);
|
|
174
|
+
}).catch((error) => {
|
|
175
|
+
state.retryNum++;
|
|
176
|
+
if (timeoutRetry) {
|
|
177
|
+
clearTimeout(timeoutRetry);
|
|
192
178
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
179
|
+
if (onError) {
|
|
180
|
+
onError(error, state);
|
|
181
|
+
}
|
|
182
|
+
if (!state.cancelRetry) {
|
|
183
|
+
const timeout = createRetryTimeout(retryOptions, state.retryNum, () => {
|
|
184
|
+
value = fn(state);
|
|
185
|
+
run();
|
|
186
|
+
});
|
|
187
|
+
if (timeout === false) {
|
|
188
|
+
state.cancelRetry = true;
|
|
189
|
+
reject(error);
|
|
190
|
+
} else {
|
|
191
|
+
mapRetryTimeouts.set(state.node, timeout);
|
|
192
|
+
timeoutRetry = timeout;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
run();
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return value;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
return Promise.reject(error);
|
|
198
203
|
}
|
|
199
|
-
return value;
|
|
200
204
|
}
|
|
201
205
|
async function waitForSet(waitForSet2, changes, value, params = {}) {
|
|
202
206
|
const waitFn = isFunction(waitForSet2) ? waitForSet2({ changes, value, ...params }) : waitForSet2;
|
|
@@ -1049,7 +1053,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1049
1053
|
});
|
|
1050
1054
|
};
|
|
1051
1055
|
if (isPromise$1(got)) {
|
|
1052
|
-
got.then(handle);
|
|
1056
|
+
got.then(handle).catch(onError);
|
|
1053
1057
|
} else {
|
|
1054
1058
|
handle(got);
|
|
1055
1059
|
}
|