Skip to content

Instantly share code, notes, and snippets.

@antonycourtney
antonycourtney / todoAppState.js
Last active October 19, 2015 02:34
Purely functional data structure for Todo list application state
/**
* todoAppState.js -- Application State for TodoMVC as
* an immutable record
*/
export default class TodoAppState extends Immutable.Record({
todoItems: Immutable.Map() // map from id to TodoItem
}) {
/**
* functional item update -- returns a new state with the given item included in the
* set of todo items. If there is an existing entry for item.id, the result state
@antonycourtney
antonycourtney / todoAppStatic.React.js
Last active October 19, 2015 02:36
top level app component for static version of app
/**
* todoApp.React.js -- top-level React component for TodoMVC
*/
export default class TodoApp extends React.Component {
render() {
const appState = this.props.appState;
const allTodos = appState.getAll();
return (
<div>
<Header />
@antonycourtney
antonycourtney / TodoApp.React.js
Last active October 19, 2015 02:36
Top level View component for TodoMVC app
/**
* todoApp.React.js -- top-level React component for TodoMVC
*/
export default class TodoApp extends React.Component {
render() {
const appState = this.props.appState;
const allTodos = appState.getAll();
return (
<div>
<Header stateRefUpdater={this.props.stateRefUpdater} />
@antonycourtney
antonycourtney / viewTest.js
Last active October 19, 2015 02:38
Test of static version of views
/**
* viewTest.js -- render TodoApp component with static test data
*/
const item0 = new TodoItem('This is a test item');
const state0 = new TodoAppState();
const todoAppState = state0.addItem(item0);
React.render(
<TodoApp appState={todoAppState} />,
document.getElementById('todoapp')
@antonycourtney
antonycourtney / todoActions.js
Last active October 19, 2015 02:42
Responses to user interaction in oneref-todomvc
/**
* todoActions.js -- event handlers for TodoMVC app
*/
import TodoItem from './todoItem';
export function create(text,updater) {
updater((state) => state.addItem(new TodoItem(text)));
}
export function toggleComplete(item,updater) {
@antonycourtney
antonycourtney / app.js
Last active October 19, 2015 02:43
Top level of React application
/**
* app.js -- top level of TodoMVC app
*/
import React from 'react';
import OneRef from 'oneref';
import TodoAppState from './todoAppState';
import TodoApp from './components/TodoApp.react';
const todoAppState = new TodoAppState();
const stateRef = new OneRef.Ref(todoAppState);
@antonycourtney
antonycourtney / Header.react.js
Last active October 19, 2015 02:49
React Header component for oneref-todomvc
/**
* Header.react.js -- React component for TodoMVC Header UI
*/
import React from 'react';
import TodoTextInput from './TodoTextInput.react';
import * as TodoActions from '../todoActions';
export default class Header extends React.Component {
render() {
return (
@antonycourtney
antonycourtney / invokeLater.js
Last active October 19, 2015 03:11
invokeLater for oneref
function invokeLater(f) {
window.setTimeout(f, 0);
}
@antonycourtney
antonycourtney / ChatAppState.js
Last active October 19, 2015 03:46
oneref-chat application state
/**
*
* ChatAppState.js - atate of Chat application as an Immutable record
*
* Our application state consists of a collection of message threads
* and a current thread (identified by its thread ID)
*
* Each thread id maps to a Thread (a collection of Message)
*/
const emptyThread = new Thread();
@antonycourtney
antonycourtney / Example1.elm
Last active November 8, 2015 06:00
Animaxe Example 1 in Elm
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import List exposing (..)
import Signal exposing (..)
import Time exposing (..)
import Array
-- a square of the given width and color:
square : Float -> Color -> Form