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 React from 'react' | |
import ReactDOM from 'react-dom' | |
import { reactive } from 'rxjs-react' | |
import { from, merge } from 'rxjs' | |
import { map, delay, startWith } from 'rxjs/operators' | |
@reactive | |
class App extends React.Component { | |
data$ = from(fetch(this.props.url).then(res => res.json())).pipe(delay(1000)) | |
render() { |
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 React from 'react' | |
import ReactDOM from 'react-dom' | |
import { reactive } from 'rxjs-react' | |
import { from, merge, of } from 'rxjs' | |
import { map } from 'rxjs/operators' | |
const ComponentA = () => <div>component A</div> | |
const Loading = () => <div>loading...</div> | |
const fakeImportComponentA = () => | |
new Promise(resovle => { |
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 recursive = f => { | |
let isCalling = false | |
let proxy = (...args) => { | |
if (isCalling) throw args | |
while (true) { | |
try { | |
isCalling = true | |
return f(...args) | |
} catch(params) { | |
if (params instanceof Error) throw params |
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 { interval, isObservable } from 'rxjs' | |
import { tap } from 'rxjs/operators' | |
const type = { | |
isThenable: obj => !!(obj && typeof obj.then === 'function'), | |
isObservable: obj => !!(obj && isObservable(obj)), | |
isError: obj => obj instanceof Error, | |
isObject: obj => obj != null && typeof obj === 'object' | |
} |
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
var noop = () => {} | |
var compose = (f1, f2) => (...args) => f1(f2(...args)) | |
var range = (start, end) => { | |
let n = start | |
let f = (next, complete) => { | |
if (n <= end) { | |
next(n++) | |
f(next, complete) | |
} else { | |
complete() |
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
// parser combintor | |
const join = separator => value => value.join(separator) | |
const predicate = f => input => { | |
if (input && f(input[0])) { | |
return { | |
value: input[0], | |
remain: input.slice(1) | |
} | |
} |
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 interval = period => sink => { | |
let timer | |
let i = 0 | |
let next = () => sink.next(i++) | |
let start = () => { | |
timer = setInterval(next, period) | |
} | |
let finish = () => { | |
clearInterval(timer) | |
sink.finish() |
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
// parser combinator | |
const fail = () => [] | |
const failed = list => list.length === 0 | |
const of = value => input => [value, input] | |
const bind = (parser, f) => input => { | |
let result = parser(input) |
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 identity = x => x | |
const noop = () => {} | |
const pipe = (...args) => args.reduce((a, f) => f(a)) | |
const create = producer => sink => { | |
let isFinish = false | |
let wrap = f => a => { | |
if (isFinish) return | |
if (f) f(a) |
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
// parser combinator | |
const pipe = (...args) => args.reduce((a, f) => f(a)) | |
const Deferred = () => { | |
let resolve, reject | |
let promise = new Promise((a, b) => { | |
resolve = a | |
reject = b | |
}) |