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
/** | |
* 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 ( |
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
/** | |
* 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
/** | |
* 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') |
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
/** | |
* 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} /> |
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
/** | |
* 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 /> |
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
/** | |
* 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 |
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
/** | |
* todoItem.js - An individual item in the TODO list as an Immutable record | |
*/ | |
export default class TodoItem extends Immutable.Record({ | |
id: '', | |
complete: false, | |
text: '' | |
}) { | |
constructor(text,complete = false) { | |
super({id: genID(), text, complete}); |
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
/* | |
* 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)) { |