{"id":24961330,"url":"https://github.com/streammedev/flux-store","last_synced_at":"2025-03-28T22:27:41.253Z","repository":{"id":57163118,"uuid":"73261515","full_name":"StreamMeDev/flux-store","owner":"StreamMeDev","description":"A redux like data store for our NERF apps","archived":false,"fork":false,"pushed_at":"2017-07-31T19:12:07.000Z","size":37,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-27T13:24:46.461Z","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":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StreamMeDev.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":"2016-11-09T07:35:47.000Z","updated_at":"2017-06-16T14:30:39.000Z","dependencies_parsed_at":"2022-09-01T00:20:21.409Z","dependency_job_id":null,"html_url":"https://github.com/StreamMeDev/flux-store","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreamMeDev%2Fflux-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreamMeDev%2Fflux-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreamMeDev%2Fflux-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreamMeDev%2Fflux-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StreamMeDev","download_url":"https://codeload.github.com/StreamMeDev/flux-store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246108364,"owners_count":20724717,"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":"2025-02-03T08:52:09.521Z","updated_at":"2025-03-28T22:27:41.233Z","avatar_url":"https://github.com/StreamMeDev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flux Store\n\n[![NPM Version](https://img.shields.io/npm/v/@streammedev/flux-store.svg)](https://npmjs.org/package/@streammedev/flux-store)\n[![NPM Downloads](https://img.shields.io/npm/dm/@streammedev/flux-store.svg)](https://npmjs.org/package/nighthawk)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nA Redux-like data store without the enforced opinions.  Similar to Redux, this module is based\non Flux principles, the entire state is stored in a single object, and all mutations are\ndescribed with action objects and applied with reducers.\n\nThe main difference is that this module supports asynchronous actions out of the box, but there are a few\nother differences.  This flux store allows for multiple reducers, which can be composed based on the action\nname, not the data structure.  This allows for multiple reducers to access and modify data across the application.\n\n## Install\n\n```\n$ npm install --save @streammedev/flux-store\n```\n\n## Usage\n\n```javascript\nimport {createStore} from '@streammedev/flux-store';\n\n// Create our reducers\nfunction incr (state = 0, action) {\n  return state + (action.value || 1);\n}\nfunction decr (state = 0, action) {\n  return state - (action.value || 1);\n}\n\n// Create our store instance with an\n// initial state and the reducers\nvar store = createStore({\n\tincr: incr,\n\tdecr: decr\n}, 0);\n\n// Subscribe to changes to the store\nstore.subscribe((state) =\u003e {\n  console.log(state);\n});\n\n// dispatch some actions\nstore.dispatch({\n  type: 'incr'\n}); // 1\n\nstore.dispatch({\n  type: 'incr',\n  value: 2\n}); // 3\n\nstore.dispatch({\n  type: 'decr'\n}); // 2\n\n```\n\n## API\n\n### `createStore([reducers[, initialState]])`\n\nCreates a store, with the reducers and state passed in.  This is the recommended way to create a store because it ensures\nthe proper scope for the methods even if you pass them around, like in a React app when you pass `dispatch` as a prop.\n\n---\n\n### `Store([reducers[, initialState]])`\n\nThe constructor for a store instance.\n\n#### `\u003cStore\u003e.dispatch(action)`\n\nDispatches an action.  Actions in this store can be one of three things:\n\n1. A simple object.  For sync actions you can simply do this.  The only requirement is that the action\nobject has a property `type`.\n2. A Promise. For actions that do asynchronous things, they should resolve/reject with an action object.\n3. A function. For action creators that want to dispatch multiple times. The function will get passed\ndispatch as the first and only argument.\n\n#### `\u003cStore\u003e.subscribe(func)`\n\nSubscribe to changes in the store.  The function passed to subscribe will be called every time\nan action is dispatched, even if there were no changes to the store.  It is passed the new state,\nthe old state, and the action dispatched, in that order.  Use this method to update the your views.\nSubscribe returns the unsubscribe function.\n\n#### `\u003cStore\u003e.getState()`\n\nReturns a clone of the current state object.\n\n#### `\u003cStore\u003e.replaceState()`\n\nReplaces the current state with a whole new object.  This can be called to clear state between route changes\nin a single page app, or to initialize the state of a new store.  It will result in firing your listener functions.\n\n#### `\u003cStore\u003e.replaceReducers()`\n\nReplaces all reducers registered with this store.\n\n#### `\u003cStore\u003e.addReducer(type, reducerFunc)`\n\nAdds a reducer for an action type.\n\n---\n\n### `bindActionCreators(actionCreators, dispatch)`\n\nA utility method which takes an object of action creators and returns a new object where\neach key's function is not wrapped with a call to `dispatch`.  See [Redux's docs for more info](http://redux.js.org/docs/api/bindActionCreators.html).\n\n## Development\n\nThis package follows semver, when you wish to publish a version run the proper npm command.  For example, if we made a bug fix you can do this:\n\n```\n$ npm version patch\n$ git push\n$ npm publish\n```\n\nHere are the other types of version bumps:\n\n- Major (`npm version major`): This is for breaking changes. Anytime a method is changed or the functionality is modified this bump should be made.\n- Minor (`npm version minor`): This is for features additions. When a new method is added which doesn't affect the behavior of existing features, this bump should be made.\n- Patch (`npm version patch`): This is for bug fixes. Only bump this if it is safe for production code to update wihout being QA'd.  (AKA, almost never)\n\nFor each of these you can run a 'pre' version by prepending to the command, ex `npm version preminor`.\n\nAll feature development should be done on a branch off `master`.  When a feature is complete and the pull request approved, publish a 'pre' version of the package for testing across environments.  To install that 'pre' version of the package do the following, where the verison number contains the correct 'pre' version:\n\n```\n$ npm install --save @streammedev/store@1.0.0-0\n```\n\nRunning the tests:\n\n```\n$ npm install \u0026\u0026 npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreammedev%2Fflux-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreammedev%2Fflux-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreammedev%2Fflux-store/lists"}