Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

turbine

> 前端框架
Open source

Purely functional frontend framework for building web applications

694 stars0 likes0 views
WebsiteGitHub

About

Purely functional frontend framework for building web applications

Turbine

A purely functional frontend framework based on functional reactive programming. Experimental.

Table of contents

  • Why Turbine?
  • Examples
  • High-level overview
  • Principles
  • Installation
  • More examples
  • Tutorial
  • API
  • Contributing

Why Turbine?

The JavaScript world is full of frameworks. So why another one? Because we want something different. We want something that is purely functional without compromises. Something that takes the best lessons from existing JavaScript frameworks and couples them with the powerful techniques found in functional languages like Haskell. We want a framework that is highly expressive. Because when functional programming is at its best it gives you more power, not less. Turbine is supposed to be approachable for typical JavaScript developers while still preserving the benefits that comes from embracing purely functional programming.

We have done our best to realize our goal. But we are not done yet. We hope you will find Turbine interesting, try it and maybe even help us making it even better.

Examples

Email validator

See the example live and editable here.

javascript
const isValidEmail = (s: string) => /.+@.+\..+/i.test(s);

const app = component((on) => {
  const isValid = on.email.map(isValidEmail);
  return [
    span("Please enter an email address: "),
    input().use({ email: "value" }),
    div(["The address is ", isValid.map((b) => (b ? "valid" : "invalid"))])
  ];
});

// `runComponent` is the only impure function in application code
runComponent("#mount", main);

Counter

See the example live and editable here.

javascript
const counter = component((on, start) => {
  const count = start(accum((n, m) => n + m, 0, on.delta));
  return E.div([
    "Counter ",
    count,
    E.button({ class: "btn btn-default" }, " + ").use(o => ({
      delta: o.click.mapTo(1)
    })),
    E.button({ class: "btn btn-default" }, " - ").use(o => ({
      delta: o.click.mapTo(-1)
    }))
  ]);
});

// `runComponent` is the only impure function in application code
runComponent("#mount", counter);

See more examples here.

High-level overview

Here our some of our key features.

  • Purely functional. A Turbine app is made up of only pure functions.
  • Leverage TypeScript and runtime checking to improve the developing experience.
  • Based on classic FRP. Behaviors represents values that change over time and streams provide reactivity. Turbine uses the FRP library Hareactive.
  • A component-based architecture. Components are immutable, encapsulated and composable. Components are monads and are typically used and composed with do-notation (we implement do-notation with generators).
  • Constructed DOM elements reacts directly to behaviors and streams. This avoids the overhead of using virtual DOM and should lead to great performance.
  • Side-effects are expressed with a declarative IO monad. This allows for easy testing of code with side-effects. Furthermore, the IO-monad is integrated with FRP.
  • The entire data flow through applications is explicit and easy to follow.
  • Our libraries are available both as CommonJS and ES2015 modules. This allows for tree-shaking.

Here are some of the features we want to implement and goals we're working towards.

  • Declarative and concise testing of time-dependent FRP code.
  • Performance. We think Turbine can be made very efficient. But we are not yet at a point where we focus on performance.
  • Support for server side rendering.
  • Browser devtools for easier development and debugging.
  • Hot-module replacement (if possible given our design).

Principles

This section describes some of the key principles and ideas underlying the design of Turbine.

Purely functional

Turbine is purely functional. We mean that in the most strict sense of the term. In a Turbine app, every single expression is pure. This gives a huge benefit in how easy it is to understand and maintain a Turbine app is.

One benefit of the complete purity is that every function in Turbine supports what is called "referential transparency". This means that an expression can always be replaced with its value.

As a simple example, say you have the following code:

javascript
const view = div([
  myComponent({ foo: "bar", something: 12 }),
  myComponent({ foo: "bar", something: 12 })
]);

One may notice that myComponent is called twice with the exact same arguments. Since all functions in a Turbine app are pure myComponent is no exception. Hence, we can make the following simple refactoring.

javascript
const component = myComponent({foo: "bar", something: 12}),
const view = div([
  component,
  component
]);

Such refactorings can always be safely done in Turbine.

Completely explicit data flow

One significant challenge when writing an interactive frontend application is how to manage the data flow through an application.

In Turbine we have strived to create an architecture where the data flow is easy to follow and understand. For us, this means that when looking at any piece of code it should be possible to see what other parts of the application it affects and what other parts it is affected by.

One manifestation of this principle is that in Turbine it is very simple to see how the model affects the view and how the view affects the model. The figure below illustrates this.

The arrows represent data flow between the model and the view. Note how these "conceptual arrows" are clearly expressed in the code. For instance, by looking at the buttons we can see exactly what output they produce.

Declarative models

Imperative programming is about doing. Functional programming is about being. This mean that ideally a functional program should be about defining what things are. That property is what makes functional programs declarative.

Below is a model from the counters example. Notice how the model consists of nothing but a series of const statements.

javascript
function* counterModel({ incrementClick, decrementClick, deleteClick }) {
  const increment = incrementClick.mapTo(1);
  const decrement = decrementClick.mapTo(-1);
  const deleteS = deleteClick.mapTo(id);
  const count = yield accum(add, 0, combine(increment, decrement));
  return { count, deleteS };
}

Each line is a declaration of a piece of the state. All models in Turbine follows this pattern. This makes state in a Turbine app very easy to understand. One can look at a single definition and be certain that it tells everything there is to know about that specific piece of state.

This is in sharp contrast to frameworks that mutate state or frameworks where state is stepped forward by reducer functions. With such approaches a single piece of state can potentially be affected and changed in several places. That can make it hard to understand how the state evolves. The benefits of having a definition as a single source of truth is lost.

Installation

bash
npm install @funkia/turbine @funkia/hareactive

Hareactive is a peer dependency. It is the FRP library that that Turbine is based upon.

Alternatively, for quickly trying out Turbine you may want to see our Turbine starter kit.

More examples

Here is a series of examples that demonstrate how to use Turbine. Approximately listed in order of increasing complexity.

  • Email validator — Very simple example of an email validator.
  • Fahrenheit celsius — A converter between fahrenheit and celsius.
  • Zip codes — A zip code validator. Shows one way of doing HTTP-requests with the IO-monad.
  • Continuous time — Shows how to utilize continuous time.
  • Counters — A list of counters. Demonstrates nested components, managing a list of components and how child components can communicate with parent components.
  • Todo — An implementation of the classic TodoMVC application.

Tutorial

In this tutorial, we will build a simple application with a list of counters. The application will be simple but not completely trivial. Along the way, most of the key concepts in Turbine will be explained. We will see how to create HTML, how to create custom components, how a component can be nested and how it can share state with its parent.

Please open an issue if you have questions regarding the tutorial or ideas for improvements.

The final result and the intermediate states can be seen by cloning this git repository, going into the directory with the counters example and running webpack to serve the application.

bash
git clone https://github.com/funkia/turbine/
cd turbine/examples/counters
npm run start

FRP

Turbine builds on top of the FRP library Hareactive. The two key concepts from FRP are behavior and stream. They are documented in more detail in the Hareactive readme. But the most important things to understand are behavior and stream.

  • Behavior represents values that change over time. For instance, the position of the mouse or the number of times a user has clicked a button.
  • Stream represents discrete events that happen over time. For instance click events.

What is Component

On top of the FRP primitives Turbine adds Component. Component is the key concept in Turbine. Once you understand Component—and how to use it—you understand Turbine. A Turbine app is just one big component.

Here is a high-level overview of what a component is.

  • Components can contain logic expressed through operations on behaviors and streams.
  • Components are encapsulated and have completely private state.
  • Components contain output through which they selectively decide what state they share with their parent.
  • Components write DOM elements as children to their parent. They can write zero, one or more DOM elements.
  • Components can declare side-effects expressed as IO-actions.
  • Components are composable—one component can be combined with another component and the result is a third component.

A Component in Turbine is pure and immutable. A Component can be thought of as a huge description of all of the above mentioned things. For instance, a Component contains a description about what its DOM look like. That part is a bit like virtual DOM. But, on top op that the description also explain how the DOM changes over time. The description also tells what output the Component contains. More on that later.

Creating HTML-elements

Turbine includes functions for creating components that represent standard HTML-elements. When you create your own components they will be made of these.

The element functions accept two arguments, both of which are optional. The first is an object describing various things like attributes, classes, etc. The second argument is a child component. For instance, to create a div with a span child we would write.

typescript
const myDiv = div({ class: "foo" }, span("Some text"));

The element functions are overloaded. So instead of giving span a component as child we can give it a string. The element functions also accept an array of child elements like this.

typescript
const myDiv = div({ class: "foo" }, [h1("A header"), p("Some text")]);

Using this we can build arbitrarily complex HTML. As an example we will build a simple view for a counter in our counter-application.

typescript
import { elements, runComponent } from "@funkia/turbine";
const { br, div, button } = elements;

// Co

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptframeworkfrpfunctional-reactive-programmingjavascript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架