@@ -7,28 +7,29 @@ as lazy evaluation. This provides a lazy `Sequence`, allowing efficient chaining
7
7
of sequence methods like ` map ` and ` filter ` without creating intermediate
8
8
representations.
9
9
10
- ` immutable-data ` implements a sparse ` Vector ` , ` Map ` , ` OrderedMap ` , ` Set ` and
11
- ` Range ` by using lazy sequences and hash maps tries. They achieve acceptable
12
- performance by using structural sharing and minimizing the need to copy data.
10
+ ` immutable ` provides ` Sequence ` , ` Range ` , ` Repeat ` , ` Map ` , ` OrderedMap ` , ` Set `
11
+ and a sparse ` Vector ` by using lazy sequences and [ hash maps tries] ( http://en.wikipedia.org/wiki/Hash_array_mapped_trie ) .
12
+ They achieve efficiency by using structural sharing and minimizing the need to
13
+ copy or cache data.
13
14
14
15
15
16
Getting started
16
17
---------------
17
18
18
- Install immutable-data using npm
19
+ Install ` immutable ` using npm
19
20
20
21
``` shell
21
- npm install immutable-data
22
+ npm install immutable
22
23
```
23
24
24
25
Then require it into any module.
25
26
26
27
``` javascript
27
- var Immutable = require (' immutable-data ' );
28
+ var Immutable = require (' immutable' );
28
29
var map = Immutable .Map ({a: 1 , b: 2 , c: 3 });
29
30
```
30
31
31
- To use ` immutable-data ` from a browser, try [ Browserify] ( http://browserify.org/ ) .
32
+ To use ` immutable ` from a browser, try [ Browserify] ( http://browserify.org/ ) .
32
33
33
34
34
35
Use these Immutable collections and sequences as you would use native
@@ -39,7 +40,7 @@ advantage of type generics, error detection, and auto-complete in your IDE.
39
40
require the full file path)
40
41
41
42
``` javascript
42
- import Immutable = require(' ./node_modules/immutable-data /dist/Immutable' );
43
+ import Immutable = require(' ./node_modules/immutable/dist/Immutable' );
43
44
var map: Immutable .Map < string, number> ;
44
45
map = Immutable .Map ({a: 1 , b: 2 , c: 3 });
45
46
```
@@ -61,11 +62,11 @@ to changes throughout the model is a dead-end and new data can only ever be
61
62
passed from above.
62
63
63
64
This model of data flow aligns well with the architecture of [ React] ( http://facebook.github.io/react/ )
64
- and especially an application designed using the ideas of [ Flux] ( http://facebook.github.io/react/docs/flux-overview.html ) .
65
+ and especially well with an application designed using the ideas of [ Flux] ( http://facebook.github.io/react/docs/flux-overview.html ) .
65
66
66
67
When data is passed from above rather than being subscribed to, and you're only
67
68
interested in doing work when something has changed, you can use equality.
68
- ` immutable-data ` always returns itself when a mutation results in an identical
69
+ ` immutable ` always returns itself when a mutation results in an identical
69
70
collection, allowing for using ` === ` equality to determine if something
70
71
has changed.
71
72
@@ -89,7 +90,7 @@ var clone = map1;
89
90
JavaScript-first API
90
91
--------------------
91
92
92
- While ` immutable-data ` is inspired by Clojure, Haskell and other functional
93
+ While ` immutable ` is inspired by Clojure, Haskell and other functional
93
94
programming environments, it's designed to bring these powerful concepts to
94
95
JavaScript, and therefore has an Object-Oriented API that closely mirrors that
95
96
of [ Array] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array ) ,
@@ -115,15 +116,12 @@ Almost all of the methods on `Array` will be found in similar form on
115
116
found on ` Immutable.Set ` , including sequence operations like ` forEach ` and ` map ` .
116
117
117
118
``` javascript
118
- > var alpha = Immutable .Map ({a: 1 , b: 2 , c: 3 , d: 4 });
119
- > alpha .map ((v , k ) => k .toUpperCase ()).forEach (k => console .log (k));
120
- A
121
- B
122
- C
123
- D
119
+ var alpha = Immutable .Map ({a: 1 , b: 2 , c: 3 , d: 4 });
120
+ alpha .map ((v , k ) => k .toUpperCase ()).join ();
121
+ // 'A,B,C,D'
124
122
```
125
123
126
- Designed to inter-operate with your existing JavaScript, ` immutable-data `
124
+ Designed to inter-operate with your existing JavaScript, ` immutable `
127
125
accepts plain JavaScript Array and Objects anywhere a method expects a
128
126
` Sequence ` with no performance penalty.
129
127
@@ -135,7 +133,19 @@ var map3 = map1.merge(map2, obj);
135
133
// Map { a: 20, b: 2, c: 10, d: 1000, t: 30, o: 2000, g: 300 }
136
134
```
137
135
138
- All ` immutable-data ` Sequences can be converted to plain JavaScript Arrays and
136
+ This is possible because ` immutible ` can treat any JavaScript Array or Object
137
+ as a Sequence. You can take advantage of this in order to get sophisticated
138
+ sequence methods on JavaScript Objects, which otherwise have a very sparse
139
+ native API. Because Sequences evaluate lazily and do not cache intermediate
140
+ results, these operations are extremely efficient.
141
+
142
+ ``` javascript
143
+ var myObject = {a: 1 ,b: 2 ,c: 3 };
144
+ Sequence (myObject).map (x => x * x).toObject ();
145
+ // { a: 1, b: 4, c: 9 }
146
+ ```
147
+
148
+ All ` immutable ` Sequences can be converted to plain JavaScript Arrays and
139
149
Objects shallowly with ` toArray() ` and ` toObject() ` or deeply with ` toJSON() ` ,
140
150
allowing ` JSON.stringify ` to work automatically.
141
151
@@ -151,7 +161,7 @@ JSON.stringify(deep) // '{"a":1,"b":2,"c":[3,4,5]}'
151
161
Nested Structures
152
162
-----------------
153
163
154
- The collections in ` immutable-data ` are intended to be nested, allowing for deep
164
+ The collections in ` immutable ` are intended to be nested, allowing for deep
155
165
trees of data, similar to JSON.
156
166
157
167
``` javascript
@@ -179,7 +189,7 @@ Lazy Sequences
179
189
--------------
180
190
181
191
The ` Sequence ` is a set of (key, value) entries which can be iterated, and
182
- is the base class for all collections in ` immutable-data ` , allowing them to make
192
+ is the base class for all collections in ` immutable ` , allowing them to make
183
193
use of all the Sequence methods (such as ` map ` and ` filter ` ).
184
194
185
195
** Sequences are immutable** — Once a sequence is created, it cannot be
@@ -225,7 +235,7 @@ not always be well defined, as is the case for the `Map`.
225
235
Equality treats Collections as Data
226
236
-----------------------------------
227
237
228
- ` immutable-data ` provides equality which treats immutable data structures as
238
+ ` immutable ` provides equality which treats immutable data structures as
229
239
pure data, performing a deep equality check if necessary.
230
240
231
241
``` javascript
@@ -252,9 +262,9 @@ Batching Mutations
252
262
253
263
There is a performance penalty paid every time you create a new immutable object
254
264
via applying a mutation. If you need to apply a series of mutations
255
- ` immutable-data ` gives you the ability to create a temporary mutable copy of a
265
+ ` immutable ` gives you the ability to create a temporary mutable copy of a
256
266
collection and applying a batch of mutations in a highly performant manner by
257
- using ` withMutations ` . In fact, this is exactly how ` immutable-data ` applies
267
+ using ` withMutations ` . In fact, this is exactly how ` immutable ` applies
258
268
complex mutations itself.
259
269
260
270
As an example, this results in the creation of 2, not 4, new immutable Vectors.
@@ -278,4 +288,15 @@ All documentation is contained within the type definition file, [Immutable.d.ts]
278
288
Contribution
279
289
------------
280
290
281
- Taking pull requests! Or, use Github issues for requests.
291
+ Or, use [ Github issues] ( https://github.com/leebyron/immutable-js/issues ) for requests.
292
+
293
+ Taking [ pull requests] ( https://help.github.com/articles/creating-a-pull-request ) !
294
+ Before submitting your diff, please add a test to the [ __ tests__ ] ( ./__tests__ )
295
+ directory and build and run all tests by running ` grunt ` .
296
+
297
+
298
+ Thanks
299
+ ------
300
+
301
+ [ Hugh Jackson] ( https://github.com/hughfdjackson/ ) , for providing the npm package
302
+ name. If you're looking for his unsupported package, see [ v1.4.1] ( https://www.npmjs.org/package/immutable/1.4.1 ) .
0 commit comments