(OLD - not relevent anymore, es2015 updated guide will be on craftsy github soon)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function CartItems({items, addToCart}) { | |
return ( | |
<div> | |
<h3>Current Cart:</h3> | |
{items.map((item)=>CartItem(item, addToCart))} | |
</div> | |
) | |
} | |
export function CartItem({name}, addToCart) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update(data) { | |
return fetch('/api/update', { | |
method: 'put', | |
body: JSON.stringify(data), | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
} | |
}) | |
.then(checkStatus) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
atom settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let multiparty = require('multiparty'); | |
let fs = require('fs'); | |
function saveImage(req, res) { | |
let form = new multiparty.Form(); | |
form.parse(req, (err, fields, files) => { | |
let {path: tempPath, originalFilename} = files.imageFile[0]; | |
let copyToPath = "./images/" + originalFilename; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uploadImage(imageFile) { | |
return new Promise((resolve, reject) => { | |
let imageFormData = new FormData(); | |
imageFormData.append('imageFile', imageFile); | |
var xhr = new XMLHttpRequest(); | |
xhr.open('post', '/upload', true); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codepen.io/hartzis/pen/VvNGZP | |
class ImageUpload extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
file: '', | |
imagePreviewUrl: '' | |
}; | |
this._handleImageChange = this._handleImageChange.bind(this); | |
this._handleSubmit = this._handleSubmit.bind(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From - http://stackoverflow.com/questions/24335821/can-i-fastclick-reactjs-running-in-cordova/24345469#24345469 | |
// or use | |
// https://github.com/zilverline/react-tap-event-plugin | |
React.initializeTouchEvents(true) | |
var TouchClick = React.createClass({ |