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 Bacon from "baconjs" | |
import React from "react" | |
import {cloneAndReplaceProps, isValidElement} from "react/lib/ReactElement" | |
import {find, isEmpty} from "lodash" | |
/** | |
* Transforms: VDOM(Observable) => Observable(VDOM) | |
* Example: | |
* const a = Bacon.constant(4) | |
* const b = Bacon.constant(3) |
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 {combineAsArray} from "baconjs" | |
import Counter from "./components/counter" | |
import BigList from "./components/bigList" | |
export default initialState => ( | |
combineAsArray(Counter(initialState), BigList()).map( | |
([$counter, $list]) => ( | |
<div> | |
<h1>Tsers!</h1> |
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 Bacon = require("baconjs") | |
Bacon | |
.sequentially(10, [1, 2, 3, 4, 5]) | |
.flatMapFirst(val => Bacon.later(25, val)) | |
.subscribe(console.log.bind(console)) |
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 Bacon = require("baconjs") | |
/** | |
* flatUpdate :: (state, [Observable+, [(state,...events)=>Observable<A>, (state, A)=>newState]]+) => Observable<state> | |
* | |
* const stateP = flatUpdate(initialState, | |
* [event1S], (state, newState) => newState, // supports normal Bacon.update | |
* [event2S], (state, newState) => Bacon.later(100, newState) // supports delayed state updating | |
* [event3S], [submitForm, handleSubmitResult] // supports 2-stage state updating | |
* ) |
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
module.exports = { | |
toProperty(initialItems) { | |
const updateItemS = | |
d.stream("item:update") | |
const updateResultS = | |
updateItemS | |
.flatMapLatest(data => Bacon.fromPromise(server.updateItem(data))) | |
.mapError({result: "failure", msg: "Server error"}) |
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 React = require('react'), | |
Router = require('react-router'), | |
lrApi = require('livereactload-api') | |
var { Route, RouteHandler, Link } = Router | |
var App = React.createClass({ | |
contextTypes: { | |
router: React.PropTypes.func |
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
#!/bin/bash | |
node_modules/.bin/nodemon --ignore public/bundle.js & | |
{ { node_modules/.bin/watchify site.js -v -t babelify -g livereactload -o static/bundle.js 1>&2; } 2>&1 \ | |
| while read result; do | |
echo "$result" | |
[[ "$result" =~ ^[0-9]+[[:space:]]bytes[[:space:]]written ]] && node_modules/.bin/livereactload notify | |
done | |
} & |
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
object OrderingDSL { | |
case class AscendingOrder[T](value: T)(implicit ord: Ordering[T]) extends Ordered[AscendingOrder[T]] { | |
def compare(that: AscendingOrder[T]): Int = ord.compare(value, that.value) | |
} | |
case class DescendingOrder[T](value: T)(implicit ord: Ordering[T]) extends Ordered[DescendingOrder[T]] { | |
def compare(that: DescendingOrder[T]): Int = -ord.compare(value, that.value) | |
} | |
def asc[T](value: T)(implicit ord: Ordering[T]) = AscendingOrder(value) |
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
object OrderingDSLExample extends App { | |
case class My(num: Int, str: String) | |
val myValues = List(My(3, "foo"), My(3, "bar"), My(5, "bar"), My(5, "foo")) | |
import OrderingDSL._ | |
require(myValues.sortBy(m => (asc(m.num), asc(m.str))) == | |
List(My(3, "bar"), My(3, "foo"), My(5, "bar"), My(5, "foo"))) | |
require(myValues.sortBy(m => (asc(m.num), desc(m.str))) == | |
List(My(3, "foo"), My(3, "bar"), My(5, "foo"), My(5, "bar"))) |
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
<script type="text/x-template" id="person-form-template"> | |
<div class="form-horizontal"> | |
<div class="control-group"> | |
<label class="control-label" for="name">Name</label> | |
<div class="controls"><input class="input" type="text" name="name" id="name" value="{{name}}" /></div> | |
</div> | |
<div class="control-group"> | |
<label class="control-label" for="age">Age</label> | |
<div class="controls"><input class="input" type="number" name="age" id="age" value="{{age}}" /></div> | |
</div> |