Skip to content

Instantly share code, notes, and snippets.

var subscribers = []
var subscribe = function(subscriber) {
subscribers
.push(subscriber)
}
var dispatch = function(action) {
stateModifiers[action.type]
&& stateModifiers[action.type](action)
var createStore = function(stateModifiers) {
var localState = {
subscribers: [],
}
var subscribe = function(subscribers) {
localState
.subscribers = (
localState
.subscribers
var actions = {
UPDATE_IDS: function(action) {
vm.ids = action.ids
},
UPDATE_PRIVILAGES: function(action) {
vm.privileges = action.privileges
},
}
var dispatch = function(
var dispatch = function(action) {
stateModifiers[action.type]
&& stateModifiers[action.type](action)
return action
}
import { EMPTY, from, fromEvent, merge, Observable, Subject } from 'rxjs'
import { delay, distinctUntilKeyChanged, filter, ignoreElements, map, mapTo, mergeMap, scan, startWith, switchMap, tap } from 'rxjs/operators'
console
.clear()
const ofType = (
...requiredTypes
) => (
filter(({
function undo<T>(undoNotifier: Observable<any>, redoNotifier: Observable<any> = EMPTY) {
return (source: Observable<T>) => merge(
undoNotifier.pipe(map(() => UNDO_TOKEN)),
redoNotifier.pipe(map(() => REDO_TOKEN)),
source,
).pipe(
scan<T, { state: T[], subtractor: number, redos: T[]|null }>((d, x) => {
let { state, subtractor, redos } = d;
if (x === UNDO_TOKEN) {
// We were notified of an "undo". pop state.
/**
* Subscribes to the `undoNotifier`, and emits all values from
* `source`. When `undoNotifier` emits, it will emit previously
* emitted values back through time.
*
* If a `redoNotifier` is passed, it's subscribed to, and when
* it emits, will "redo" anything that was "undone", unless new
* values have come from the source.
*
* TODO: Add an upper-bounds to the undo state collected.
const render$ = new Subject()
render$.subscribe(
value => output.textContent = '' + value
);
// Just a source that increments a number over time when
// you click buttons.
const source$ = render$.pipe(
startWith(INITIAL_VALUE),
// Just a source that increments a number over time when
// you click buttons.
const source$ = merge(
// when we click "+ 1" it adds `1`
add1Click$.pipe(map(() => 1)),
// when we click "+ 2" it adds `2`
add2Click$.pipe(map(() => 2)),
).pipe(
// A reducer to accumlate our number
scan((acc, n) => acc + n, 0),
export default (
connect(
(
{ nodes },
{ id },
) => (
nodes[id]
)
)(
Node,