This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Stream, Sink, Scheduler, Disposable} from '@most/types'; | |
import {disposeOnce, disposeAll} from '@most/disposable'; | |
export type ActivateExtension<A = any> = (source: Stream<A>) => Stream<A>; | |
export type DeactivateExtension = null; | |
export type ExtensionAction<A = any> = ActivateExtension<A>|DeactivateExtension; | |
export type ExtensionLifecycle<A = any> = Stream<ExtensionAction<A>>; | |
export function extensible<A>(source: Stream<A>, extensions: Stream<ExtensionLifecycle<A>>): Stream<A> { | |
return new ExtensiblePipeline(extensions, source); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function identity<T>(value: T): T { | |
return value; | |
} | |
let wrap = identity; | |
export function inspect<T>(fn: (value: T) => T): void { | |
wrap = fn; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Preprocessor Directives | |
======================= | |
// --- OMIT A SINGLE LINE ---------------------------------------------------- | |
log("This line will be excluded from the build"); // ## DEV ## | |
// --- OMIT A WHOLE BLOCK ---------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Immutable from 'immutable'; | |
import formatDate from 'date-fns/format'; | |
import immutableDiff from 'immutablediff'; | |
/* eslint-disable no-underscore-dangle */ | |
var colors = { | |
0: ['white', '#7fbad8', '#0075b2'], | |
1: ['white', '#91a0ce', '#24429e'], | |
2: ['white', '#ab86e0', '#570ec1'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {using} from 'proxy-abstraction'; | |
function render() { | |
// The `using` function takes a callback function. It looks at the functions `.length` property | |
// and generates a proxy for each. You then return a tuple containing the value you want to | |
// persist, and fulfillment streams for each of the referenced proxies. The using function will | |
// automatically complete the proxies internally and return the first tuple argument. | |
return using((click$, hover$) => { | |
const view = div(......); | |
return [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copyArray<T>(values: T[]): T[] { | |
switch(value.length) { | |
case 0: return []; | |
case 1: return [value[0]]; | |
case 2: return [value[0], value[1]]; | |
case 3: return [value[0], value[1], value[2]]; | |
case 4: return [value[0], value[1], value[2], value[3]]; | |
case 5: return [value[0], value[1], value[2], value[3], value[4]]; | |
case 6: return [value[0], value[1], value[2], value[3], value[4], value[5]]; | |
case 7: return [value[0], value[1], value[2], value[3], value[4], value[5], value[6]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# CriticalSection | |
"A stream-flavoured critical section implementation for isolating access to a stream subgraph" | |
Events entering a stream graph fenced off by a critical section will cause all other entry points to switch into | |
blocking mode, with events received at a given entry point being retained in that entry point's internal buffer, | |
and the entry point buffer enqueued for subsequent processing. Each time an event flows through an exit point, the | |
next entry point in the queue will be dequeued and its next buffered event emitted into the inner stream graph. | |
When no data is buffered at any entry point, the critical section unblocks, allowing direct dispatch of the next | |
future data item to arrive, at which point it will switch back into blocking mode. Errors ignore critical section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Limit the rate of flow to an event every 250ms: | |
// const stream$ = other$.thru(limitFlow(250)); | |
export function limitFlow(period) { | |
return function limitFlow(stream) { | |
const source = new RateLimitSource(stream.source, period); | |
return new stream.constructor(source); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Rx} from '@cycle/core'; | |
export default function (responses, strings) { | |
var log = responses.log.create('Sample'); | |
var str$ = Rx.Observable | |
.from(strings) | |
.do(str => { | |
log.trace('Just tracing stuff'); | |
log.debug('Here is a debug message'); | |
log.success('The successful thing happened that we wanted to happen'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MulticastSource = require('most/lib/source/MulticastSource'); | |
const PropagateTask = require('most/lib/scheduler/PropagateTask'); | |
const CompoundDisposable = require('most/lib/disposable/CompoundDisposable'); | |
module.exports = ReplaySource; | |
function ReplaySource(source) { | |
this._buffer = []; | |
this._ended = false; | |
MulticastSource.call(this, source); |