{"id":12674,"library":"wonka","title":"Wonka Stream Library","description":"Wonka is a lightweight, capable push and pull stream library designed for TypeScript and Flow, loosely adhering to the callbag specification. Currently at stable version 6.3.6, it provides a functional approach to handling event streams and iterable data sets, offering helpers to create, transform, and consume multiple values over time. The project maintains an active release cadence, with frequent patch updates addressing minor fixes and improvements, and occasional minor versions introducing new features, such as adding the `addOne` argument to `takeWhile` in `v6.3.0`. Its key differentiators include its small bundle size, strong TypeScript integration, and a focus on composing operations through a `pipe` function, offering a pragmatic alternative to larger reactive programming libraries while maintaining clear stream semantics. Version 6 notably shifted its focus exclusively to TypeScript, Flow, and JavaScript environments, dropping support for Reason/OCaml/esy/dune that was present in v5.","status":"active","version":"6.3.6","language":"javascript","source_language":"en","source_url":"https://github.com/0no-co/wonka","tags":["javascript","wonka","typescript","events","callbag","callback","observable","iterable","stream"],"install":[{"cmd":"npm install wonka","lang":"bash","label":"npm"},{"cmd":"yarn add wonka","lang":"bash","label":"yarn"},{"cmd":"pnpm add wonka","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"All core utilities and operators are named exports.","wrong":"import pipe from 'wonka'","symbol":"pipe","correct":"import { pipe } from 'wonka'"},{"note":"Wonka v6+ is primarily designed for ESM; while CommonJS might work with transpilation, direct `require` usage can lead to issues in mixed environments.","wrong":"const fromArray = require('wonka').fromArray;","symbol":"fromArray","correct":"import { fromArray } from 'wonka'"},{"note":"`subscribe` is a top-level operator in Wonka, not a method on an Observable instance like in some other RxJS-like libraries.","wrong":"import { Observable } from 'wonka'; new Observable().subscribe();","symbol":"subscribe","correct":"import { subscribe } from 'wonka'"},{"note":"`make` is the primary low-level function for creating custom observable sources.","wrong":"import { createSource } from 'wonka'","symbol":"make","correct":"import { make } from 'wonka'"}],"quickstart":{"code":"import { pipe, fromArray, map, filter, subscribe, make } from 'wonka';\n\n// 1. Create a simple stream from an array, transform it, and log values\nconst numberStream = pipe(\n  fromArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),\n  filter(n => n % 2 === 0), // Keep only even numbers\n  map(n => n * 2),          // Double them\n  subscribe(value => {\n    console.log(`Array Stream: ${value}`);\n  })\n);\n\n// For demonstration, manually unsubscribe after some time (optional for finite streams)\n// setTimeout(() => numberStream.unsubscribe(), 100);\n\n// 2. Create a custom interval stream that emits a few values\nconst intervalSource = (intervalMs: number) =>\n  make<number>(({ next, complete }) => {\n    let count = 0;\n    const id = setInterval(() => {\n      if (count < 3) { // Emit 3 values then complete\n        next(count++);\n      } else {\n        complete(); // Signal completion\n        clearInterval(id);\n      }\n    }, intervalMs);\n    return () => clearInterval(id); // Teardown logic\n  });\n\nconst intervalPipeline = pipe(\n  intervalSource(1000), // Emit every second\n  map(val => `Custom Interval Stream: ${val}`),\n  subscribe(console.log)\n);\n\n// The interval stream will automatically complete and clean up after 3 emissions.\n","lang":"typescript","description":"Demonstrates creating a stream from an array, applying `filter` and `map` operators, and subscribing. It also shows how to create a custom observable source using `make` with teardown logic for an interval stream."},"warnings":[{"fix":"For existing Reason/OCaml projects, consider staying on `wonka@5` or porting stream logic to a JavaScript/TypeScript compatible implementation.","message":"Version 6 of Wonka dropped support for Reason/OCaml/esy/dune. Users migrating from v5 who relied on these environments will need to remain on v5 or rewrite their streaming logic for TypeScript/Flow/JavaScript.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Ensure that any custom `ObservableSubscription` implementations or type assertions explicitly define `closed: boolean`. Update any logic that might check for `subscription.closed == null` to `subscription.closed === false` or `subscription.closed === true`.","message":"In `v6.2.5`, the `closed` property on `ObservableSubscription`s was made a required boolean field to align with the Observable proposal's type specification. Code expecting `closed` to be optional or `undefined` might encounter TypeScript errors.","severity":"breaking","affected_versions":">=6.2.5"},{"fix":"Update to `wonka@6.3.4` or higher to resolve missing `Symbol.observable` typings. If unable to update, manually declare `Symbol.observable` globally if necessary for your environment.","message":"Prior to `v6.3.4`, there were issues with missing `Symbol.observable` global declarations in typings, which could lead to type errors when integrating with libraries or patterns relying on the TC39 Observable proposal.","severity":"gotcha","affected_versions":"<6.3.4"},{"fix":"Update to `wonka@6.3.1` or higher to include the fix for ambient enum declarations.","message":"Early patch versions of `v6.3` (specifically prior to `v6.3.1`) had missing `declare` keywords on internal ambient enums, causing potential compilation issues in some TypeScript environments.","severity":"gotcha","affected_versions":">=6.3.0 <6.3.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Switch to ES Module `import` syntax (e.g., `import { pipe } from 'wonka';`). Ensure your project is configured for ESM, or use a bundler that correctly handles module resolution.","cause":"Attempting to use CommonJS `require()` syntax in an environment where Wonka is distributed as an ESM-only package or when the project's `type` is set to `module` in `package.json`.","error":"TypeError: require is not a function"},{"fix":"Always use `pipe()` as a standalone function: `pipe(source, operator1, operator2, ...)`. Do not try to call `source.pipe()`.","cause":"Misunderstanding Wonka's functional API where `pipe` is a top-level function that composes operations, rather than a method on the source object itself.","error":"Property 'pipe' does not exist on type 'Source<T>'"},{"fix":"Update to `wonka@6.2.5` or later. If sticking to older versions, adjust your TypeScript types to explicitly allow `boolean | undefined` for `closed` if you're writing custom subscription logic.","cause":"This error can occur in versions `<6.2.5` if you explicitly typed an `ObservableSubscription` and then accessed `closed`, as it was optionally `boolean | undefined`. After `v6.2.5`, `closed` became a required `boolean`.","error":"Type 'boolean | undefined' is not assignable to type 'boolean'."}],"ecosystem":"npm"}