Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else if (_isMobx(storeUpdater)) {
// if it is a function asume it is MobX resources store
// TODO: pull out into a helper function. Same method used in the reducer
Object.entries(
_convertToJsonApiSpec(resourceType, resourcesById)
).forEach(([id, resource]) => {
if (!storeUpdater[resourceType]) {
storeUpdater[resourceType] = {};
}
storeUpdater[resourceType][id] = resource;
});
}
});
} else {
Object.entries(
jsonApiNormalize(payload)
).forEach(([resourceType, resourcesById]) => {
if (_isRedux(storeUpdater)) {
// if it is a function asume it is Redux dispatch
storeUpdater({
type: "MERGE_RESOURCES",
resourceType,
resourcesById
});
} else if (_isMobx(storeUpdater)) {
// TODO: pull out into a helper function. Same method used in the reducer
Object.entries(resourcesById).forEach(([id, resource]) => {
if (!storeUpdater[resourceType]) {
storeUpdater[resourceType] = {};
}
storeUpdater[resourceType][id] = resource;
});
updateResources(payload) {
// Create insert order index
let index = isGraphQl(payload)
? _createIndexForGraphQl(payload)
: _createIndexForJsonApi(payload);
const resourcesByType = {};
Object.entries(
isGraphQl(payload) ? graphQlNormalize(payload) : jsonApiNormalize(payload)
).forEach(([resourceType, resourcesById]) => {
const rById = isGraphQl(payload)
? toJsonApiSpec(resourceType, resourcesById)
: resourcesById;
resourcesByType[resourceType] = resourcesById;
});
this.actions.updateResources(this.mutator, resourcesByType, index);
}
.then((res) => {
const customer = build(normalize(res), 'customers', res.data.id);
// TODO temporary fix to handle multiple subscriptions
let sub = customer.subscriptions;
if (!Array.isArray(sub)) {
sub = [sub];
}
const subPlus = sub.reduce((acc, curr) => {
let a = acc;
if (curr.productName.includes('Plus')) {
a = curr;
}
return a;
}, {});
this._setSubscriptionData(subPlus);
return customer;
})
)
updateResources(payload) {
// Create insert order index
let index = isGraphQl(payload)
? _createIndexForGraphQl(payload)
: _createIndexForJsonApi(payload);
const resourcesByType = {};
Object.entries(
isGraphQl(payload) ? graphQlNormalize(payload) : jsonApiNormalize(payload)
).forEach(([resourceType, resourcesById]) => {
const rById = isGraphQl(payload)
? toJsonApiSpec(resourceType, resourcesById)
: resourcesById;
resourcesByType[resourceType] = resourcesById;
});
this.actions.updateResources(this.mutator, resourcesByType, index);
}
return function (dispatch) {
const normalized = normalize(data);
if (typeof normalized.categories !== 'undefined') {
Object.keys(normalized.categories).forEach((categoryId) => {
dispatch(storeCategory(normalized.categories[categoryId]));
});
}
if (typeof normalized.files !== 'undefined') {
Object.keys(normalized.files).forEach((fileId) => {
dispatch(storeFile(normalized.files[fileId]));
});
}
if (typeof normalized.recipes !== 'undefined') {
Object.keys(normalized.recipes).forEach((recipeId) => {
dispatch(storeRecipe(normalized.recipes[recipeId], normalized.images));
});
json => normalize(json, { endpoint: 'currentPageOperators' }),
)
export const fetchJob = requestFetch('JOB', api.v2.specs.getJobSpec, (json) =>
normalize(json, { camelizeKeys: false }),
)
json => normalize(json, { endpoint: 'currentPageJobRuns' }),
)
const _updateResourcesByStateManger = (spec, payload, storeUpdater) => {
Object.entries(
spec === GraphQL ? graphQlNormalize(payload) : jsonApiNormalize(payload)
).forEach(([resourceType, resourcesById]) => {
const rById = spec === GraphQL
? toJsonApiSpec(resourceType, resourcesById)
: resourcesById;
if (isRedux(storeUpdater)) {
_updateResourcesRedux(storeUpdater, resourceType, rById);
} else if (isMobx(storeUpdater)) {
_updateResourcesMobx(storeUpdater, resourceType, rById);
} else if (isVuex(storeUpdater)) {
_updateResourcesVuex(storeUpdater, resourceType, rById);
} else if (isSetState(storeUpdater)) {
_updateResourcesSetState(storeUpdater, resourceType, rById);
}
});
};