ConfigsSep 11, 2026·3 min read

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.

Agent ready

Safe staging for this asset

This asset is staged first. The copied prompt tells the agent to inspect the staged files and ask before activating scripts, MCP config, or global config.

Stage only · 17/100Policy: stage
Agent surface
Any MCP/CLI agent
Kind
Script
Install
Stage only
Trust
Trust: Established
Entrypoint
Bacon.js
Safe staging command
npx -y tokrepo@latest install dfe99632-ade5-11f1-9bc6-00163e2b0d79 --target codex

Stages files first; activation requires review of the staged README and plan.

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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets