Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Last active April 11, 2017 23:42
Show Gist options
  • Save jongacnik/171850792f3431fa85cf43f7f34b1955 to your computer and use it in GitHub Desktop.
Save jongacnik/171850792f3431fa85cf43f7f34b1955 to your computer and use it in GitHub Desktop.
choo renderers
var Inferno = require('inferno')
var hyperx = require('hyperx')
var html = hyperx(require('inferno-create-element'))
function infernoRenderer (state, emit, renderer) {
renderer.render = function (tree, newTree, root) {
return Inferno.render(newTree, root)
}
renderer.mount = function (tree, root) {
return Inferno.render(tree, root)
}
}
var preact = require('preact')
var hyperx = require('hyperx')
var html = hyperx(preact.h)
function preactRenderer (state, emit, renderer) {
renderer.render = function (tree, newTree, root) {
return preact.render(newTree, root, tree)
}
renderer.mount = function (tree, root) {
return preact.render(tree, root)
}
}
var React = require('react')
var ReactDOM = require('react-dom')
var hyperx = require('hyperx')
var html = hyperx(React.createElement)
function reactRenderer (state, emit, renderer) {
renderer.render = function (tree, newTree, root) {
return ReactDOM.render(newTree, root)
}
renderer.mount = function (tree, root) {
return ReactDOM.render(tree, root)
}
}
var html = require('snabby')
function snabbyRenderer (state, emit, renderer) {
renderer.render = function (tree, newTree, root) {
html.update(tree, newTree)
return newTree
}
renderer.mount = function (tree, root) {
html.update(root, tree)
return tree
}
}
var vdom = require('virtual-dom')
var hyperx = require('hyperx')
var html = hyperx(vdom.h)
var rootNode
function vdomRenderer (state, emit, renderer) {
renderer.render = function (tree, newTree, root) {
var patches = vdom.diff(tree, newTree)
rootNode = vdom.patch(rootNode, patches)
return newTree
}
renderer.mount = function (tree, root) {
rootNode = vdom.create(tree)
root.appendChild(rootNode)
return tree
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment