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
/** | |
* 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) { |
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
/** | |
* 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); |
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
const Message = Immutable.Record({ | |
id: '', | |
threadID: '', | |
threadName: '', | |
authorName: '', | |
text: '', | |
date: new Date(), | |
isRead: false | |
}); |
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
/** | |
* Contents of a single conversation (message thread) sharing a common thread ID | |
* | |
* We use a SortedMap and add messages in chronological order | |
*/ | |
export default class Thread extends Immutable.Record({ | |
messageIdMap: Immutable.OrderedMap() // map from id to Message, ordered by date | |
}) { | |
/* | |
* add or update the message by its message id |
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
/** | |
* | |
* 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(); |
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
import EventEmitter from 'events'; | |
export class Ref extends EventEmitter { | |
constructor(v) { | |
super(); | |
this._value = v; | |
} | |
getValue() { |
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
/* | |
* fill view by generating more requests if necessary | |
*/ | |
function fillView(st,updater) { | |
const lastSith = st.lastKnownSith(); | |
if (st.needsApprentice(lastSith)) { | |
requestSithInfo(true,lastSith.info.apprenticeId,updater); | |
} else { | |
const firstSith = st.firstKnownSith(); | |
if (st.needsMaster(firstSith)) { |
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 scroll(scrollAmount,updater) { | |
updater((prevState) => { | |
const {nextState, oldRequests} = prevState.scrollAdjust(scrollAmount); | |
oldRequests.forEach((req) => req.abort()); // cancel old requests | |
// Need invokeLater since we're within updater | |
invokeLater(() => fillView(nextState,updater)); | |
return nextState; | |
}); | |
} |
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 invokeLater(f) { | |
window.setTimeout(f, 0); | |
} |
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
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 |