How to use json-api-normalizer - 9 common examples

To help you get started, we’ve selected a few json-api-normalizer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blue-chip-js / blue-chip / src / actions.js View on Github external
} 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;
        });
github blue-chip-js / blue-chip / dist / bundle.esm.js View on Github external
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);
  }
github ghostery / ghostery-extension / src / classes / Account.js View on Github external
.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;
			})
	)
github blue-chip-js / blue-chip / src / actions / Actions.js View on Github external
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);
  }
github contentacms / contenta_react / src / actions / api.js View on Github external
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));
      });
github smartcontractkit / chainlink / operator_ui / src / actionCreators.ts View on Github external
export const fetchJob = requestFetch('JOB', api.v2.specs.getJobSpec, (json) =>
  normalize(json, { camelizeKeys: false }),
)
github smartcontractkit / chainlink / explorer / client / src / actions / jobRuns.ts View on Github external
  json => normalize(json, { endpoint: 'currentPageJobRuns' }),
)
github blue-chip-js / blue-chip / src / actions / updateResources.js View on Github external
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);
    }
  });
};

json-api-normalizer

JSON API response normalizer

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis

Popular json-api-normalizer functions