add fatal error sync action
This commit is contained in:
parent
8093d69807
commit
8344379bfd
4 changed files with 96 additions and 69 deletions
80
dist/bundle.es.js
vendored
80
dist/bundle.es.js
vendored
|
@ -289,6 +289,7 @@ const FETCH_COST_INFO_FAILED = 'FETCH_COST_INFO_FAILED';
|
||||||
|
|
||||||
// Sync
|
// Sync
|
||||||
const USER_STATE_POPULATE = 'USER_STATE_POPULATE';
|
const USER_STATE_POPULATE = 'USER_STATE_POPULATE';
|
||||||
|
const SYNC_FATAL_ERROR = 'SYNC_FATAL_ERROR';
|
||||||
|
|
||||||
var action_types = /*#__PURE__*/Object.freeze({
|
var action_types = /*#__PURE__*/Object.freeze({
|
||||||
WINDOW_FOCUSED: WINDOW_FOCUSED,
|
WINDOW_FOCUSED: WINDOW_FOCUSED,
|
||||||
|
@ -529,7 +530,8 @@ var action_types = /*#__PURE__*/Object.freeze({
|
||||||
FETCH_COST_INFO_STARTED: FETCH_COST_INFO_STARTED,
|
FETCH_COST_INFO_STARTED: FETCH_COST_INFO_STARTED,
|
||||||
FETCH_COST_INFO_COMPLETED: FETCH_COST_INFO_COMPLETED,
|
FETCH_COST_INFO_COMPLETED: FETCH_COST_INFO_COMPLETED,
|
||||||
FETCH_COST_INFO_FAILED: FETCH_COST_INFO_FAILED,
|
FETCH_COST_INFO_FAILED: FETCH_COST_INFO_FAILED,
|
||||||
USER_STATE_POPULATE: USER_STATE_POPULATE
|
USER_STATE_POPULATE: USER_STATE_POPULATE,
|
||||||
|
SYNC_FATAL_ERROR: SYNC_FATAL_ERROR
|
||||||
});
|
});
|
||||||
|
|
||||||
const CC_LICENSES = [{
|
const CC_LICENSES = [{
|
||||||
|
@ -1754,43 +1756,55 @@ function doPopulateSharedUserState(sharedSettings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function doPreferenceSet(key, value, version, success, fail) {
|
function doPreferenceSet(key, value, version, success, fail) {
|
||||||
const preference = {
|
return dispatch => {
|
||||||
type: typeof value,
|
const preference = {
|
||||||
version,
|
type: typeof value,
|
||||||
value
|
version,
|
||||||
};
|
value
|
||||||
|
};
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
key,
|
key,
|
||||||
value: JSON.stringify(preference)
|
value: JSON.stringify(preference)
|
||||||
};
|
};
|
||||||
|
|
||||||
lbryProxy.preference_set(options).then(() => {
|
lbryProxy.preference_set(options).then(() => {
|
||||||
success(preference);
|
success(preference);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
if (fail) {
|
dispatch({
|
||||||
fail();
|
type: SYNC_FATAL_ERROR
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
if (fail) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function doPreferenceGet(key, success, fail) {
|
function doPreferenceGet(key, success, fail) {
|
||||||
const options = {
|
return dispatch => {
|
||||||
key
|
const options = {
|
||||||
|
key
|
||||||
|
};
|
||||||
|
|
||||||
|
return lbryProxy.preference_get(options).then(result => {
|
||||||
|
if (result) {
|
||||||
|
const preference = result[key];
|
||||||
|
return success(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(null);
|
||||||
|
}).catch(err => {
|
||||||
|
dispatch({
|
||||||
|
type: SYNC_FATAL_ERROR
|
||||||
|
});
|
||||||
|
|
||||||
|
if (fail) {
|
||||||
|
fail(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return lbryProxy.preference_get(options).then(result => {
|
|
||||||
if (result) {
|
|
||||||
const preference = result[key];
|
|
||||||
return success(preference);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success(null);
|
|
||||||
}).catch(err => {
|
|
||||||
if (fail) {
|
|
||||||
fail(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -1831,7 +1845,7 @@ const buildSharedStateMiddleware = (actions, sharedStateFilters, sharedStateCb)
|
||||||
if (!isEqual(oldShared, shared)) {
|
if (!isEqual(oldShared, shared)) {
|
||||||
// only update if the preference changed from last call in the same session
|
// only update if the preference changed from last call in the same session
|
||||||
oldShared = shared;
|
oldShared = shared;
|
||||||
doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION);
|
dispatch(doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sharedStateCb) {
|
if (sharedStateCb) {
|
||||||
|
|
|
@ -268,3 +268,4 @@ export const FETCH_COST_INFO_FAILED = 'FETCH_COST_INFO_FAILED';
|
||||||
|
|
||||||
// Sync
|
// Sync
|
||||||
export const USER_STATE_POPULATE = 'USER_STATE_POPULATE';
|
export const USER_STATE_POPULATE = 'USER_STATE_POPULATE';
|
||||||
|
export const SYNC_FATAL_ERROR = 'SYNC_FATAL_ERROR';
|
||||||
|
|
|
@ -74,45 +74,57 @@ export function doPreferenceSet(
|
||||||
success: Function,
|
success: Function,
|
||||||
fail: Function
|
fail: Function
|
||||||
) {
|
) {
|
||||||
const preference = {
|
return (dispatch: Dispatch) => {
|
||||||
type: typeof value,
|
const preference = {
|
||||||
version,
|
type: typeof value,
|
||||||
value,
|
version,
|
||||||
};
|
value,
|
||||||
|
};
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
key,
|
key,
|
||||||
value: JSON.stringify(preference),
|
value: JSON.stringify(preference),
|
||||||
};
|
};
|
||||||
|
|
||||||
Lbry.preference_set(options)
|
Lbry.preference_set(options)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
success(preference);
|
success(preference);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
if (fail) {
|
dispatch({
|
||||||
fail();
|
type: ACTIONS.SYNC_FATAL_ERROR,
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
if (fail) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doPreferenceGet(key: string, success: Function, fail?: Function) {
|
export function doPreferenceGet(key: string, success: Function, fail?: Function) {
|
||||||
const options = {
|
return (dispatch: Dispatch) => {
|
||||||
key,
|
const options = {
|
||||||
|
key,
|
||||||
|
};
|
||||||
|
|
||||||
|
return Lbry.preference_get(options)
|
||||||
|
.then(result => {
|
||||||
|
if (result) {
|
||||||
|
const preference = result[key];
|
||||||
|
return success(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(null);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.SYNC_FATAL_ERROR,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (fail) {
|
||||||
|
fail(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return Lbry.preference_get(options)
|
|
||||||
.then(result => {
|
|
||||||
if (result) {
|
|
||||||
const preference = result[key];
|
|
||||||
return success(preference);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success(null);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
if (fail) {
|
|
||||||
fail(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ export const buildSharedStateMiddleware = (
|
||||||
if (!isEqual(oldShared, shared)) {
|
if (!isEqual(oldShared, shared)) {
|
||||||
// only update if the preference changed from last call in the same session
|
// only update if the preference changed from last call in the same session
|
||||||
oldShared = shared;
|
oldShared = shared;
|
||||||
doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION);
|
dispatch(doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sharedStateCb) {
|
if (sharedStateCb) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue