Skip to content

Commit 79280d4

Browse files
committed
Update docs on use of Records and avoiding new
1 parent c690ca8 commit 79280d4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

type-definitions/Immutable.d.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ declare module Immutable {
21932193
* ```js
21942194
* const { Record } = require('immutable')
21952195
* const ABRecord = Record({ a: 1, b: 2 })
2196-
* const myRecord = new ABRecord({ b: 3 })
2196+
* const myRecord = ABRecord({ b: 3 })
21972197
* ```
21982198
*
21992199
* Records always have a value for the keys they define. `remove`ing a key
@@ -2214,7 +2214,7 @@ declare module Immutable {
22142214
* ignored for this record.
22152215
*
22162216
* ```js
2217-
* const myRecord = new ABRecord({ b: 3, x: 10 })
2217+
* const myRecord = ABRecord({ b: 3, x: 10 })
22182218
* myRecord.get('x') // undefined
22192219
* ```
22202220
*
@@ -2233,14 +2233,22 @@ declare module Immutable {
22332233
* Record. This is not a common pattern in functional environments, but is in
22342234
* many JS programs.
22352235
*
2236+
* However Record Classes are more restricted than typical JavaScript classes.
2237+
* They do not use a class constructor, which also means they cannot use
2238+
* class properties (since those are technically part of a constructor).
2239+
*
2240+
* It's useful to think of Record Classes more like a Record Factory where
2241+
* record instances returned from the factory have additional API methods. It
2242+
* is best practice to not use `new` when creating new Records.
2243+
*
22362244
* ```
22372245
* class ABRecord extends Record({ a: 1, b: 2 }) {
22382246
* getAB() {
22392247
* return this.a + this.b;
22402248
* }
22412249
* }
22422250
*
2243-
* var myRecord = new ABRecord({b: 3})
2251+
* var myRecord = ABRecord({b: 3})
22442252
* myRecord.getAB() // 4
22452253
* ```
22462254
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy