{"id":18787594,"url":"https://github.com/freddy03h/immutable-data-structure","last_synced_at":"2025-10-05T06:57:33.244Z","repository":{"id":44122272,"uuid":"102203358","full_name":"Freddy03h/immutable-data-structure","owner":"Freddy03h","description":"Normalize and Merge your application's data store using Immutable.JS objects","archived":false,"fork":false,"pushed_at":"2023-01-04T01:18:38.000Z","size":1548,"stargazers_count":1,"open_issues_count":13,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-11T11:49:03.535Z","etag":null,"topics":["data","immutable","redux","store"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Freddy03h.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-02T14:48:58.000Z","updated_at":"2019-08-01T09:47:36.000Z","dependencies_parsed_at":"2023-02-01T17:30:38.952Z","dependency_job_id":null,"html_url":"https://github.com/Freddy03h/immutable-data-structure","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Freddy03h/immutable-data-structure","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freddy03h%2Fimmutable-data-structure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freddy03h%2Fimmutable-data-structure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freddy03h%2Fimmutable-data-structure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freddy03h%2Fimmutable-data-structure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Freddy03h","download_url":"https://codeload.github.com/Freddy03h/immutable-data-structure/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freddy03h%2Fimmutable-data-structure/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278420208,"owners_count":25983814,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["data","immutable","redux","store"],"created_at":"2024-11-07T20:54:54.536Z","updated_at":"2025-10-05T06:57:33.209Z","avatar_url":"https://github.com/Freddy03h.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Immutable-Data-Structure\n\n**BETA VERSION**\n\nGive me some feedback to improve the API and the Doc\n\n---\n\nImmutable-Data-Structure is a project to help you **normalize** and **merge** your application's data using **Immutable.JS** objects.\n\nIt is useful to help manage your **Redux** store, it is created for this purpose, but Redux isn't a dependency of this project so you basically can use it elsewhere.\n\nIt only provides functions :\n\n* Writing functions to use inside your reducers (merge, update, delete, … )\n* Reading functions to use inside your `mapStateToProps` (selectors)\n\n## Structure of the store\n\nAssuming your already know why it's important to normalize your data and to be resource oriented. Here is an example of a manga's `series` reducer store.\n\nThe **Immutable Record** look like :\n\n```javascript\nconst SerieRecord = Immutable.Record({\n  id: null,\n  title: null,\n  type_id: null,\n})\n```\nAnd we also declare an array of all foreign keys for the Record :\n\n```javascript\nconst serieForeignKeys = ['type_id']\n```\n\nThe point of this project is to produce and maintain a structure like this :\n\n```\nImmutable.Map {\n  data: Immutable.Map {\n    d1a38f41: Object {\n      \"id\": \"d1a38f41\",\n      \"title\": \"Naruto\",\n      \"type_id\": \"106f524e\",\n    },\n    f0db2df6: Object {\n      \"id\": \"f0db2df6\",\n      \"title\": \"Naruto : Les Romans\",\n      \"type_id\": \"bb3d92a9\",\n    },\n    a02cf154: Object {\n      \"id\": \"a02cf154\",\n      \"title\": \"One Piece\",\n      \"type_id\": \"106f524e\",\n    },\n    f59ab8de: Object {\n      \"id\": \"f59ab8de\",\n      \"title\": \"Radiant\",\n      \"type_id\": \"3c009f18\",\n    },\n    96138837: Object {\n      \"id\": \"96138837\",\n      \"title\": \"Dreamland\",\n      \"type_id\": \"3c009f18\",\n    },\n    b9652346: Object {\n      \"id\": \"b9652346\",\n      \"title\": \"Fullmetal Alchemist\",\n      \"type_id\": \"106f524e\",\n    },\n    940629b6: Object {\n      \"id\": \"940629b6\",\n      \"title\": \"Dragon Ball\",\n      \"type_id\": \"106f524e\",\n    },\n  },\n  relations: Immutable.Map {\n    type_id: Immutable.Map {\n      106f524e: Immutable.OrderedSet [\n        \"a02cf154\",\n        \"d1a38f41\",\n        \"940629b6\",\n        \"b9652346\",\n      ],\n      3c009f18: Immutable.OrderedSet [\n        \"96138837\",\n        \"f59ab8de\",\n      ],\n      bb3d92a9: Immutable.OrderedSet [\n        \"f0db2df6\",\n      ],\n    },\n  },\n}\n```\n\n### Data\n\n`data` stores all the resources with a quick access by `id`\n\n### Relations\n\n`relations` store all the foreign keys relations like a relational database. It provides a fast access to resources based on a foreign key to avoid doing a `filter` directly on the `data` object that can be really huge and slow.\n\n## Selectors\n\nIf you already know `Immutable.JS` you know how to access data :\n\n```javascript\nstate.getIn(['series', 'data', 'd1a38f41'])\n```\n\n**But, it's not recommended !** We provide selectors to easily access data and can change the structure internally without breaking / migrating your code.\n\n### getDataById\n\nTo get a Record knowing it's ID.\n\n```javascript\nimport { getDataById } from `immutable-data-structure`\n\n// ....\n\n// inside mapStateToProps\nconst seriesID = 'd1a38f41'\nconst serie = getDataById(state, 'series', seriesID)\n```\n\n### getDataByIds\n\nTo get a **List** (Immutable.List) of Records by giving a **Set** (Immutable.Set) of IDs.\n\n```javascript\nconst narutoSeriesIDs = Immutable.Set(['d1a38f41', 'f0db2df6'])\n\nconst narutoSeries = getDataByIds(state, 'series', narutoSeriesIDs)\n```\n\n### getForeignIds\n\nTo get the **OrderedSet** (Immutable.OrderedSet) of IDs by giving a ForeignKeys ID.\n\n```javascript\nconst manfraTypeID = '3c009f18'\n\nconst manfraSeriesIDs = getForeignIds(state, 'series', 'type_id', manfraTypeID)\n```\n\nIt's the equivalent of the **not recommended** Immutable.JS way :\n\n```javascript\nstate.getIn(['series', 'relations', 'type_id', '3c009f18'])\n```\n\n### getDataByForeignId\n\nIn many cases, `getForeignIds` is enough to use in the `mapStateToProps` of a list component. It's recommended to `.map` IDs in the list and then `connect` each row by using `getDataById ` inside the `mapStateToProps` of the row, for performance reason.\n\nBut sometimes, you need to order / filter / … the list based on Records attributes. So we need to get all the data.\n\n`getDataByForeignId` return a **List** (Immutable.List) of Records by giving a ForeignKeys ID.\n\n```javascript\nconst manfraTypeID = '3c009f18'\n\nconst manfraSeries = getDataByForeignId(state, 'series', 'type_id', manfraTypeID)\n```\n\nYou can think of this function like an easy version of something like this :\n\n```javascript\nconst manfraTypeID = '3c009f18'\n\nconst manfraSeriesIDs = getForeignIds(state, 'series', 'type_id', manfraTypeID)\n\nconst manfraSeries = manfraSeriesIDs.map((serieID) =\u003e getDataById(state, 'series', serieID))\n```\n\n## Manage (CRUD actions)\n\nFunctions to use in yours reducers.\n\n### updateRecord\n\nFunction to Create or Update one entity in the store. It automatically update `data` and `relations` to keep a consistent state.\n\nFor example inside a reducer :\n\n```javascript\ncase FETCH_SERIE_SUCCESS: {\n  const apiResponse = Immutable.fromJS(action.jsonResponse)\n\n  const newStore = updateRecord(store, SerieRecord, apiResponse, serieForeignKeys)\n\n  return newStore\n}\n```\n\n### deleteRecord\n\nFunction to Delete one entity in the store.\n\n```javascript\ncase DELETE_SERIE_SUCCESS: {\n  const newStore = deleteRecord(store, action.seriesIDToDelete, serieForeignKeys)\n\n  return newStore\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreddy03h%2Fimmutable-data-structure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreddy03h%2Fimmutable-data-structure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreddy03h%2Fimmutable-data-structure/lists"}