{"id":19916830,"url":"https://github.com/srackham/flux-backbone-todo","last_synced_at":"2025-05-03T06:30:35.799Z","repository":{"id":23687506,"uuid":"27059247","full_name":"srackham/flux-backbone-todo","owner":"srackham","description":"Didactic Todo app written using Flux, Backbone and React.","archived":false,"fork":false,"pushed_at":"2024-07-30T17:17:19.000Z","size":1196,"stargazers_count":9,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T00:14:36.646Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srackham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-24T03:36:56.000Z","updated_at":"2024-10-10T04:49:20.000Z","dependencies_parsed_at":"2022-08-22T04:10:25.995Z","dependency_job_id":null,"html_url":"https://github.com/srackham/flux-backbone-todo","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fflux-backbone-todo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fflux-backbone-todo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fflux-backbone-todo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fflux-backbone-todo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srackham","download_url":"https://codeload.github.com/srackham/flux-backbone-todo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252154732,"owners_count":21702982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T21:47:44.960Z","updated_at":"2025-05-03T06:30:35.488Z","avatar_url":"https://github.com/srackham.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flux Backbone Todos Example\n\n- **[Version 1.4.0](https://github.com/srackham/flux-backbone-todo/tree/1.2.0)** (4 April 2015), added functional tests using Zombie + Mocha.\n- **[Version 1.3.0](https://github.com/srackham/flux-backbone-todo/tree/1.2.0)** (19 March 2015), eslint checks; deploy live demo.\n- **[Version 1.2.0](https://github.com/srackham/flux-backbone-todo/tree/1.2.0)** (23 December 2014), convert app to ES6 using 6to5 transpiler.\n- **[Version 1.1.0](https://github.com/srackham/flux-backbone-todo/tree/1.1.0)** (30 November 2014), persist Todos to LocalStorage.\n- **[Version 1.0.0](https://github.com/srackham/flux-backbone-todo/tree/1.0.0)** (14 November 2014).\n\nThis didactic Todo app was written to illustrate the\n[Flux](http://facebook.github.io/react/blog/2014/05/06/flux.html) DSV\n(Dispatch Store View) design pattern.\n\n[Live Demo](http://srackham.github.io/flux-backbone-todo/)\n\nFlux is a design pattern for building scaleable applications using a\nUnidirectional Data Flow (it is not a Web development framework), the\nFlux library implements a\n[Dispatcher](http://facebook.github.io/flux/docs/dispatcher.html).\nwhich works well with the Flux design pattern.\n\nThe Todo app is implemented using\n[Flux](http://facebook.github.io/react/blog/2014/05/06/flux.html),\n[Backbone](http://backbonejs.org/) and\n[React](http://facebook.github.io/react/index.html).\n\n\n## Architecture and Implementation\nThe Flux/React combination results in a highly decoupled declarative\napplication structure. Here is the actual code:\n\n    var dispatcher = new Flux.Dispatcher();\n    var todoStore = new TodoStore([], {dispatcher: dispatcher});\n\n    React.render(\n        \u003cdiv\u003e\n          \u003ch3\u003eTodos\u003c/h3\u003e\n          \u003cTodoFormComponent store={todoStore} /\u003e\n          \u003cTodoListComponent store={todoStore} /\u003e\n          \u003cp\u003e\n          Want a second fully synchronized list? Just declare another list component: no code required,\n          no events to wire up!\n          \u003c/p\u003e\n          \u003cTodoListComponent store={todoStore} /\u003e\n        \u003c/div\u003e,\n        document.getElementById('app')\n    );\n\nJust declare the Dispatcher, Store and View and you're done. The\nFlux unidirectional _Dispatcher-\u003eStore-\u003eView_ dependencies are\nobvious.\n\n- The `todoStore` is passed the `dispatcher` (as a constructor\n  argument) when it is instantiated.\n\n- UI components that display or update the Todo list are passed the\n  `todoStore` (as a property) when they are instantiated.\n\nDisplaying a second fully synchronized Todo list is a bit nonsensical\nbut it graphically illustrates the power of the Flux architecture --\ntry doing this in any other framework.\n\n\n## Data flow\nData flows unidirectionally in a circular path\n_Dispatcher-\u003eStore-\u003eView-\u003eDispatcher-\u003e ..._:\n\n- The `todoStore` listens for `dispatcher` actions (messages) and updates\n  itself in response to these messages.\n\n- UI components listen for Backbone events from the `todoStore`\n  informing them of changes to the store that need to be displayed in\n  the UI.\n\n- UI components send actions (messages) to the `dispatcher` in\n  response to user input -- components do not mutate the store\n  directly.\n\n\n## The Store\n- The store is a Black Box containing the application's state and the\n  logic to execute dispatcher actions which update (mutate) the store.\n- Externally there is no way to mutate the store other than indirectly\n  via dispatcher actions.\n- The store emits change events to subscribers (UI view components).\n- The store has no knowledge of its external environment.\n\nBackbone is used to implement a pub/sub data store for the Todos list\nwith Backbone Models and Collections (Backbone is not used as a\ndevelopment framework). Backbone unburdens the app from having to\nimplement a pub/sub event emitter for the store (as well as providing\na rich model/collection API).\n\nStoring the component state in a mutative Backbone store instead of\nusing an immutable component `State` object means we need to use the\nReact\n[forceUpdate](http://facebook.github.io/react/docs/component-api.html#forceupdate)\nAPI which could have performance implications for complex React UIs.\nSee this [excellent\ndiscussion](http://stackoverflow.com/questions/21709905/can-i-avoid-forceupdate-when-using-react-with-backbone)\nexplains the issue and, if necessary, strategies to resolve it.  React\ndoes a great job of DOM update optimization so I would stick with the\nsimplicity of using `forceUpdate` until confronted with a real\nuse-case to the contrary.\n\n`TodoStore` collection and `TodoItem` models are passed a Flux\ndispatcher when they are instantiated. `TodoItem` models are\ninstantiated by the Backbone Collection `add` method which passes the\ndispatcher option to the `TodoItem` model's `initialize` function.\n\n\n## Building and Running\nThe app is developed and built in a node/npm environment. To install\nand run:\n\n1. Make sure you have node and npm installed.\n\n2. Clone the Github repo:\n\n        git clone https://github.com/srackham/flux-backbone-todo.git\n\n3. Install npm dependencies:\n\n        cd flux-backbone-todo\n        npm install\n\n4. Build the app `app/bundle.js` bundle (although JQuery is not\n  required by Backbone I had to include it to satisfy webpack which\n  thought it was a dependency):\n\n        webpack\n\n5. Start the app in a server:\n\n        npm start\n\n6. Open your Web browser at \u003chttp://localhost:8888/\u003e.\n\n\n## Lessons learnt\n- As always in JavaScript, when you pass a callback you need to ensure\n  that they are bound to the correct context. In the following example\n  the Backbone Model event handler's context is bound to the current\n  object:\n\n        this.props.store.on('change',\n            function() {\n              this.forceUpdate();\n            }.bind(this)\n        );\n\n- When binding you need to take caller and callee arguments into\n  consideration. The previous example can be simplified by passing\n  `forceUpdate` as the change handler callback, but if you do not\n  remember to explicitly bind the `forceUpdate` first argument to\n  `null` the program will throw an error because `forceUpdate` would\n  be called by the Backbone event dispatcher with a first argument\n  that is not a callback (namely the changed Backbone model):\n\n        this.props.store.on('change',\n          this.forceUpdate.bind(this, null)\n        );\n\n- Backbone Model attributes are not model properties -- access them\n  with `get()` and `set()` not with the dot syntax.\n\n- I spent far to much time debugging what is a very simple\n  application, most of the time could have been saved if I had been\n  using a language with type checking -- _ES6 + JSX + type\n  annotations + type checking_  would be nice (this is a criticism of\n  JavaScript in general, not of the application architecture or the\n  tools).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrackham%2Fflux-backbone-todo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrackham%2Fflux-backbone-todo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrackham%2Fflux-backbone-todo/lists"}