···11---
22title: API Reference
33-order: 3
33+order: 4
44---
5566Wonka, in essence, can be used to create sources, to transform sources with operators,
+1-1
docs/basics/index.md
···11---
22title: Basics
33-order: 2
33+order: 3
44---
5566Wonka introduces a new primitive for streams.
+110
docs/migration.md
···11+---
22+title: Migration
33+order: 2
44+---
55+66+This page lists breaking changes and migration guides for
77+various major releases of Wonka.
88+99+## v4.0.0
1010+1111+In `v4.0.0` of Wonka, we've migrated to BuckleScript v7 and
1212+`genType` for automatic type generation for TypeScript. The
1313+Flow types are derived from the automatic types and are generated
1414+by `flowgen`.
1515+1616+This may mean that `bsb-native` and Dune/Esy builds are temporarily
1717+broken, as they haven't been tested yet. If so, they will be fixed
1818+in a future minor release. Please stick with `v3.2.2` if you're having
1919+trouble.
2020+2121+This release has no breaking changes for Reason/OCaml in terms of
2222+API changes. You can use the library exactly as you have before.
2323+2424+**For TypeScript and Flow some APIs have changed**.
2525+2626+### New TypeScript and Flow typings
2727+2828+The type for `Subscription`, `Observer`, and `Subject` have changed.
2929+These used to be exposed as tuples (fixed-size arrays) in the past,
3030+but are now compiled to objects, due to the upgrade to BuckleScript v7.
3131+3232+If you're using `subscribe`, `makeSubject`, or `make` you will have
3333+to change some of your types. If you don't, you won't have to update
3434+any of your code and can even mix Wonka `v4.0.0` with `v3.2.2` in the
3535+same bundle.
3636+3737+The `Subscription` type has changed from `[() => void]` to
3838+`{ unsubscribe: (_: void) => void }`:
3939+4040+```ts
4141+import { subscribe } from 'wonka';
4242+4343+// Before:
4444+const [unsubscribe] = subscribe(source);
4545+// After:
4646+const { unsubscribe } = subscribe(source);
4747+```
4848+4949+The `Observer` type has changed similarly, so you'll have to
5050+update your code if you're using `make`:
5151+5252+```ts
5353+import { make } from 'wonka';
5454+5555+// Before:
5656+const source = make(([next, complete]) => /* ... */);
5757+// After:
5858+const source = make(({ next, complete }) => /* ... */);
5959+```
6060+6161+And lastly the `Subject` type has changed as well, so update
6262+your usage of `makeSubject`:
6363+6464+```ts
6565+import { makeSubject } from 'wonka';
6666+6767+// Before:
6868+const [source, next, complete] = makeSubject();
6969+// After:
7070+const { source, next, complete } = makeSubject();
7171+```
7272+7373+### Improvements
7474+7575+The test suite has been rewritten from scratch to improve our
7676+testing of some tricky edge cases. In most cases operators have
7777+been updated to behave more nicely and closer to the spec and
7878+as expected. This is especially true if you're using synchronous
7979+sources or iterables a lot.
8080+8181+Wonka has reached a much higher test coverage and operators like
8282+`merge` and `switchMap` will now behave as expected with synchronous
8383+sources.
8484+8585+This is the list of operators that have changed. If your code has
8686+been working before, you _shouldn't see any different behaviour_.
8787+The changed operators will simply have received bugfixes and will
8888+behave more predictably (and hopefully correctly) in certain edge cases!
8989+9090+- [`buffer`](./api/operators.md#buffer)
9191+- [`combine`](./api/operators.md#combine)
9292+- [`debounce`](./api/operators.md#debounce)
9393+- [`delay`](./api/operators.md#delay)
9494+- [`sample`](./api/operators.md#sample)
9595+- [`skipUntil`](./api/operators.md#skipuntil)
9696+- [`take`](./api/operators.md#take)
9797+- [`takeLast`](./api/operators.md#takelast)
9898+- [`takeWhile`](./api/operators.md#takewhile)
9999+- [`switchMap`](./api/operators.md#switchmap)
100100+- [`mergeMap`](./api/operators.md#mergemap)
101101+- [`concatMap`](./api/operators.md#concatmap)
102102+- [`switchAll`](./api/operators.md#switchall)
103103+- [`mergeAll`](./api/operators.md#mergeall)
104104+- [`concatAll`](./api/operators.md#concatall)
105105+- [`merge`](./api/operators.md#merge)
106106+- [`concat`](./api/operators.md#concat)
107107+108108+The `take` operator is the only one that has been changed to fix
109109+a notable new usage case. It can now accept a maximum of `0` or below,
110110+to close the source immediately.