Skip to content

Instantly share code, notes, and snippets.

View tribou's full-sized avatar

Aaron Tribou tribou

View GitHub Profile
@tribou
tribou / TodoConstants.js
Last active August 29, 2015 14:23
Todo app constants for React and Flux architecture
// Todo constants
module.exports = {
NEW_ITEM: 'NEW_ITEM',
SAVE_ITEM: 'SAVE_ITEM',
REMOVE_ITEM: 'REMOVE_ITEM'
};
@tribou
tribou / AppDispatcher.js
Last active August 29, 2015 14:23
Todo app dispatcher for React and Flux architecture
// Todo app dispatcher with actions responding to both
// view and server actions
var Dispatcher = require('flux').Dispatcher;
var AppDispatcher = new Dispatcher();
AppDispatcher.handleViewAction = function(action) {
this.dispatch({
source: 'VIEW_ACTION',
action: action
@tribou
tribou / TodoActions.js
Last active August 29, 2015 14:23
Todo app actions for React and Flux architecture
// Todo actions
var AppDispatcher = require('../dispatcher/AppDispatcher');
var TodoConstants = require('../constants/TodoConstants');
module.exports = {
addItem: function() {
AppDispatcher.handleViewAction({
actionType: TodoConstants.NEW_ITEM
});
@tribou
tribou / TodoStore.js
Last active August 29, 2015 14:23
Todo app store for React and Flux architecture
// Todo store
//
// Requiring the Dispatcher, Constants, and
// event emitter dependencies
var AppDispatcher = require('../dispatcher/AppDispatcher');
var AppConstants = require('../constants/TodoConstants');
var ObjectAssign = require('object-assign');
var EventEmitter = require('events').EventEmitter;
var CHANGE_EVENT = 'change';
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Todo App</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
@tribou
tribou / TodoIndex.jsx
Last active August 29, 2015 14:24
Todo app components for React and Flux architecture
// React components
var React = require('react');
var TodoStore = require('../stores/TodoStore');
var TodoActions = require('../actions/TodoActions');
var TodoItem = React.createClass({
render: function() {
return(
// Todo constants
module.exports = {
NEW_ITEM: 'NEW_ITEM',
SAVE_ITEM: 'SAVE_ITEM',
REMOVE_ITEM: 'REMOVE_ITEM',
GET_RANDOM: 'GET_RANDOM',
GET_RANDOM_RESPONSE: 'GET_RANDOM_RESPONSE'
};
// Todo server actions
var AppDispatcher = require('../dispatcher/AppDispatcher');
var TodoConstants = require('../constants/TodoConstants');
module.exports = {
receiveRandom: function(response) {
AppDispatcher.handleServerAction({
actionType: TodoConstants.GET_RANDOM_RESPONSE,
response: response
// Todo actions
var AppDispatcher = require('../dispatcher/AppDispatcher');
var TodoConstants = require('../constants/TodoConstants');
var RandomUserAPI = require('../utils/RandomUserAPI');
module.exports = {
addItem: function() {
AppDispatcher.handleViewAction({
actionType: TodoConstants.NEW_ITEM
// Random User API logic
var TodoServerActions = require('../actions/TodoServerActions');
var request = require('superagent');
module.exports = {
get: function() {
request.get('http://api.randomuser.me/')
.set('Accept', 'application/json')
.end(function(err, response) {