Skip to content

Instantly share code, notes, and snippets.

Avatar
🐦
tsers

Matti Lankinen milankinen

🐦
tsers
  • Finland
View GitHub Profile
@milankinen
milankinen / ServerOnly.js
Created Dec 9, 2015
React "ServerOnly" component
View ServerOnly.js
import React from "react"
import {findDOMNode} from "react-dom"
export default React.createClass({
componentWillMount() {
if (process.browser) {
this.setState({html: findDOMNode(this).innerHTML})
}
},
render() {
@milankinen
milankinen / ClientOnly.js
Created Dec 9, 2015
React ClientOnly component
View ClientOnly.js
/*
* <ClientOnly>
* <MyStuff />
* </ClientOnly>
*/
export default React.createClass({
getInitialState() {
return { allowRender: false }
},
componentDidMount() {
@milankinen
milankinen / clientti.js
Created Dec 2, 2015
injektio ilman he:tä
View clientti.js
const initial = JSON.parse(app.getAttribute('data-state'))
console.log(initial)
View clientti.js
const he = require("he")
const initial = JSON.parse(he.unescape(window.INITIAL_STATE))
console.log(initial)
View clientti.js
// 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 Dec 2, 2015
requirebin sketch
View index.js
// 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 Nov 5, 2015
megablob@0.3.0-alpha1 aka "microblob" \o/
View app.js
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 Nov 4, 2015
atomiperffiä
View app.js
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 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
}
@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() => {