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 / ClientOnly.js
Created December 9, 2015 07:55
React ClientOnly component
/*
* <ClientOnly>
* <MyStuff />
* </ClientOnly>
*/
export default React.createClass({
getInitialState() {
return { allowRender: false }
},
componentDidMount() {
@milankinen
milankinen / clientti.js
Created December 2, 2015 08:42
injektio ilman he:tä
const initial = JSON.parse(app.getAttribute('data-state'))
console.log(initial)
@milankinen
milankinen / clientti.js
Created December 2, 2015 08:37
injektio #2
const he = require("he")
const initial = JSON.parse(he.unescape(window.INITIAL_STATE))
console.log(initial)
@milankinen
milankinen / clientti.js
Created December 2, 2015 08:35
injektio #1
// bundlen entry point
const he = require("he")
const initial = JSON.parse(he.unescape(document.getElementById("state").innerHTML))
console.log(initial)
@milankinen
milankinen / index.js
Created December 2, 2015 08:13
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
@milankinen
milankinen / app.js
Last active November 5, 2015 14:22
megablob@0.3.0-alpha1 aka "microblob" \o/
import React from "react"
import {render} from "react-dom"
import Bacon from "baconjs"
import {sum} from "lodash"
import {atom} from "megablob"
import {Combinator} from "megablob/react"
function init() {
@milankinen
milankinen / app.js
Last active November 4, 2015 22:34
atomiperffiä
import React from "react"
import Bacon from "baconjs"
import {render} from "react-dom"
import {range, sum} from "lodash"
import combineAsComponent from "./combineAsComponent"
import Atom from "./atom"
@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
}
@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 / 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)