How to use the immutability-helper.extend function in immutability-helper

To help you get started, we’ve selected a few immutability-helper 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 Azure / pcs-remote-monitoring-webui / src / components / pages / dashboard / panels / telemetry / telemetryChart.js View on Github external
import React, { Component } from 'react';
import update from 'immutability-helper';
import { Observable } from 'rxjs';
import 'tsiclient';

import { joinClasses } from 'utilities';

import './telemetryChart.css';
// TODO: find a way to import without the relative path
import '../../../../../../node_modules/tsiclient/tsiclient.css';

const maxDatums = 100; // Max telemetry messages for the telemetry graph

// Extend the immutability helper to include object autovivification
update.extend('$auto', (val, obj) => update(obj || {}, val));

/**
 *  A helper function containing the logic to convert a getTelemetry response
 *  object into the chart object structure.
 *
 * @param getCurrentTelemetry A function that returns an object of formatted telemetry messages
 * @param items An array of telemetry messages from the getTelemetry response object
 */
export const transformTelemetryResponse = getCurrentTelemetry => items =>
  Observable.from(items)
    .flatMap(({ data, deviceId, time }) =>
      Observable.from(Object.keys(data))
        .filter(metric => metric.indexOf('Unit') < 0)
        .map(metric => ({ metric, deviceId, time, data: data[metric] }))
    )
    .reduce(
github Automattic / wp-calypso / client / lib / cart-values / index.js View on Github external
/**
 * Internal dependencies
 */
import {
	hasRenewalItem,
	hasFreeTrial,
	hasProduct,
	hasDomainRegistration,
	hasPlan,
} from './cart-items';
import { isCredits, isDomainRedemption, whitelistAttributes } from 'lib/products-values';
import { detectWebPaymentMethod } from 'lib/web-payment';

// Auto-vivification from https://github.com/kolodny/immutability-helper#autovivification
extendImmutabilityHelper( '$auto', function( value, object ) {
	return object ? update( object, value ) : update( {}, value );
} );

const PAYMENT_METHODS = {
	alipay: 'WPCOM_Billing_Stripe_Source_Alipay',
	bancontact: 'WPCOM_Billing_Stripe_Source_Bancontact',
	'credit-card': 'WPCOM_Billing_MoneyPress_Paygate',
	ebanx: 'WPCOM_Billing_Ebanx',
	eps: 'WPCOM_Billing_Stripe_Source_Eps',
	giropay: 'WPCOM_Billing_Stripe_Source_Giropay',
	ideal: 'WPCOM_Billing_Stripe_Source_Ideal',
	netbanking: 'WPCOM_Billing_Dlocal_Redirect_India_Netbanking',
	paypal: 'WPCOM_Billing_PayPal_Express',
	p24: 'WPCOM_Billing_Stripe_Source_P24',
	'brazil-tef': 'WPCOM_Billing_Ebanx_Redirect_Brazil_Tef',
	wechat: 'WPCOM_Billing_Stripe_Source_Wechat',
github stackscz / re-app / src / utils / immutabilityHelper.js View on Github external
import update from 'immutability-helper';

update.extend('$delete', (value, original) => {
	const result = update(original, { [value]: { $set: undefined } });
	delete result[value];
	return result;
});

export default update;
github Azure / pcs-remote-monitoring-webui / src / components / pages / devices / flyouts / deviceJobs / deviceJobProperties.js View on Github external
FormSection,
  Indicator,
  PropertyGrid as Grid,
  PropertyGridBody as GridBody,
  PropertyGridHeader as GridHeader,
  PropertyRow as Row,
  PropertyCell as Cell,
  SectionDesc,
  SectionHeader,
  SummaryBody,
  SummaryCount,
  SummarySection,
  Svg
} from 'components/shared';

update.extend('$autoArray', (val, obj) => update(obj || [], val));

const isNumeric = value => typeof value === 'number';
const isAlphaNumericRegex = /^[a-zA-Z0-9]*$/;
const nonAlphaNumeric = x => !x.match(isAlphaNumericRegex);

export const propertyJobConstants = {
  firmware: 'Firmware',
  multipleValues: 'Multiple',
  stringType: 'Text',
  numberType: 'Number'
};

const initialState = {
  isPending: false,
  error: undefined,
  successCount: 0,
github thinger-io / Mobile-App / src / reducers / selectedAttributes.js View on Github external
export default function selectedAttributes(
  state: SelectedAttributesState = initialState,
  action: AttributeAction
) {
  update.extend("$auto", function(value, object) {
    return object ? update(object, value) : update({}, value);
  });
  switch (action.type) {
    case "ATTRIBUTE_SELECT":
      return update(state, {
        [action.chart]: { $auto: { [action.attribute]: { $set: true } } }
      });
    case "ATTRIBUTE_DESELECT":
      return update(state, {
        [action.chart]: { $auto: { [action.attribute]: { $set: false } } }
      });
    case "ATTRIBUTE_REMOVE_ALL":
      return initialState;
    default:
      return state;
  }
github smpio / kubernator / src / utils / immutability-helper.js View on Github external
import update from 'immutability-helper';
import {
  arrayDelete,
  arrayPushUnique,
  objectDelete,
} from '@uqee/immutability-helper-x';

update.extend('$pop', arrayDelete);
update.extend('$pushuniq', arrayPushUnique);
update.extend('$del', objectDelete);
github Altinn / altinn-studio / src / react-apps / applications / service-development / src / sharedResources / appCluster / appClusterReducer.ts View on Github external
const newDeploymentListItem: IEnvironmentItem = {
    env: params.env,
    items: params.result,
    getStatus: {
      error: null,
      success: true,
    },
  };

  newState.push(newDeploymentListItem);

  return newState;
});

update.extend('$updateEnvFailed', (params: any, original: any) => {
  const newState = original.filter((elem: any) => elem.env !== params.env );

  const newDeploymentListItem: IEnvironmentItem = {
    env: params.env,
    items: [],
    getStatus: {
      error: params.error.message,
      success: false,
    },
  };

  newState.push(newDeploymentListItem);

  return newState;
});
github Coding / WebIDE-Frontend / app / utils / immutableUpdate.js View on Github external
return original
}

update.extend('$removeValue', removeValue)
update.extend('$without', removeValue)

const removeKey = (keysToRemove, original) => {
  if (!_.isArray(original) && !_.isObject(original)) return original
  if (!_.isArray(keysToRemove)) keysToRemove = [keysToRemove]
  return _.reduce(original, (result, value, key) => {
    if (!keysToRemove.includes(key)) result[key] = value
    return result
  }, _.isArray(original) ? [] : {})
}

update.extend('$removeKey', removeKey)
update.extend('$delete', removeKey)

update.extend('$map', (fn, original) => {
  if (_.isArray(original)) return _.map(original, fn)
  if (_.isObject(original)) return _.mapValues(original, fn)
  return original
})

export default update
github Altinn / altinn-studio / src / Altinn.Apps / AppFrontend / react / altinn-app-frontend / src / features / form / data / formDataReducer.ts View on Github external
isSubmitting: boolean;
  isSaving: boolean;
  hasSubmitted: boolean;
}

const initialState: IFormDataState = {
  formData: {},
  error: null,
  responseInstance: null,
  unsavedChanges: false,
  isSubmitting: false,
  isSaving: false,
  hasSubmitted: false,
};

Immutable.extend('$setField', (params: any, original: IFormData) => {
  original[params.field] = params.data;
  return original;
});

const FormDataReducer: Reducer = (
  state: IFormDataState = initialState,
  action?: Action,
): IFormDataState => {
  if (!action) {
    return state;
  }

  switch (action.type) {
    case actionTypes.FETCH_FORM_DATA_FULFILLED: {
      const { formData } = action as IFetchFormDataFulfilled;
      return Immutable(state, {
github smpio / kubernator / src / utils / immutability-helper.js View on Github external
import update from 'immutability-helper';
import {
  arrayDelete,
  arrayPushUnique,
  objectDelete,
} from '@uqee/immutability-helper-x';

update.extend('$pop', arrayDelete);
update.extend('$pushuniq', arrayPushUnique);
update.extend('$del', objectDelete);

immutability-helper

mutate a copy of data without changing the original source

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis