Ultra-high performance reactive programming
Switch branches/tags
add-api-docs add-concurrent-merge add-currying add-debounce add-es7-observable-160 add-es7-observable add-extract add-fantasy-land add-filter-map-fusion add-flatmapenderror-aliases add-generate add-hold add-lift add-loop add-maybe-monad add-maybeT-eitherT add-merge-zip add-most-core-readme-note add-periodic-value add-promise add-publisher add-sample add-switch-remote-example add-switch add-transactional-time add-websocket add-xstream-perf-results bublify clarify-unfold-done-value curry-public-api deprecate-cycle deprecate-fromEventWhere dev dispose-inner-join-immediately es2015-ts-defs extract-fusion-rules fix-090-dispose-regression fix-208-b fix-create-early-end fix-scan-dispose-state fix-scan-initial fix-scan-join-dispose greenkeeper-babel-cli-6.9.0 greenkeeper-babel-cli-6.10.0 greenkeeper-babel-cli-6.10.1 greenkeeper-babel-cli-6.11.4 greenkeeper-babel-cli-6.14.0 greenkeeper-babel-eslint-6.0.5 greenkeeper-babel-eslint-6.1.0 greenkeeper-babel-eslint-6.1.1 greenkeeper-babel-eslint-6.1.2 greenkeeper-babel-polyfill-6.9.1 greenkeeper-babel-polyfill-6.13.0 greenkeeper-babel-polyfill-6.16.0 greenkeeper-babel-polyfill-6.20.0 greenkeeper-babel-polyfill-6.22.0 greenkeeper-babel-polyfill-6.23.0 greenkeeper-babel-preset-es2015-6.9.0 greenkeeper-babel-preset-es2015-6.13.0 greenkeeper-babel-preset-es2015-6.13.1 greenkeeper-babel-preset-es2015-6.13.2 greenkeeper-babel-preset-es2015-6.14.0 greenkeeper-babel-register-6.9.0 greenkeeper-babel-register-6.11.5 greenkeeper-babel-register-6.11.6 greenkeeper-babel-register-6.14.0 greenkeeper-buba-2.0.4 greenkeeper-buba-4.0.2 greenkeeper-eslint-2.12.0 greenkeeper-eslint-2.13.0 greenkeeper-eslint-2.13.1 greenkeeper-eslint-3.0.1 greenkeeper-eslint-3.1.1 greenkeeper-eslint-3.2.0 greenkeeper-eslint-3.2.1 greenkeeper-eslint-3.2.2 greenkeeper-eslint-3.3.0 greenkeeper-eslint-3.3.1 greenkeeper-eslint-3.4.0 greenkeeper-eslint-3.5.0 greenkeeper-eslint-3.6.0 greenkeeper-eslint-3.6.1 greenkeeper-eslint-3.7.0 greenkeeper-eslint-3.7.1 greenkeeper-eslint-3.8.0 greenkeeper-eslint-3.8.1 greenkeeper-eslint-3.9.0 greenkeeper-eslint-3.9.1 greenkeeper-eslint-3.10.0 greenkeeper-eslint-3.10.1 greenkeeper-eslint-3.10.2 greenkeeper-eslint-3.11.0 greenkeeper-eslint-3.11.1 greenkeeper-eslint-3.12.0 greenkeeper-eslint-3.12.1 greenkeeper-eslint-3.13.0 greenkeeper-eslint-3.13.1 greenkeeper-eslint-3.14.0 greenkeeper-eslint-3.14.1 greenkeeper-eslint-3.15.0 greenkeeper-eslint-3.16.0 greenkeeper-eslint-3.16.1 greenkeeper-eslint-3.17.0 greenkeeper-eslint-3.18.0 greenkeeper-eslint-3.19.0 greenkeeper-markdown-doctest-0.8.1 greenkeeper-markdown-doctest-0.9.1 greenkeeper-rimraf-2.6.0 greenkeeper-rimraf-2.6.1 greenkeeper-rollup-0.34.12 greenkeeper-rollup-0.34.13 greenkeeper-rollup-0.35.12 greenkeeper-rollup-0.35.13 greenkeeper-rollup-0.35.14 greenkeeper-rollup-0.35.15 greenkeeper-rollup-0.36.4 greenkeeper-rollup-0.37.1 greenkeeper-rollup-0.37.2 greenkeeper-rollup-0.38.1 greenkeeper-rollup-0.38.2 greenkeeper-rollup-0.38.3 greenkeeper-rollup-0.40.0 greenkeeper-rollup-0.40.1 greenkeeper-rollup-0.40.2 greenkeeper-rollup-0.41.0 greenkeeper-rollup-0.41.1 greenkeeper-rollup-0.41.2 greenkeeper-rollup-0.41.3 greenkeeper-rollup-plugin-buble-0.14.0 greenkeeper-rollup-plugin-node-resolve-2.1.0 greenkeeper-rollup-plugin-node-resolve-2.1.1 greenkeeper-symbol-observable-1.0.1 greenkeeper-symbol-observable-1.0.2 greenkeeper-symbol-observable-1.0.3 greenkeeper-symbol-observable-1.0.4 greenkeeper-uglify-js-2.6.3 greenkeeper-uglify-js-2.6.4 greenkeeper-uglify-js-2.7.0 greenkeeper-uglify-js-2.7.1 greenkeeper-uglify-js-2.7.2 greenkeeper-uglify-js-2.7.3 greenkeeper-uglify-js-2.7.4 greenkeeper-uglify-js-2.7.5 greenkeeper-uglify-js-2.8.0 greenkeeper-uglify-js-2.8.1 greenkeeper-uglify-js-2.8.2 greenkeeper-uglify-js-2.8.3 greenkeeper-uglify-js-2.8.4 greenkeeper-uglify-js-2.8.5 greenkeeper-uglify-js-2.8.10 greenkeeper-uglify-js-2.8.11 greenkeeper-uglify-js-2.8.12 greenkeeper-uglify-js-2.8.13 greenkeeper-uglify-js-2.8.14 greenkeeper-uglify-js-2.8.15 greenkeeper-uglify-js-2.8.17 greenkeeper-uglify-js-2.8.18 greenkeeper-uglify-js-2.8.19 greenkeeper-uglify-js-2.8.20 greenkeeper-uglify-js-2.8.21 greenkeeper-uglify-js-2.8.22 greenkeeper-uglify-js-2.8.23 greenkeeper-uglify-js-2.8.26 greenkeeper-webpack-1.13.1 greenkeeper-webpack-1.13.2 greenkeeper/eslint-4.0.0 greenkeeper/eslint-4.1.0 greenkeeper/eslint-4.1.1 greenkeeper/eslint-4.2.0 greenkeeper/eslint-4.3.0 greenkeeper/eslint-4.4.0 greenkeeper/eslint-4.4.1 greenkeeper/eslint-4.5.0 greenkeeper/eslint-4.6.0 greenkeeper/eslint-4.6.1 greenkeeper/eslint-4.7.0 greenkeeper/eslint-4.7.1 greenkeeper/eslint-4.7.2 greenkeeper/eslint-4.8.0 greenkeeper/eslint-4.9.0 greenkeeper/eslint-4.10.0 greenkeeper/eslint-4.11.0 greenkeeper/eslint-4.12.0 greenkeeper/eslint-4.12.1 greenkeeper/flow-bin-0.55.0 greenkeeper/flow-bin-0.56.0 greenkeeper/flow-bin-0.57.1 greenkeeper/flow-bin-0.57.2 greenkeeper/flow-bin-0.57.3 greenkeeper/flow-bin-0.58.0 greenkeeper/flow-bin-0.59.0 greenkeeper/@most/hold-3.0.0 greenkeeper/@most/multicast-1.3.0 greenkeeper/@most/multicast-pin-1.2.5 greenkeeper/rollup-0.46.0 greenkeeper/rollup-0.46.1 greenkeeper/rollup-0.46.2 greenkeeper/rollup-0.46.3 greenkeeper/rollup-0.47.0 greenkeeper/rollup-0.47.1 greenkeeper/rollup-0.47.2 greenkeeper/rollup-0.47.3 greenkeeper/rollup-0.47.4 greenkeeper/rollup-0.47.5 greenkeeper/rollup-0.47.6 greenkeeper/rollup-0.48.0 greenkeeper/rollup-0.48.1 greenkeeper/rollup-0.48.2 greenkeeper/rollup-0.49.0 greenkeeper/rollup-0.49.1 greenkeeper/rollup-0.49.2 greenkeeper/rollup-0.49.3 greenkeeper/rollup-0.50.0 greenkeeper/rollup-0.50.1 greenkeeper/rollup-0.51.0 greenkeeper/rollup-0.51.1 greenkeeper/rollup-0.51.2 greenkeeper/rollup-0.51.3 greenkeeper/rollup-0.51.4 greenkeeper/rollup-0.51.5 greenkeeper/rollup-0.51.6 greenkeeper/rollup-0.51.7 greenkeeper/rollup-0.51.8 greenkeeper/rollup-0.52.0 greenkeeper/rollup-plugin-buble-0.16.0 greenkeeper/rollup-plugin-buble-0.17.0 greenkeeper/rollup-plugin-buble-0.18.0 greenkeeper/symbol-observable-1.1.0 greenkeeper/symbol-observable-pin-1.0.4 greenkeeper/uglify-js-3.1.1 greenkeeper/uglify-js-3.1.3 greenkeeper/uglify-js-3.1.4 greenkeeper/uglify-js-3.1.5 greenkeeper/uglify-js-3.1.6 greenkeeper/uglify-js-3.1.7 greenkeeper/uglify-js-3.1.8 greenkeeper/uglify-js-3.1.9 greenkeeper/uglify-js-3.1.10 greenkeeper/uglify-js-3.2.0 greenkeeper/uglify-js-pin-3.1.2 improve-scan-initial-timing improve-scheduler-data-structures master move-flow-tests multicast-allthethings new-promise-stream node-read-adapter optimize-fromArray optimize-inner-just-empty readmefix reorg-combinators-add-merge-zip rethink-applicative simplify-scheduling support-fl-2.0 switch-to-benchmarkjs tylors/feat/count unscriptable-profit update-deps update-readme-from-96 update-transduce-protocol use-when-promise-directly v0.9.1 v0.10-merge v0.10-perf v0.10
Nothing to show
Clone or download
briancavalier Add note to point devs at @most/core for new projects (#526)
* Add note to point devs at most/core for new projects

* Rephrase, add same note to docs
Latest commit 13ca5c6 Aug 24, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add CONTRIBUTING, issue and PR templates (#417) Mar 8, 2017
dist release: 1.7.3 Feb 1, 2018
docs Add note to point devs at @most/core for new projects (#526) Aug 24, 2018
src Clear debounce timer when propagating debounced event (#515) Jan 31, 2018
test Clear debounce timer when propagating debounced event (#515) Jan 31, 2018
type-definitions chore(test): move flow tests (#489) Sep 9, 2017
.editorconfig should noop when it's already disposed (#361) Dec 1, 2016
.eslintignore chore(test): move flow tests (#489) Sep 9, 2017
.eslintrc chore(test): move flow tests (#489) Sep 9, 2017
.flowconfig Use standard, update deps, drop some (#510) Dec 2, 2017
.gitignore feat(types): Add flow definitions (#478) Aug 28, 2017
.markdown-doctest-setup.js Es6 imports exports (#301) Sep 1, 2016
.npmignore Add type-to-search wikipedia example. See #23 Aug 22, 2014
.travis.yml Use standard, update deps, drop some (#510) Dec 2, 2017
CONTRIBUTING.md Add CONTRIBUTING, issue and PR templates (#417) Mar 8, 2017
LICENSE chore(license): Add license file (#326) Sep 13, 2016
PACKAGES.md Update PACKAGES.md (#503) Nov 17, 2017
README.md Add note to point devs at @most/core for new projects (#526) Aug 24, 2018
bower.json fix(package): add src dir and module to package.json files (#313) Sep 8, 2016
package-lock.json release: 1.7.3 Feb 1, 2018
package.json release: 1.7.3 Feb 1, 2018
rollup.config.js Es6 imports exports (#301) Sep 1, 2016

README.md

________________________________
___   |/  /_  __ \_  ___/__  __/
__  /|_/ /_  / / /____ \__  /   
_  /  / / / /_/ /____/ /_  /    
/_/  /_/  \____/______/ /_/

Monadic streams for reactive programming

Greenkeeper badge

Build Status Join the chat at https://gitter.im/cujojs/most

Starting a new project?

Strongly consider starting with @most/core. It is the foundation of the upcoming most 2.0, has improved documentation, new features, better tree-shaking build characteristics, and simpler APIs. Updating from @most/core to most 2.0 will be non-breaking and straightforward.

Using most 1.x already on an existing project?

You can keep using most 1.x, and update to either @most/core or most 2.0 when you're ready. See the upgrade guide for more information.

What is it?

Most.js is a toolkit for reactive programming. It helps you compose asynchronous operations on streams of values and events, e.g. WebSocket messages, DOM events, etc, and on time-varying values, e.g. the "current value" of an <input>, without many of the hazards of side effects and mutable shared state.

It features an ultra-high performance, low overhead architecture, APIs for easily creating event streams from existing sources, like DOM events, and a small but powerful set of operations for merging, filtering, transforming, and reducing event streams and time-varying values.

Learn more

Simple example

Here's a simple program that displays the result of adding two inputs. The result is reactive and updates whenever either input changes.

First, the HTML fragment for the inputs and a place to display the live result:

<form>
	<input class="x"> + <input class="y"> = <span class="result"></span>
</form>

Using most.js to make it reactive:

import { fromEvent, combine } from 'most'

const xInput = document.querySelector('input.x')
const yInput = document.querySelector('input.y')
const resultNode = document.querySelector('.result')

const add = (x, y) => x + y

const toNumber = e => Number(e.target.value)

const renderResult = result => {
	resultNode.textContent = result
}

export const main = () => {
	// x represents the current value of xInput
	const x = fromEvent('input', xInput).map(toNumber)

	// y represents the current value of yInput
	const y = fromEvent('input', yInput).map(toNumber)

	// result is the live current value of adding x and y
	const result = combine(add, x, y)

	// Observe the result value by rendering it to the resultNode
	result.observe(renderResult)
}

More examples

You can find the example above and others in the Examples repo.

Get it

Requirements

Most requires ES6 Promise. You can use your favorite polyfill, such as creed, when, bluebird, es6-promise, etc. Using a polyfill can be especially beneficial on platforms that don't yet have good unhandled rejection reporting capabilities.

Install

As a module:

npm install --save most
// ES6
import { /* functions */ } from 'most'
// or
import * as most from 'most'
// ES5
var most = require('most')

As window.most:

bower install --save most
<script src="most/dist/most.js"></script>

As a library via cdn :

<!-- unminified -->
<script src="https://unpkg.com/most/dist/most.js"></script>
<!-- minified -->
<script src="https://unpkg.com/most/dist/most.min.js"></script>

Typescript support

Most.js works with typescript out of the box as it provides local typings that will be read when you import Most.js in your code. You do not need to manually link an external d.ts file in your tsconfig.

Most.js has a dependency on native Promises so a type definition for Promise must be available in your setup:

  • If your tsconfig is targeting ES6, you do not need to do anything as typescript will include a definition for Promise by default.
  • If your tsconfig is targeting ES5, you need to provide your own Promise definition. For instance es6-shim.d.ts

Interoperability

Promises/A+ Fantasy Land

Most.js streams are compatible with Promises/A+ and ES6 Promises. They also implement Fantasy Land and Static Land Semigroup, Monoid, Functor, Apply, Applicative, Chain and Monad.

Reactive Programming

Reactive programming is an important concept that provides a lot of advantages: it naturally handles asynchrony and provides a model for dealing with complex data and time flow while also lessening the need to resort to shared mutable state. It has many applications: interactive UIs and animation, client-server communication, robotics, IoT, sensor networks, etc.

Why most.js for Reactive Programming?

High performance

A primary focus of most.js is performance. The perf test results indicate that it is achieving its goals in this area. Our hope is that by publishing those numbers, and showing what is possible, other libs will improve as well.

Modular architecture

Most.js is highly modularized. It's internal Stream/Source/Sink architecture and APIs are simple, concise, and well defined. Combinators are implemented entirely in terms of that API, and don't need to use any private details. This makes it easy to implement new combinators externally (ie in contrib repos, for example) while also guaranteeing they can still be high performance.

Simplicity

Aside from making combinators less "obviously correct", complexity can also lead to performace and maintainability issues. We felt a simple implementation would lead to a more stable and performant lib overall.

Integration

Most.js integrates with language features, such as promises, iterators, generators, and asynchronous generators.

Promises

Promises are a natural compliment to asynchronous reactive streams. The relationship between synchronous "sequence" and "value" is clear, and the asynchronous analogue needs to be clear, too. By taking the notion of a sequence and a value and lifting them into the asynchronous world, it seems clear that reducing an asynchronous sequence should produce a promise. Hence, most.js uses promises when a single value is the natural synchronous analogue.

Most.js interoperates seamlessly with ES6 and Promises/A+ promises. For example, reducing a stream returns a promise for the final result:

import { from } from 'most'
// After 1 second, logs 10
from([1, 2, 3, 4])
	.delay(1000)
	.reduce((result, y) => result + y, 0)
	.then(result => console.log(result))

You can also create a stream from a promise:

import { fromPromise } from 'most'
// Logs "hello"
fromPromise(Promise.resolve('hello'))
	.observe(message => console.log(message))

Generators

Conceptually, generators allow you to write a function that acts like an iterable sequence. Generators support the standard ES6 Iterator interface, so they can be iterated over using ES6 standard for of or the iterator's next() API.

Most.js interoperates with ES6 generators and iterators. For example, you can create an event stream from any ES6 iterable:

import { from } from 'most'

function* allTheIntegers() {
	let i=0
	while(true) {
		yield i++
	}
}

// Log the first 100 integers
from(allTheIntegers())
	.take(100)
	.observe(x => console.log(x))

Asynchronous Generators

You can also create an event stream from an asynchronous generator, a generator that yields promises:

import { generate } from 'most'

function* allTheIntegers(interval) {
	let i=0
	while(true) {
		yield delayPromise(interval, i++)
	}
}

const delayPromise = (ms, value) =>
	new Promise(resolve => setTimeout(() => resolve(value), ms))

// Log the first 100 integers, at 1 second intervals
generate(allTheIntegers, 1000)
	.take(100)
	.observe(x => console.log(x))