Skip to content

Commit 9e2cdad

Browse files
committed
fix: simplify ReadableStream source constructor
1 parent 111e891 commit 9e2cdad

3 files changed

Lines changed: 10 additions & 25 deletions

File tree

docs/content/docs/contributing/api-modelling.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ When naming an overloaded function, we can use the `With` suffix to indicate tha
6363
Constructors follow a different naming rule than methods.
6464

6565
- Keep singleton constructors named `make`.
66-
- Keep true default constructors named `make`, even when the constructor family also has typed overloads.
66+
- Keep true no-argument default constructors named `make`, even when the constructor family also has typed overloads.
6767
- When a constructor family does not have a default constructor, use `from*` names for every overload, including the first one.
6868
- Base `from*` names on the source input type: `fromString`, `fromArrayBuffer`, `fromMediaStream`, `fromURLWithProtocols`, and so on.
6969
- If an optional labeled argument hides a real default constructor, split that binding into `make()` plus typed `from*` overloads instead of keeping the optional argument on `make`.

packages/File/src/ReadableStream.res

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,23 @@ let stream: ReadableStream.t<string> = ReadableStream.make()
1818
external make: unit => t<'t> = "ReadableStream"
1919

2020
/**
21-
`fromUnderlyingSource(underlyingSource<'t>)`
21+
`fromUnderlyingSource(underlyingSource<'t>, ~strategy: queuingStrategy<'t>=?)`
2222
23-
Creates a new `ReadableStream` from an `underlyingSource`.
23+
Creates a new `ReadableStream` from an `underlyingSource`, with an optional queuing strategy.
2424
2525
```res
2626
let stream = ReadableStream.fromUnderlyingSource(myUnderlyingSource)
27-
```
28-
29-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ReadableStream)
30-
*/
31-
@new
32-
external fromUnderlyingSource: Types.underlyingSource<'t> => t<'t> = "ReadableStream"
3327
34-
/**
35-
`fromUnderlyingSourceWithStrategy(~underlyingSource: underlyingSource<'t>, ~strategy: queuingStrategy<'t>)`
36-
37-
Creates a new `ReadableStream` from an `underlyingSource` and `queuingStrategy`.
38-
39-
```res
40-
let stream =
41-
ReadableStream.fromUnderlyingSourceWithStrategy(
42-
~underlyingSource=myUnderlyingSource,
43-
~strategy=myQueuingStrategy,
44-
)
28+
let streamWithStrategy =
29+
ReadableStream.fromUnderlyingSource(myUnderlyingSource, ~strategy=myQueuingStrategy)
4530
```
4631
4732
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ReadableStream)
4833
*/
4934
@new
50-
external fromUnderlyingSourceWithStrategy: (
51-
~underlyingSource: Types.underlyingSource<'t>,
52-
~strategy: Types.queuingStrategy<'t>,
35+
external fromUnderlyingSource: (
36+
Types.underlyingSource<'t>,
37+
~strategy: Types.queuingStrategy<'t>=?,
5338
) => t<'t> = "ReadableStream"
5439

5540
/**

tests/FileAPI/ReadableStream__test.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let _make: WebApiFile.ReadableStream.t<string> = WebApiFile.ReadableStream.make(
55

66
let _fromUnderlyingSource = WebApiFile.ReadableStream.fromUnderlyingSource(underlyingSource)
77

8-
let _fromUnderlyingSourceWithStrategy = WebApiFile.ReadableStream.fromUnderlyingSourceWithStrategy(
9-
~underlyingSource,
8+
let _fromUnderlyingSourceWithStrategy = WebApiFile.ReadableStream.fromUnderlyingSource(
9+
underlyingSource,
1010
~strategy,
1111
)

0 commit comments

Comments
 (0)