This file contains hidden or 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
var subscribers = [] | |
var subscribe = function(subscriber) { | |
subscribers | |
.push(subscriber) | |
} | |
var dispatch = function(action) { | |
stateModifiers[action.type] | |
&& stateModifiers[action.type](action) |
This file contains hidden or 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
var createStore = function(stateModifiers) { | |
var localState = { | |
subscribers: [], | |
} | |
var subscribe = function(subscribers) { | |
localState | |
.subscribers = ( | |
localState | |
.subscribers |
This file contains hidden or 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
var actions = { | |
UPDATE_IDS: function(action) { | |
vm.ids = action.ids | |
}, | |
UPDATE_PRIVILAGES: function(action) { | |
vm.privileges = action.privileges | |
}, | |
} | |
var dispatch = function( |
This file contains hidden or 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
var dispatch = function(action) { | |
stateModifiers[action.type] | |
&& stateModifiers[action.type](action) | |
return action | |
} |
This file contains hidden or 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 { 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(({ |
This file contains hidden or 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 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. |
This file contains hidden or 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
/** | |
* 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. |
This file contains hidden or 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 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), |
This file contains hidden or 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
// 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), |
This file contains hidden or 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
export default ( | |
connect( | |
( | |
{ nodes }, | |
{ id }, | |
) => ( | |
nodes[id] | |
) | |
)( | |
Node, |