Skip to content

Instantly share code, notes, and snippets.

View milankinen's full-sized avatar
🐦
tsers

Matti Lankinen milankinen

🐦
tsers
View GitHub Profile
@milankinen
milankinen / dev
Last active August 29, 2015 14:18
react-router with LiveReactload
#!/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
} &
@milankinen
milankinen / example.js
Created May 28, 2015 20:02
react-router with livereactload 0.5.2
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
@milankinen
milankinen / optimistic.js
Last active August 29, 2015 14:22
Bacon.js optimistic/pessimistic updates
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"})
@milankinen
milankinen / index.js
Last active September 25, 2015 09:56
Bacon.js flatMapFirst
const Bacon = require("baconjs")
Bacon
.sequentially(10, [1, 2, 3, 4, 5])
.flatMapFirst(val => Bacon.later(25, val))
.subscribe(console.log.bind(console))
@milankinen
milankinen / aspect_example.coffee
Created November 24, 2012 13:56
Coffeescript aspects
class MyClass
foo: ->
alert "foobar"
bar: ->
alert "barfoo"
@foo()
@milankinen
milankinen / gist:4261912
Created December 11, 2012 20:33
Aspect examples
class MyClass
simple: ->
alert "hello!"
another: ->
alert "hi!"
withParams: (a, b) ->
alert a + " - " + b
withReturnValue: (a) ->
return 2 * a
@milankinen
milankinen / application.js
Created October 23, 2015 10:25
Bottom-up-MÖLLYKKÄ
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>
@milankinen
milankinen / liftVDOM.js
Last active November 3, 2015 10:34
React VDOM(Bacon.Observable) => Bacon.Observable(VDOM)
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)
@milankinen
milankinen / app.js
Last active November 3, 2015 12:40
Pekonimmmmehustelua
import React from "react"
import Bacon from "baconjs"
import {render} from "react-dom"
import liftVDOM from "./liftVDOM"
import combineAsComponent from "./combineAsComponent"
import Atom from "./atom"
function initApp() => {
@milankinen
milankinen / counterz.js
Created November 4, 2015 13:44
React reactive swiss army knife
import React from "react"
import Bacon from "baconjs"
import {render} from "react-dom"
function Counter(initial) {
const incBus = new Bacon.Bus()
const value = incBus.map(1).scan(initial, (state, inc) => state + inc)
value.inc = () => incBus.push()
return value
}