1.6.3 • Published 5 years ago

immutable-extras v1.6.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

immutable-extras

Simple extensions for the Immutable.js library

Install

npm install --save immutable-extras
yarn add immutable-extras

Usage

import Immutable from 'immutable';
import 'immutable-extras';

const someList = Immutable.List([
  Immutable.Map({
    id: 5,
    name: 'a'
  }),
  Immutable.Map({
    id: 15,
    name: 'b'
  }),
  Immutable.Map({
    id: 5,
    name: 'c'
  }),
  Immutable.Map({
    id: 5,
    name: 'a'
  }),
]);

const uniqueList = someList.unique('id');
// uniqueList ->
//    [ { id: 5, name: 'a' }, { id: 15, name: 'b' } ]

const mapped = someList.mapOn(v => v.name);
// mapped ->
//    {
//      a: { id: 5, name: 'a' },
//      b: { id: 15, name: 'b' },
//      c: { id: 5, name: 'c' },
//    }

const sortedList = Immutable.List([ 'bd', 'ab', 'c', 'bb']).multiSort(
  (a, b) => b.length - a.length,
  (a, b) => a.localeCompare(b),
)
// sortedList ->
//    ["ab", "bb", "bd", "c"]

const groupedList = Immutable.List([ '1', '2', '3', '4' ]).group(2)
// groupedList ->
//    [ [ '1', '2' ], [ '3', '4' ]]

const safeSetMap = Immutable.fromJS({ a: undefined }).safeSetIn({ a: { b: 'c' }})
// safeSetMap ->
//   {
//     a: {
//       b: 'c'
//     }
//   }

class TestClass {}
const classList1 = Immutable.List([ { a: 1 } ]).class(TestClass);
const classList2 = Immutable.List.of({ a: 1 }).class(TestClass);
// classList1 ->
//   Immutable.List([ TestClass(...) ])
// classList2 ->
//   Immutable.List([ TestClass(...) ])
1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago