Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsSep 11, 2026·3 min de lecture

Bacon.js — Functional Reactive Programming for JavaScript

Handle complex event streams and asynchronous data flows with a composable reactive programming library for the browser and Node.js.

Prêt pour agents

Staging sûr pour cet actif

Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.

Stage only · 17/100Policy : staging
Surface agent
Tout agent MCP/CLI
Type
Script
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
Bacon.js
Commande de staging sûr
npx -y tokrepo@latest install dfe99632-ade5-11f1-9bc6-00163e2b0d79 --target codex

Stage les fichiers d'abord; l'activation exige la revue du README et du plan staged.

Introduction

Bacon.js is a functional reactive programming (FRP) library for JavaScript that models asynchronous events as composable streams and properties. It provides a declarative way to handle complex event logic, replacing tangled callback chains with clean, testable data flow pipelines.

What Bacon.js Does

  • Represents event sequences as EventStreams and time-varying values as Properties
  • Provides operators to map, filter, combine, merge, and throttle streams
  • Handles async operations with flatMap, retry, and error propagation
  • Integrates with DOM events, Node.js EventEmitters, Promises, and callbacks
  • Supports lazy evaluation so unused stream branches carry no overhead

Architecture Overview

Bacon.js models two core abstractions: EventStream (a series of discrete events over time) and Property (a value that changes over time and always has a current value). Both support the same composable operators. The library uses a push-based evaluation model where events propagate through the operator graph. Subscriptions manage lifecycle, and streams are garbage-collected when all subscribers unsubscribe.

Self-Hosting & Configuration

  • Install from npm: npm install baconjs
  • Import the full library or use tree-shakable ESM imports for smaller bundles
  • No configuration file needed; the library is stateless and side-effect-free
  • Works in browsers via bundlers (webpack, Rollup, Vite) and in Node.js directly
  • TypeScript definitions are included in the package

Key Features

  • Clean separation between EventStreams and Properties
  • Rich combinator library: merge, zip, combine, sampledBy, and debounce
  • Built-in error handling through the stream pipeline
  • Bus class for imperative event injection when bridging non-FRP code
  • Works with any UI framework or vanilla JavaScript

Comparison with Similar Tools

  • RxJS — larger API surface with more operators and scheduler support; Bacon.js is simpler with its EventStream/Property distinction
  • Most.js — focused on performance with a monadic API; Bacon.js prioritizes readability
  • Kefir — inspired by Bacon.js with a lighter footprint and similar API
  • Solid.js signals — fine-grained reactivity for UI; Bacon.js is a general-purpose FRP library

FAQ

Q: How does Bacon.js differ from RxJS? A: Bacon.js distinguishes EventStreams from Properties (time-varying values), while RxJS uses Observables for both. Bacon's API is smaller and more opinionated.

Q: Is Bacon.js suitable for production? A: Yes. It has been used in production applications for over a decade and has a stable API.

Q: Does it support TypeScript? A: Yes. TypeScript type definitions ship with the npm package.

Q: What is the bundle size? A: The full library is about 18 KB gzipped. Tree-shaking reduces this when using ESM imports.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires