-
Notifications
You must be signed in to change notification settings - Fork 469
Add some docs to stblib Symbol #7336
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 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
398d0f5
Add some docs to stblib Symbol
jderochervlk 42cdf74
add to artifacts
jderochervlk 5520d1d
start switching to assert
jderochervlk 0326321
check
jderochervlk e5734fa
all asserts
jderochervlk eb1e28c
pr feedback
jderochervlk 370d85a
fixing tests
jderochervlk 25113a7
work
jderochervlk f6debf9
tests passing
jderochervlk 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
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 | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,107 @@ | ||||||||
/*** | ||||||||
A built-in object that serves as a namespace for globally-unique identifiers. | ||||||||
|
||||||||
Compiles to a regular JavaScript Symbol. | ||||||||
*/ | ||||||||
|
||||||||
/** | ||||||||
Type representing a Symbol. | ||||||||
*/ | ||||||||
type t | ||||||||
|
||||||||
/** | ||||||||
`make(key)` | ||||||||
|
||||||||
Makes a new unique Symbol value. | ||||||||
|
||||||||
## Examples | ||||||||
|
||||||||
```rescript | ||||||||
let sym = Symbol.make("foo") | ||||||||
``` | ||||||||
*/ | ||||||||
@val | ||||||||
external make: string => t = "Symbol" | ||||||||
|
||||||||
/** | ||||||||
`getFor(key)` | ||||||||
|
||||||||
Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found. | ||||||||
Otherwise a new Symbol gets created and registered with key. | ||||||||
|
||||||||
## Examples | ||||||||
|
||||||||
```rescript | ||||||||
let sym = Symbol.getFor("foo") | ||||||||
``` | ||||||||
*/ | ||||||||
@val | ||||||||
external getFor: string => t = "Symbol.for" | ||||||||
|
||||||||
/** | ||||||||
`keyFor(key)` | ||||||||
|
||||||||
Retrieves a shared Symbol key from the global Symbol registry for the given Symbol. | ||||||||
|
||||||||
## Examples | ||||||||
|
||||||||
```rescript | ||||||||
let globalSym = Symbol.getFor("sym1") // Global symbol | ||||||||
|
||||||||
Console.log(Symbol.keyFor(globalSym)) | ||||||||
// Expected output: "sym1" | ||||||||
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. Make those a test instead of just documenting it, it'd be even more useful!
Suggested change
|
||||||||
|
||||||||
let localSym = Symbol.make("sym2") // Local symbol | ||||||||
|
||||||||
Console.log(Symbol.keyFor(localSym)) | ||||||||
// Expected output: undefined | ||||||||
``` | ||||||||
*/ | ||||||||
@val | ||||||||
external keyFor: t => option<string> = "Symbol.keyFor" | ||||||||
|
||||||||
/** | ||||||||
`description` | ||||||||
|
||||||||
Returns `Some(string)` containing the description of this symbol, or `None` if the symbol has no description. | ||||||||
## Examples | ||||||||
|
||||||||
```rescript | ||||||||
let sym = Symbol.make("foo") | ||||||||
Console.log(sym->Symbol.description) | ||||||||
``` | ||||||||
*/ | ||||||||
@get | ||||||||
external description: t => option<string> = "description" | ||||||||
|
||||||||
/** | ||||||||
`toString` | ||||||||
|
||||||||
// Returns a string representing this symbol value. | ||||||||
|
||||||||
## Examples | ||||||||
|
||||||||
```rescript | ||||||||
let sym = Symbol.make("foo") | ||||||||
Console.log(sym->Symbol.toString) | ||||||||
// Expected output: "Symbol(foo)" | ||||||||
``` | ||||||||
*/ | ||||||||
@send | ||||||||
external toString: t => string = "toString" | ||||||||
|
||||||||
@val | ||||||||
external asyncIterator: t = "Symbol.asyncIterator" | ||||||||
@val | ||||||||
external hasInstance: t = "Symbol.hasInstance" | ||||||||
@val external isConcatSpreadable: t = "Symbol.isConcatSpreadable" | ||||||||
@val external iterator: t = "Symbol.iterator" | ||||||||
@val external match: t = "Symbol.match" | ||||||||
@val external matchAll: t = "Symbol.matchAll" | ||||||||
@val external replace: t = "Symbol.replace" | ||||||||
@val external search: t = "Symbol.search" | ||||||||
@val external species: t = "Symbol.species" | ||||||||
@val external split: t = "Symbol.split" | ||||||||
@val external toPrimitive: t = "Symbol.toPrimitive" | ||||||||
@val external toStringTag: t = "Symbol.toStringTag" | ||||||||
@val external unscopables: t = "Symbol.unscopables" |
Oops, something went wrong.
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.
you also forgot to update the interface file, and while we're there, I'd also use
@scope
for these bindings, which is cleaner IMO: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.
Fixed.