{"id":18295109,"url":"https://github.com/codesuki/reactive-flux","last_synced_at":"2025-04-05T12:31:22.840Z","repository":{"id":26596533,"uuid":"30051365","full_name":"codesuki/reactive-flux","owner":"codesuki","description":"Fluxish model implemented with RxJS","archived":false,"fork":false,"pushed_at":"2017-01-24T09:04:33.000Z","size":23,"stargazers_count":73,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-21T03:51:15.754Z","etag":null,"topics":["flux","javascript","js","no-dispatcher","react","reactive-extensions","rxjs"],"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/codesuki.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":"2015-01-30T02:00:15.000Z","updated_at":"2022-02-09T08:33:50.000Z","dependencies_parsed_at":"2022-08-28T03:01:48.466Z","dependency_job_id":null,"html_url":"https://github.com/codesuki/reactive-flux","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Freactive-flux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Freactive-flux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Freactive-flux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Freactive-flux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codesuki","download_url":"https://codeload.github.com/codesuki/reactive-flux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247338753,"owners_count":20922994,"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":["flux","javascript","js","no-dispatcher","react","reactive-extensions","rxjs"],"created_at":"2024-11-05T14:33:27.256Z","updated_at":"2025-04-05T12:31:17.829Z","avatar_url":"https://github.com/codesuki.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reactive-flux\n\n\u003e Fluxish model implemented with RxJS\n\nI was trying to use React + Flux to build a Dashboard but while reading Flux tutorials I already started to dislike the switch statements and constants that are all over the place.\n\nReact and the Flux architecture seem to fit well with RxJS, so this is my take on it.\n\nThis is my first JavaScript code so feel free to send pull requests and let me know of any bugs or improvements you can think of. It's inspired by several libraries that try to combine React with Rx but they didn't seem to do exactly what I had in mind.\n\n## Installation\n```\nnpm install reactive-flux\n```\n\n## Description\nThe dispatcher is completely gone. Instead we are using Rx.Subjects as Actions and Stores.\n\n* An Action can have many Stores subscribed to it\n* A Store can subscribe to many Actions, each with its own handler\n* Additionally it can request to be notified after other stores in case there are any dependencies (Dispatcher.waitFor())\n* React components can subscribe to many Stores as they are subclasses of Rx.Subject\n\n## Changelog\n\n* 0.1.2: Custom function argument for Action. Fixed problem that the library could not be required correctly.\n\n## Example\n```javascript\nlet ReactiveFlux = require('reactive-flux'),\n\trequest = require('superagent'),\n\tReact = require('react'),\n\tAction = ReactiveFlux.Action,\n\tStore = ReactiveFlux.Store;\n\nlet LoginSucceededAction = Action.make();\nlet LoginFailedAction = Action.make();\n\nlet LoginAction = Action.make((username, password) =\u003e {\n\trequest\n\t\t.post('/login')\n\t\t.send({ username: username, password: password })\n\t\t.end(function(err, res){\n\t\t\tif (res.status == 200) {\n\t\t\t\tLoginSucceededAction(res.body.token);\n\t\t\t} else {\n\t\t\t\tLoginFailedAction();\n\t\t\t}\n\t\t});\n});\n\nlet LOGIN_TOKEN_KEY = 'token';\n\nclass LoginStore extends Store {\n\tconstructor() {\n\t\tsuper();\n\n\t\t// yes, I agree this is superfluous and needs to be changed :)\n\t\tthis.init();\n\t}\n\n\tinit() {\n\t\tthis.observe(LoginSucceededAction, this.onLoginSucceeded);\n\t\tthis.observe(LoginFailedAction, this.onLoginFailed);\n\t}\n\n\tonLoginSucceeded(token) {\n\t\twindow.localStorage.setItem(LOGIN_TOKEN_KEY, token);\n\t}\n\n\tonLoginFailed() {\n\t\twindow.localStorage.removeItem(LOGIN_TOKEN_KEY);\n\t}\n\n\tgetToken() {\n\t\treturn window.localStorage.getItem(LOGIN_TOKEN_KEY);\n\t}\n\n\tisLoggedIn() {\n\t\treturn !!this.getToken();\n\t}\n}\n\nvar LoginComponent = React.createClass({\n\tgetInitialState() {\n\t\treturn { isLoggedIn: LoginStore.isLoggedIn() };\n\t},\n\n\t_subscription: {},\n\n\tcomponentDidMount() {\n\t\tself = this;\n\t\tthis._subscription = LoginStore.subscribe(function () {\n\t\t\tif (LoginStore.isLoggedIn()) {\n\t\t\t   // do something useful\n\t\t\t}\n\t\t});\n\t},\n\n\tcomponentWillUnmount() {\n\t\tthis._subscription.dispose();\n\t},\n\n\trender() {\n\t\treturn (\n\t\t\t// something\n\t\t);\n\t},\n\n\thandleSubmit(e) {\n\t\te.preventDefault();\n\n\t\tlet username = this.refs.username.getValue().trim();\n\t\tlet password = this.refs.password.getValue().trim();\n\n\t\tif (!username || !password) {\n\t\t\treturn;\n\t\t}\n\n\t\t// call our action\n\t\tLoginAction(username, password);\n\t}\n});\n\n// Actions are subjects so we can subscribe to an API or similar\nvar source = Rx.Observable.fromEvent(document, 'mousemove');\nsource.subscribe(SomeAction); // All mousemove events will be send to subscribing stores of SomeAction\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesuki%2Freactive-flux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodesuki%2Freactive-flux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesuki%2Freactive-flux/lists"}