-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add docs for Record flow types #1343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2415,6 +2415,33 @@ declare module Immutable { | |
* var myRecord = new ABRecord({b: 3}) | ||
* myRecord.getAB() // 4 | ||
* ``` | ||
* | ||
* | ||
* **Flow Typing Records:** | ||
* | ||
* Immutable.js exports two Flow types designed to make it easier to use | ||
* Records with flow typed code, `RecordOf<T>` and `RecordFactory<T>`. | ||
* | ||
* When defining a new kind of Record factory function, use a flow type that | ||
* describes the values the record contains along with `RecordFactory<T>`. | ||
* To type instances of the Record (which the factory function returns), | ||
* use `RecordOf<T>`. | ||
* | ||
* Typically, new Record definitions will export both the Record factory | ||
* function as well as the Record instance type for use in other code. | ||
* | ||
* ```js | ||
* import type { RecordFactory, RecordOf } from 'immutable'; | ||
* | ||
* // Use RecordFactory<T> for defining new Record factory functions. | ||
* type Point3DFields = { x: number, y: number, z: number }; | ||
* const makePoint3D: RecordFactory<Point3DFields> = Record({ x: 0, y: 0, z: 0 }); | ||
* export makePoint3D; | ||
* | ||
* // Use RecordOf<T> for defining new instances of that Record. | ||
* export type Point3D = RecordOf<Point3DFields>; | ||
* const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check it out @peggyrayzis! Well typed Records! |
||
* ``` | ||
*/ | ||
export module Record { | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my gosh, thank you I've been hoping for this.