Skip to content

Instantly share code, notes, and snippets.

Avatar
🐦
tsers

Matti Lankinen milankinen

🐦
tsers
  • Finland
View GitHub Profile
@milankinen
milankinen / dev
Last active Aug 29, 2015
react-router with LiveReactload
View dev
#!/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
react-router with livereactload 0.5.2
View example.js
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 Aug 29, 2015
Bacon.js optimistic/pessimistic updates
View optimistic.js
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 Sep 25, 2015
Bacon.js flatMapFirst
View index.js
const Bacon = require("baconjs")
Bacon
.sequentially(10, [1, 2, 3, 4, 5])
.flatMapFirst(val => Bacon.later(25, val))
.subscribe(console.log.bind(console))
View aspect_example.coffee
class MyClass
foo: ->
alert "foobar"
bar: ->
alert "barfoo"
@foo()
View gist:4261912
class MyClass
simple: ->
alert "hello!"
another: ->
alert "hi!"
withParams: (a, b) ->
alert a + " - " + b
withReturnValue: (a) ->
return 2 * a
@milankinen
milankinen / application.js
Created Oct 23, 2015
Bottom-up-MÖLLYKKÄ
View application.js
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 Nov 3, 2015
React VDOM(Bacon.Observable) => Bacon.Observable(VDOM)
View liftVDOM.js
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 Nov 3, 2015
Pekonimmmmehustelua
View app.js
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 Nov 4, 2015
React reactive swiss army knife
View counterz.js
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
}
You can’t perform that action at this time.