Skip to content

Instantly share code, notes, and snippets.

View sebjwallace's full-sized avatar

Sebastian Wallace sebjwallace

  • United Kingdom
View GitHub Profile
.Media {
display: flex;
align-items: stretch;
}
.Media__image {
margin-right: 1em;
}
.Media__body {
function extend(base, derivative){
for(var i in base)
if(!derivative[i])
derivative[i] = base[i]
return derivative
}
var base = {
color: '#555',
fontSize: '2em'
function styles(padding){
return {
padding: padding + 'px',
backgroundColor: '#ddd'
}
}
function Hello(name, styles){
return ["div", {style:styles}, "Hello " + name]
}
function Hello(name){
return ["div", null,
["b", null, "Hello "],
["i", null, name]
];
}
function prerender(root){
for(var i in root)
if(Array.isArray(root[i]))
function Hello(name){
return ["div", null, "Hello " + name];
}
ReactDOM.render(
React.createElement.apply(this, Hello('world')),
document.getElementById('container')
);
function Hello(name){
return React.createElement("div", null, "Hello " + name);
}
ReactDOM.render(
Hello("World"),
document.getElementById('container')
);
@sebjwallace
sebjwallace / no_JSX.js
Last active April 22, 2016 10:25
Less React, more JS
// https://jsfiddle.net/reactjs/5vjqabv3/
var Hello = React.createClass({
displayName: 'Hello',
render: function() {
return React.createElement("div", null, "Hello ", this.props.name);
}
});
ReactDOM.render(
@sebjwallace
sebjwallace / shallowMerge.js
Created April 9, 2016 18:07
Shallow merge objects without overwriting or mutation
function mergeObjects(merger,mergee){
var mergent = {};
for(var prop in mergee){
mergent[prop] = mergee[prop]
}
for(prop in merger){
if(mergent[prop])
mergent[prop] = mergeObjects(mergent[prop],merger[prop])
else mergent[prop] = merger[prop]
@sebjwallace
sebjwallace / README.md
Last active April 9, 2016 15:52
Convert an array-tree into an vTree

Writing hyperscript can get tedious when repeating this syntax for every element.

h('div', 'this is an element', [
  h('ul', [
    h('li', 'writing all these h calls')
    h('li', 'can get boring...')
  ])  
])
@sebjwallace
sebjwallace / README.md
Last active April 8, 2016 14:58
virtual-dom todos <100 LOC

This was a small challenge to write a standard and unstyled todos app within 100 lines of code, while maintaining readability.

It can be found on JS Bin

This project was to also prove that components are nothing more than a function that returns a vTree. The only purpose of creating an instance of the component is to maintain internal state. If there is none, then a component can just be a pure function.

Although a trivial application, it might also demonstrate that such things can be built without frameworks or virtual-dom libraries - only the virtual-dom is needed.

I did use my own fork from the virtual-dom repo for this project so that I could use the vDOM object.