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 Immutable = require('immutable') | |
const Range = Immutable.Range | |
const fib = n => { | |
switch (n) { | |
case 0: | |
return 1; | |
case 1: | |
return 1; | |
default: |
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
export const error = ComposedComponent => | |
class extends Component { | |
state = { display: 0 } | |
toggle = display => | |
this.setState({ display }) | |
reset = () => | |
this.toggle(0) |
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 mapState = ({ error }) => ({ error }) | |
const mapDispatch = dispatch => bindActionCreators({ showErr, cancelErr }, dispatch) | |
@connect(mapState, mapDispatch) | |
export const error = ComposedComponent => | |
class extends Component { | |
render = () => <div> | |
<ComposedComponent { ...this.props } | |
showErr={ this.props.showErr } | |
cancelErr={ this.props.cancelErr } /> |
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 'rx' | |
import Cycle from '@cycle/core' | |
import {h, div, input, h2, makeDOMDriver} from '@cycle/dom' | |
/* utils */ | |
const renderWeightSlider = weight => div([ | |
`Weight${weight}kg`, | |
input('#weight', {type: 'range', min: 40, max: 140, value: weight})]) | |
const renderHeightSlider = height => div([ |
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' | |
const Node = ({ data }) => { | |
if (data instanceof Array) | |
return <ol>{ data.map(i => <Node data={ data[i - 1] } key={ i } />) }</ol> | |
else if (data instanceof Object) | |
return <ul>{ Object.keys(data).map(i =><Node data={ data[i] } key={ i } />) }</ul> | |
else | |
return <li>{ data }</li> | |
} |
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 { Observable } from 'rx' | |
const { fromEvent } = Observable | |
const $app = document.querySelector('#app') | |
$app.innerText = 'app' | |
const one = () => 1 | |
const sum = (x, y) => x + y | |
fromEvent($app, 'click') |
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 { Observable } from 'rx' | |
import { run } from '@cycle/core' | |
import { makeDOMDriver, hJSX } from '@cycle/dom' | |
import { makeHTTPDriver } from '@cycle/http' | |
const { of, just, combineLatest } = Observable | |
const square = x => x * x | |
const bmi = (weight, height) => | |
Math.round(weight / square(height * 0.01)) |
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 { run } from '@cycle/core' | |
import { makeDOMDriver, hJSX } from '@cycle/dom' | |
import { makeHTTPDriver } from '@cycle/http' | |
import isolate from '@cycle/isolate' | |
import { Observable } from 'rx' | |
const { of, combineLatest } = Observable | |
const LabeledSlider = ({ DOM, props$ }) => { | |
const initialValue$ = props$.map(({ initial }) => initial).first() |
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 makeReactDriver = query => | |
reactElement$ => | |
reactElement$.subscribe(reactElement => | |
render(reactElement, document.querySelector(query))) | |
const main = ({ react }) => { | |
return { | |
react: of(<h2>hello</h2>) | |
} | |
} |
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 { Observable, Subject } from 'rx' | |
const { timer, fromEvent } = Observable | |
/* --- logic --- */ | |
const main = DOM => | |
DOM.startWith(null) | |
.flatMapLatest( | |
() => timer(0, 100).map( | |
i => `seconds elapsed ${i}`)) |