Skip to content

Instantly share code, notes, and snippets.

View hartzis's full-sized avatar

(Brian) Emil Hartz hartzis

View GitHub Profile
@hartzis
hartzis / high-order-viewport-component-example.js
Created July 24, 2015 19:06
Higher-order React component example
//from - https://github.com/kriasoft/react-starter-kit/blob/master/docs/react-style-guide.md
//Higher-order React component example:
// withViewport.js
import React, { Component } from 'react';
import { canUseDOM } from 'react/lib/ExecutionEnvironment';
function withViewport(ComposedComponent) {
return class WithViewport extends Component {
atom settings
@hartzis
hartzis / clientSideFetch.js
Created October 6, 2015 01:20
client side fetch example
function update(data) {
return fetch('/api/update', {
method: 'put',
body: JSON.stringify(data),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(checkStatus)
@hartzis
hartzis / nodeSideFetch.js
Created October 6, 2015 01:23
node side fetch example with express and body-parser
let router = require('express').Router();
let bodyParser = require('body-parser');
// parse application/json
router.use(bodyParser.json());
router.put('/api/update', update);
function update(req, res) {
console.log('updating-', req.body);
@hartzis
hartzis / statelessFunctionalComponents.js
Last active November 7, 2015 21:30
Stateless functional components
export function CartItems({items, addToCart}) {
return (
<div>
<h3>Current Cart:</h3>
{items.map((item)=>CartItem(item, addToCart))}
</div>
)
}
export function CartItem({name}, addToCart) {
@hartzis
hartzis / react-style-guide-old.md
Created November 28, 2015 20:06
React style guide : react < v0.13
@hartzis
hartzis / List.jsx
Last active December 29, 2015 01:22
simply test react components
import Item from './Item';
export function List ({items}) {
return (
<div>
<p>Number in List: <span>{items.length}</span></p>
{items.map(item => <Item item={item}/>)}
</div>
)
}
@hartzis
hartzis / List-tests.js
Last active July 7, 2016 06:19
Enzyme Tape React Tests example List
import test from 'tape';
import React from 'react';
import { shallow } from 'enzyme';
import List from './List';
test('empty <List/>', (t)=> {
t.plan(1);
const emptyList = [];
const wrapper = shallow(<List items={emptyList} />);
@hartzis
hartzis / Item-tests.js
Last active December 27, 2015 19:29
Enzyme Tape React Tests example Item
test('basic <Item/>', (t)=> {
t.plan(1);
const basicItem = {id: 'one'};
const wrapper = shallow(<Item item={basicItem}/>);
t.equal(wrapper.find('div').text(), 'one');
});
const scientists = {
'alan' : {
fullname: 'Alan Mathison Turing',
dob: {month: 6, day: 23, year: 1912},
image: 'turing.jpg',
},
'grace' : {
fullname: 'Grace Brewster Murray Hopper',
dob: {month: 12, day: 9, year: 1906},
image: 'hopper.jpg',