From 85339bfdae5cd622fb97dc8c681376ba24e847da Mon Sep 17 00:00:00 2001 From: fisherwebdev Date: Fri, 14 Mar 2014 10:37:56 -0700 Subject: [PATCH] TodoMVC Flux Example --- examples/todomvc-flux/css/app.css | 25 + examples/todomvc-flux/index.html | 19 + .../todomvc-flux/js/actions/TodoActions.js | 95 +++ examples/todomvc-flux/js/app.js | 26 + .../js/components/Footer.react.js | 84 +++ .../js/components/Header.react.js | 53 ++ .../js/components/MainSection.react.js | 71 +++ .../js/components/TodoApp.react.js | 79 +++ .../js/components/TodoItem.react.js | 108 ++++ .../js/components/TodoTextInput.react.js | 89 +++ .../js/constants/TodoConstants.js | 29 + .../js/dispatcher/AppDispatcher.js | 41 ++ .../todomvc-flux/js/dispatcher/Dispatcher.js | 125 ++++ examples/todomvc-flux/js/stores/TodoStore.js | 186 ++++++ examples/todomvc-flux/package.json | 32 + examples/todomvc-flux/readme.md | 100 ++++ .../todomvc-flux/todomvc-common/.bower.json | 14 + examples/todomvc-flux/todomvc-common/base.css | 556 ++++++++++++++++++ examples/todomvc-flux/todomvc-common/base.js | 209 +++++++ examples/todomvc-flux/todomvc-common/bg.png | Bin 0 -> 2126 bytes .../todomvc-flux/todomvc-common/bower.json | 4 + .../todomvc-flux/todomvc-common/readme.md | 8 + 22 files changed, 1953 insertions(+) create mode 100644 examples/todomvc-flux/css/app.css create mode 100644 examples/todomvc-flux/index.html create mode 100644 examples/todomvc-flux/js/actions/TodoActions.js create mode 100644 examples/todomvc-flux/js/app.js create mode 100644 examples/todomvc-flux/js/components/Footer.react.js create mode 100644 examples/todomvc-flux/js/components/Header.react.js create mode 100644 examples/todomvc-flux/js/components/MainSection.react.js create mode 100644 examples/todomvc-flux/js/components/TodoApp.react.js create mode 100644 examples/todomvc-flux/js/components/TodoItem.react.js create mode 100644 examples/todomvc-flux/js/components/TodoTextInput.react.js create mode 100644 examples/todomvc-flux/js/constants/TodoConstants.js create mode 100644 examples/todomvc-flux/js/dispatcher/AppDispatcher.js create mode 100644 examples/todomvc-flux/js/dispatcher/Dispatcher.js create mode 100644 examples/todomvc-flux/js/stores/TodoStore.js create mode 100644 examples/todomvc-flux/package.json create mode 100644 examples/todomvc-flux/readme.md create mode 100644 examples/todomvc-flux/todomvc-common/.bower.json create mode 100644 examples/todomvc-flux/todomvc-common/base.css create mode 100644 examples/todomvc-flux/todomvc-common/base.js create mode 100644 examples/todomvc-flux/todomvc-common/bg.png create mode 100644 examples/todomvc-flux/todomvc-common/bower.json create mode 100644 examples/todomvc-flux/todomvc-common/readme.md diff --git a/examples/todomvc-flux/css/app.css b/examples/todomvc-flux/css/app.css new file mode 100644 index 0000000000..2baee13e9a --- /dev/null +++ b/examples/todomvc-flux/css/app.css @@ -0,0 +1,25 @@ +/** + * Copyright 2013-2014 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * base.css overrides + */ + +/** + * We are not changing from display:none, but rather re-rendering instead. + * Therefore this needs to be displayed normally by default. + */ +#todo-list li .edit { + display: inline; +} \ No newline at end of file diff --git a/examples/todomvc-flux/index.html b/examples/todomvc-flux/index.html new file mode 100644 index 0000000000..e7660c5c82 --- /dev/null +++ b/examples/todomvc-flux/index.html @@ -0,0 +1,19 @@ + + + + + Flux • TodoMVC + + + + +
+ + + + + diff --git a/examples/todomvc-flux/js/actions/TodoActions.js b/examples/todomvc-flux/js/actions/TodoActions.js new file mode 100644 index 0000000000..ae86061a5e --- /dev/null +++ b/examples/todomvc-flux/js/actions/TodoActions.js @@ -0,0 +1,95 @@ +/** + * Copyright 2013-2014 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * TodoActions + */ + +var AppDispatcher = require('../dispatcher/AppDispatcher'); +var TodoConstants = require('../constants/TodoConstants'); + +var TodoActions = { + + /** + * @param {string} text + */ + create: function(text) { + AppDispatcher.handleViewAction({ + actionType: TodoConstants.TODO_CREATE, + text: text + }); + }, + + /** + * @param {string} id The ID of the ToDo item + * @param {string} text + */ + updateText: function(id, text) { + AppDispatcher.handleViewAction({ + actionType: TodoConstants.TODO_UPDATE_TEXT, + id: id, + text: text + }); + }, + + /** + * Toggle whether a single ToDo is complete + * @param {object} todo + */ + toggleComplete: function(todo) { + var id = todo.id; + if (todo.complete) { + AppDispatcher.handleViewAction({ + actionType: TodoConstants.TODO_UNDO_COMPLETE, + id: id + }); + } else { + AppDispatcher.handleViewAction({ + actionType: TodoConstants.TODO_COMPLETE, + id: id + }); + } + }, + + /** + * Mark all ToDos as complete + */ + toggleCompleteAll: function() { + AppDispatcher.handleViewAction({ + actionType: TodoConstants.TODO_TOGGLE_COMPLETE_ALL + }); + }, + + /** + * @param {string} id + */ + destroy: function(id) { + AppDispatcher.handleViewAction({ + actionType: TodoConstants.TODO_DESTROY, + id: id + }); + }, + + /** + * Delete all the completed ToDos + */ + destroyCompleted: function() { + AppDispatcher.handleViewAction({ + actionType: TodoConstants.TODO_DESTROY_COMPLETED + }); + } + +}; + +module.exports = TodoActions; diff --git a/examples/todomvc-flux/js/app.js b/examples/todomvc-flux/js/app.js new file mode 100644 index 0000000000..a2c793a22e --- /dev/null +++ b/examples/todomvc-flux/js/app.js @@ -0,0 +1,26 @@ +/** + * Copyright 2013-2014 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @jsx React.DOM + */ + +var React = require('react'); + +var TodoApp = require('./components/TodoApp.react'); + +React.renderComponent( + , + document.getElementById('todoapp') +); \ No newline at end of file diff --git a/examples/todomvc-flux/js/components/Footer.react.js b/examples/todomvc-flux/js/components/Footer.react.js new file mode 100644 index 0000000000..ba985b42e5 --- /dev/null +++ b/examples/todomvc-flux/js/components/Footer.react.js @@ -0,0 +1,84 @@ +/** + * Copyright 2013-2014 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @jsx React.DOM + */ + +var React = require('react'); +var ReactPropTypes = React.PropTypes; +var TodoActions = require('../actions/TodoActions'); + +var Footer = React.createClass({ + + propTypes: { + allTodos: ReactPropTypes.object.isRequired + }, + + /** + * @return {object} + */ + render: function() { + var allTodos = this.props.allTodos; + var total = Object.keys(allTodos).length; + + if (total === 0) { + return