JSPM

immutable-custom-merge

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q23958F
  • License MIT

Custom deep merging of Immutable data structures

Package Exports

  • immutable-custom-merge

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (immutable-custom-merge) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm version Build Status Coverage Status

immutable-custom-merge

Allows deep merging of Immutable objects with custom merging strategy fine-tuned per property.

import {fromJS} from 'immutable'
import merge from 'immutable-custom-merge'

const object1 = fromJS({
  a: [1, 2, 3],
  b: {
    c: [1, 2, 3],
    d: 4,
    e: 5
  },
  c: [1, 2, 3]
})

const object2 = fromJS({
  a: [3, 4],
  b: {
    c: [3, 4],
    d: 8,
    e: 6
  },
  c: [3, 4]
})

// defines how properties should be merged in case of collisions
const mergeSchema = {
  a: 'append',
  b: {
    c: 'union',
    e: (a, b) => a + b
  }
}

const result = merge(object1, object2, mergeSchema)
// resulted object:
{
  a: [1, 2, 3, 3, 4], //colliding arrays were appended
  b: {
    c: [1, 2, 3, 4],  // union of items
    d: 8,             // no rule for property means later overrides former
    e: 11             // custom function to solve collisions
  },
  c: [3, 4, 3]        // no rule - default Immutable merge
}