{"id":22382398,"url":"https://github.com/jcoreio/redux-immutable-collections","last_synced_at":"2025-03-26T19:40:54.495Z","repository":{"id":57350862,"uuid":"76289399","full_name":"jcoreio/redux-immutable-collections","owner":"jcoreio","description":"Reducers and actions for storing collections of documents in Redux state","archived":false,"fork":false,"pushed_at":"2017-12-21T21:51:16.000Z","size":132,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T22:16:41.989Z","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/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-12T19:40:12.000Z","updated_at":"2016-12-12T19:41:26.000Z","dependencies_parsed_at":"2022-09-18T00:20:56.850Z","dependency_job_id":null,"html_url":"https://github.com/jcoreio/redux-immutable-collections","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fredux-immutable-collections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fredux-immutable-collections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fredux-immutable-collections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fredux-immutable-collections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/redux-immutable-collections/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245726793,"owners_count":20662544,"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-12-05T00:12:52.486Z","updated_at":"2025-03-26T19:40:54.457Z","avatar_url":"https://github.com/jcoreio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-immutable-collections\n\n[![Build Status](https://travis-ci.org/jcoreio/redux-immutable-collections.svg?branch=master)](https://travis-ci.org/jcoreio/redux-immutable-collections)\n[![Coverage Status](https://coveralls.io/repos/github/jcoreio/redux-immutable-collections/badge.svg?branch=master)](https://coveralls.io/github/jcoreio/redux-immutable-collections?branch=master)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\nReducers and actions for storing collections of documents in Immutable.js collections in Redux state.\nDesigned for Mongo documents, but potentially useful even if you're not using Mongo.\n\n## Usage\n\n```\nnpm i --save redux-immutable-collections\n```\n\n### Keyed collections\n\n```es6\nimport {reducer as keyedCollectionReducer, actions} from './lib/keyedCollection'\nimport {createStore} from 'redux'\nimport {combineReducers} from 'mindfront-redux-utils-immutable'\n\nconst USERS = 'USERS.'\nconst POSTS = 'POSTS.'\n\n// the keyed collection action types are just INSERT, UPDATE, REMOVE, and BATCH,\n// unless we specify an action type prefix like so:\n\nconst reducer = combineReducers({\n  users: keyedCollectionReducer({actionTypePrefix: USERS}),\n  posts: keyedCollectionReducer({actionTypePrefix: POSTS}),\n})\nconst userActions = mapValues(actions(USERS))\nconst postActions = mapValues(actions(POSTS))\n\nconst store = createStore(reducer)\n\nstore.dispatch(userActions.insert('28nkdjas9i23kjsdaf', {\n  username: 'jimbob',\n  firstName: 'Jim',\n  lastName: 'Bob',\n}))\nstore.dispatch(userActions.update('28nkdjas9i23kjsdaf', {\n  email: 'jim@bob.com',\n}))\n\nconsole.log(store.getState())\n```\n\nThe state will look like this:\n```\nMap {\n  \"users\": Map {\n    \"28nkdjas9i23kjsdaf\": Map {\n      \"username\": \"jimbob\",\n      \"firstName\": \"Jim\",\n      \"lastName\": \"Bob\",\n      \"email\": \"jim@bob.com\"\n    }\n  },\n  \"posts\": undefined\n}\n```\n\nYou can also `remove` documents:\n```es6\nstore.dispatch(userActions.remove('28nkdjas9i23kjsdaf'))\n```\n\nIf you need to make a lot of changes rapidly, dispatch them in a batch; the reducer will handle them inside a\n`withMutations` call, which is much more efficient, and redux subscribers will only be notified once:\n```es6\nstore.dispatch(userActions.batch([\n  userActions.insert('28nkdjas9i23kjsdaf', {\n    username: 'jimbob',\n    firstName: 'Jim',\n    lastName: 'Bob',\n  }),\n  userActions.update('28nkdjas9i23kjsdaf', {\n    email: 'jim@bob.com',\n  }),\n]))\n```\n\nThere is a `clear` action as well that will clear the collection.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fredux-immutable-collections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fredux-immutable-collections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fredux-immutable-collections/lists"}