Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsSep 11, 2026·3 min de lectura

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.

Listo para agents

Staging seguro para este activo

Este activo primero queda en staging. El prompt copiado pide inspeccionar los archivos staged antes de activar scripts, config MCP o config global.

Stage only · 17/100Política: staging
Superficie agent
Cualquier agent MCP/CLI
Tipo
Script
Instalación
Stage only
Confianza
Confianza: Established
Entrada
Bacon.js
Comando de staging seguro
npx -y tokrepo@latest install dfe99632-ade5-11f1-9bc6-00163e2b0d79 --target codex

Primero deja archivos en staging; la activación requiere revisar el README y el 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

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados