Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bun add immutable
Then require it into any module.

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const map1 = Map({ a: 1, b: 2, c: 3 });
const map2 = map1.set('b', 50);
map1.get('b') + ' vs. ' + map2.get('b'); // 2 vs. 50
Expand Down Expand Up @@ -135,7 +135,7 @@ lib. Include either `"target": "es2015"` or `"lib": "es2015"` in your
`tsc` command.

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const map1 = Map({ a: 1, b: 2, c: 3 });
const map2 = map1.set('b', 50);
map1.get('b') + ' vs. ' + map2.get('b'); // 2 vs. 50
Expand Down Expand Up @@ -184,7 +184,7 @@ treat Immutable.js collections as values, it's important to use the
instead of the `===` operator which determines object _reference identity_.

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const map1 = Map({ a: 1, b: 2, c: 3 });
const map2 = Map({ a: 1, b: 2, c: 3 });
map1.equals(map2); // true
Expand All @@ -200,7 +200,7 @@ potentially be more costly. The `===` equality check is also used internally by
`Immutable.is` and `.equals()` as a performance optimization.

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const map1 = Map({ a: 1, b: 2, c: 3 });
const map2 = map1.set('b', 2); // Set to same value
map1 === map2; // true
Expand All @@ -212,7 +212,7 @@ than the object itself, this results in memory savings and a potential boost in
execution speed for programs which rely on copies (such as an undo-stack).

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const map = Map({ a: 1, b: 2, c: 3 });
const mapCopy = map; // Look, "copies" are free!
```
Expand All @@ -238,7 +238,7 @@ immutable collection. Methods which return new arrays, like `slice` or `concat`,
instead return new immutable collections.

```js
const { List } = require('immutable');
import { List } from 'immutable';
const list1 = List([1, 2]);
const list2 = list1.push(3, 4, 5);
const list3 = list2.unshift(0);
Expand All @@ -256,7 +256,7 @@ found on `Immutable.Set`, including collection operations like `forEach()`
and `map()`.

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const alpha = Map({ a: 1, b: 2, c: 3, d: 4 });
alpha.map((v, k) => k.toUpperCase()).join();
// 'A,B,C,D'
Expand All @@ -269,7 +269,7 @@ accepts plain JavaScript Arrays and Objects anywhere a method expects a
`Collection`.

```js
const { Map, List } = require('immutable');
import { Map, List } from 'immutable';
const map1 = Map({ a: 1, b: 2, c: 3, d: 4 });
const map2 = Map({ c: 10, a: 20, t: 30 });
const obj = { d: 100, o: 200, g: 300 };
Expand All @@ -289,7 +289,7 @@ native API. Because Seq evaluates lazily and does not cache intermediate
results, these operations can be extremely efficient.

```js
const { Seq } = require('immutable');
import { Seq } from 'immutable';
const myObject = { a: 1, b: 2, c: 3 };
Seq(myObject)
.map((x) => x * x)
Expand All @@ -302,7 +302,7 @@ JavaScript Object properties are always strings, even if written in a quote-less
shorthand, while Immutable Maps accept keys of any type.

```js
const { fromJS } = require('immutable');
import { fromJS } from 'immutable';

const obj = { 1: 'one' };
console.log(Object.keys(obj)); // [ "1" ]
Expand All @@ -325,7 +325,7 @@ to `JSON.stringify` directly. They also respect the custom `toJSON()` methods of
nested objects.

```js
const { Map, List } = require('immutable');
import { Map, List } from 'immutable';
const deep = Map({ a: 1, b: 2, c: List([3, 4, 5]) });
console.log(deep.toObject()); // { a: 1, b: 2, c: List [ 3, 4, 5 ] }
console.log(deep.toArray()); // [ 1, 2, List [ 3, 4, 5 ] ]
Expand Down Expand Up @@ -357,7 +357,7 @@ All Immutable.js collections are [Iterable][iterators], which allows them to be
used anywhere an Iterable is expected, such as when spreading into an Array.

```js
const { List } = require('immutable');
import { List } from 'immutable';
const aList = List([1, 2, 3]);
const anArray = [0, ...aList, 4, 5]; // [ 0, 1, 2, 3, 4, 5 ]
```
Expand All @@ -376,7 +376,7 @@ The collections in Immutable.js are intended to be nested, allowing for deep
trees of data, similar to JSON.

```js
const { fromJS } = require('immutable');
import { fromJS } from 'immutable';
const nested = fromJS({ a: { b: { c: [3, 4, 5] } } });
// Map { a: Map { b: Map { c: List [ 3, 4, 5 ] } } }
```
Expand All @@ -386,7 +386,7 @@ most useful are `mergeDeep`, `getIn`, `setIn`, and `updateIn`, found on `List`,
`Map` and `OrderedMap`.

```js
const { fromJS } = require('immutable');
import { fromJS } from 'immutable';
const nested = fromJS({ a: { b: { c: [3, 4, 5] } } });

const nested2 = nested.mergeDeep({ a: { b: { d: 6 } } });
Expand Down Expand Up @@ -419,7 +419,7 @@ const obj1 = { a: 1, b: 2, c: 3 };
const obj2 = { a: 1, b: 2, c: 3 };
obj1 !== obj2; // two different instances are always not equal with ===

const { Map, is } = require('immutable');
import { Map, is } from 'immutable';
const map1 = Map({ a: 1, b: 2, c: 3 });
const map2 = Map({ a: 1, b: 2, c: 3 });
map1 !== map2; // two different instances are not reference-equal
Expand All @@ -431,7 +431,7 @@ Value equality allows Immutable.js collections to be used as keys in Maps or
values in Sets, and retrieved with different but equivalent collections:

```js
const { Map, Set } = require('immutable');
import { Map, Set } from 'immutable';
const map1 = Map({ a: 1, b: 2, c: 3 });
const map2 = Map({ a: 1, b: 2, c: 3 });
const set = Set().add(map1);
Expand Down Expand Up @@ -469,7 +469,7 @@ change in _value_ occurred, to allow for efficient _reference equality_ checking
to quickly determine if no change occurred.

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const originalMap = Map({ a: 1, b: 2, c: 3 });
const updatedMap = originalMap.set('b', 2);
updatedMap === originalMap; // No-op .set() returned the original reference.
Expand All @@ -480,7 +480,7 @@ of these operations occur independently, so two similar updates will not return
the same reference:

```js
const { Map } = require('immutable');
import { Map } from 'immutable';
const originalMap = Map({ a: 1, b: 2, c: 3 });
const updatedMap = originalMap.set('b', 1000);
// New instance, leaving the original immutable.
Expand Down Expand Up @@ -512,7 +512,7 @@ As an example, building `list2` results in the creation of 1, not 3, new
immutable Lists.

```js
const { List } = require('immutable');
import { List } from 'immutable';
const list1 = List([1, 2, 3]);
const list2 = list1.withMutations(function (list) {
list.push(4).push(5).push(6);
Expand Down Expand Up @@ -550,7 +550,7 @@ For example, the following performs no work, because the resulting
`Seq`'s values are never iterated:

```js
const { Seq } = require('immutable');
import { Seq } from 'immutable';
const oddSquares = Seq([1, 2, 3, 4, 5, 6, 7, 8])
.filter((x) => x % 2 !== 0)
.map((x) => x * x);
Expand All @@ -567,7 +567,7 @@ oddSquares.get(1); // 9
Any collection can be converted to a lazy Seq with `Seq()`.

```js
const { Map, Seq } = require('immutable');
import { Map, Seq } from 'immutable';
const map = Map({ a: 1, b: 2, c: 3 });
const lazySeq = Seq(map);
```
Expand All @@ -587,7 +587,7 @@ As well as expressing logic that would otherwise seem memory or time
limited, for example `Range` is a special kind of Lazy sequence.

```js
const { Range } = require('immutable');
import { Range } from 'immutable';
Range(1, Infinity)
.skip(1000)
.map((n) => -n)
Expand Down
28 changes: 14 additions & 14 deletions type-definitions/immutable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ declare namespace Immutable {
* a collection of other sets.
*
* ```js
* const { Set } = require('immutable')
* import { Set } from 'immutable'
* const intersected = Set.intersect([
* Set([ 'a', 'b', 'c' ])
* Set([ 'c', 'a', 't' ])
Expand All @@ -1387,7 +1387,7 @@ declare namespace Immutable {
* collection of other sets.
*
* ```js
* const { Set } = require('immutable')
* import { Set } from 'immutable'
* const unioned = Set.union([
* Set([ 'a', 'b', 'c' ])
* Set([ 'c', 'a', 't' ])
Expand Down Expand Up @@ -2029,7 +2029,7 @@ declare namespace Immutable {
* `new` keyword during construction.
*
* ```js
* const { Range } = require('immutable')
* import { Range } from 'immutable'
* Range(10, 15) // [ 10, 11, 12, 13, 14 ]
* Range(10, 30, 5) // [ 10, 15, 20, 25 ]
* Range(30, 10, 5) // [ 30, 25, 20, 15 ]
Expand All @@ -2050,7 +2050,7 @@ declare namespace Immutable {
* `new` keyword during construction.
*
* ```js
* const { Repeat } = require('immutable')
* import { Repeat } from 'immutable'
* Repeat('foo') // [ 'foo', 'foo', 'foo', ... ]
* Repeat('bar', 4) // [ 'bar', 'bar', 'bar', 'bar' ]
* ```
Expand All @@ -2065,7 +2065,7 @@ declare namespace Immutable {
* create Record instances.
*
* ```js
* const { Record } = require('immutable')
* import { Record } from 'immutable'
* const ABRecord = Record({ a: 1, b: 2 })
* const myRecord = ABRecord({ b: 3 })
* ```
Expand Down Expand Up @@ -2229,7 +2229,7 @@ declare namespace Immutable {
* method. If one was not provided, the string "Record" is returned.
*
* ```js
* const { Record } = require('immutable')
* import { Record } from 'immutable'
* const Person = Record({
* name: null
* }, 'Person')
Expand Down Expand Up @@ -2449,7 +2449,7 @@ declare namespace Immutable {
* `Seq`'s values are never iterated:
*
* ```js
* const { Seq } = require('immutable')
* import { Seq } from 'immutable'
* const oddSquares = Seq([ 1, 2, 3, 4, 5, 6, 7, 8 ])
* .filter(x => x % 2 !== 0)
* .map(x => x * x)
Expand Down Expand Up @@ -2557,7 +2557,7 @@ declare namespace Immutable {
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* import { Seq } from 'immutable'
* Seq.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
* // Seq { "a": 10, "b": 20 }
* ```
Expand Down Expand Up @@ -2691,7 +2691,7 @@ declare namespace Immutable {
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* import { Seq } from 'immutable'
* Seq.Indexed([ 1, 2 ]).map(x => 10 * x)
* // Seq [ 10, 20 ]
* ```
Expand Down Expand Up @@ -2994,7 +2994,7 @@ declare namespace Immutable {
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* import { Seq } from 'immutable'
* Seq([ 1, 2 ]).map(x => 10 * x)
* // Seq [ 10, 20 ]
* ```
Expand All @@ -3012,7 +3012,7 @@ declare namespace Immutable {
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* import { Seq } from 'immutable'
* Seq([ 1, 2 ]).map(x => 10 * x)
* // Seq [ 10, 20 ]
* ```
Expand Down Expand Up @@ -3171,7 +3171,7 @@ declare namespace Immutable {
* `mapper` function.
*
* ```js
* const { Collection } = require('immutable')
* import { Collection } from 'immutable'
* Collection.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
* // Seq { "a": 10, "b": 20 }
* ```
Expand Down Expand Up @@ -3465,7 +3465,7 @@ declare namespace Immutable {
* `mapper` function.
*
* ```js
* const { Collection } = require('immutable')
* import { Collection } from 'immutable'
* Collection.Indexed([1,2]).map(x => 10 * x)
* // Seq [ 1, 2 ]
* ```
Expand Down Expand Up @@ -3530,7 +3530,7 @@ declare namespace Immutable {
* the value as both the first and second arguments to the provided function.
*
* ```js
* const { Collection } = require('immutable')
* import { Collection } from 'immutable'
* const seq = Collection.Set([ 'A', 'B', 'C' ])
* // Seq { "A", "B", "C" }
* seq.forEach((v, k) =>
Expand Down
Loading