8000 Improve asImmutable() docs (#1415) · immutable-js/immutable-js@97a33d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97a33d2

Browse files
authored
Improve asImmutable() docs (#1415)
Misleading to say it always results itself (it doesn't) and encourages use of withMutations when possible. Closes #1413
1 parent 0d34c76 commit 97a33d2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

type-definitions/Immutable.d.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,14 +1280,18 @@ declare module Immutable {
12801280
* a mutable copy of this collection. Mutable copies *always* return `this`,
12811281
* and thus shouldn't be used for equality. Your function should never return
12821282
* a mutable copy of a collection, only use it internally to create a new
1283-
* collection. If possible, use `withMutations` as it provides an easier to
1284-
* use API.
1283+
* collection.
1284+
*
1285+
* If possible, use `withMutations` to work with temporary mutable copies as
1286+
* it provides an easier to use API and considers many common optimizations.
12851287
*
12861288
* Note: if the collection is already mutable, `asMutable` returns itself.
12871289
*
12881290
* Note: Not all methods can be used on a mutable collection or within
12891291
* `withMutations`! Read the documentation for each method to see if it
12901292
* is safe to use in `withMutations`.
1293+
*
1294+
* @see `Map#asImmutable`
12911295
*/
12921296
asMutable(): this;
12931297

@@ -1301,8 +1305,15 @@ declare module Immutable {
13011305

13021306
/**
13031307
* The yin to `asMutable`'s yang. Because it applies to mutable collections,
1304-
* this operation is *mutable* and returns itself. Once performed, the mutable
1305-
* copy has become immutable and can be safely returned from a function.
1308+
* this operation is *mutable* and may return itself (though may not
1309+
* return itself, i.e. if the result is an empty collection). Once
1310+
* performed, the original mutable copy must no longer be mutated since it
1311+
* may be the immutable result.
1312+
*
1313+
* If possible, use `withMutations` to work with temporary mutable copies as
1314+
* it provides an easier to use API and considers many common optimizations.
1315+
*
1316+
* @see `Map#asMutable`
13061317
*/
13071318
asImmutable(): this;
13081319

0 commit comments

Comments
 (0)
0