How to use the immutability-helper.newContext 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 DefinitelyTyped / DefinitelyTyped / immutability-helper / immutability-helper-tests.ts View on Github external
}

namespace TestArrayUpdate {
  update([], {
    foo: {
      bar: { $set: 'baz' }
    }
  });
}

namespace TestExtend {
  update.extend('$command', (specValue, originalValue) => originalValue);
}

namespace TestNewContext {
  update.newContext().extend('$command', (specValue, originalValue) => originalValue);
  newContext().extend('$command', (specValue, originalValue) => originalValue);

  // This shouldn't compile, but we can't test negatives.
  // newContext().newContext();
}

namespace TestFromReactDocs {
  // These are copied from https://facebook.github.io/react/docs/update.html
  let initialArray = [1, 2, 3];
  let newArray = update(initialArray, { $push: [4] }); // => [1, 2, 3, 4]

  let collection = [1, 2, { a: [12, 17, 15] }];
  let newCollection = update(collection, { 2: { a: { $splice: [[1, 1, 13, 14]] } } });
  // => [1, 2, {a: [12, 13, 14, 15]}]

  let obj = { a: 5, b: 3 };
github seansfkelley / react-layered-chart / src / connected / flux / reducer.ts View on Github external
import * as _ from 'lodash';
import { newContext } from 'immutability-helper';

const update = newContext();

update.extend('$assign', (spec, object) => _.assign({}, object, spec));

import { ActionType, Action } from './atomicActions';
import { ChartState, DEFAULT_CHART_STATE, invalidLoader } from '../model/state';
import { DEFAULT_Y_DOMAIN } from '../model/constants';
import { objectWithKeys, replaceValuesWithConstant, objectWithKeysFromObject } from './reducerUtils';

export default function(state: ChartState, action: Action): ChartState {
  if (state === undefined) {
    return DEFAULT_CHART_STATE;
  }

  switch (action.type) {
    case ActionType.SET_SERIES_IDS: {
      const seriesIds = action.payload;

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