{"id":13835504,"url":"https://github.com/redbadger/immutable-cursor","last_synced_at":"2025-04-22T11:48:47.105Z","repository":{"id":57272761,"uuid":"42590130","full_name":"redbadger/immutable-cursor","owner":"redbadger","description":"👊 Immutable cursors incorporating the Immutable.js interface over a Clojure-inspired atom","archived":false,"fork":false,"pushed_at":"2017-05-01T00:29:17.000Z","size":137,"stargazers_count":60,"open_issues_count":9,"forks_count":7,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-04-11T11:15:21.887Z","etag":null,"topics":["cursor","immutability","state-management"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redbadger.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-09-16T13:52:05.000Z","updated_at":"2025-02-18T18:59:07.000Z","dependencies_parsed_at":"2022-09-08T21:41:37.493Z","dependency_job_id":null,"html_url":"https://github.com/redbadger/immutable-cursor","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/redbadger%2Fimmutable-cursor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redbadger%2Fimmutable-cursor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redbadger%2Fimmutable-cursor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redbadger%2Fimmutable-cursor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redbadger","download_url":"https://codeload.github.com/redbadger/immutable-cursor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250237793,"owners_count":21397399,"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":["cursor","immutability","state-management"],"created_at":"2024-08-04T14:01:03.700Z","updated_at":"2025-04-22T11:48:47.084Z","avatar_url":"https://github.com/redbadger.png","language":"JavaScript","funding_links":[],"categories":["目录"],"sub_categories":[],"readme":"# Immutable Cursor\n[![Circle CI](https://circleci.com/gh/redbadger/immutable-cursor.svg?style=svg)](https://circleci.com/gh/redbadger/immutable-cursor)\n[![npm version](https://badge.fury.io/js/immutable-cursor.svg)](http://badge.fury.io/js/immutable-cursor)\n\n\u003e Immutable cursors incorporating the [Immutable.js](https://github.com/facebook/immutable-js) API interface over a Clojure-inspired atom\n\n## Rationale\n\nIn Immutable.js' [cursor implementation](https://github.com/facebook/immutable-js/tree/master/contrib/cursor), all applicable parts of it's [native interface](https://facebook.github.io/immutable-js/docs) are exposed as first-class citizens directly on the cursor, allowing for a rich mutative API.\n\nEach cursor however, holds it's *own* reference to the root state, which quickly leads to issues with the integrity of the root state when updates are made from derived cursors - i.e not included in a chained sequence with the root cursor.\n\n### Solution\n\nA Clojure-inspired atom is placed above the cursor composition, and is the only point of mutation in the entire system. Each cursor references this atom, which ensures that an accurate state representation **always** flows down the system.\n\n```js\nconst data = Immutable.fromJS({a: 1, b: 2});\n\nconst cursor = Cursor.from(data, (nextValue, prevValue, keyPath) =\u003e {\n  console.log('Value changed from', prevValue, 'to', nextValue, 'at', keyPath);\n});\n\n// Multiple update transactions are serialised.\ncursor.set('a', 2);\n// Value changed from Map { a: 1, b: 2 } to Map { a: 2, b: 2 } at [ 'a' ]\ncursor.set('b', 3);\n// Value changed from Map { a: 2, b: 2 } to Map { a: 2, b: 3 } at [ 'b' ]\n\n// Whilst the cursor the itself stays immutable.\ncursor.deref(); // =\u003e Map { \"a\": 1, \"b\": 2 }\n```\n\nThis has far reaching consequences when used in component-centric view layers such as React. A typical use case\nwould be to make several derivations of a cursor within a React component before propagating them down the\nsub-tree as `props`.\n\n## Contributing\n\n1. Fork the repo and create your branch from `master`\n2. `npm install`\n3. Add tests\n4. Commit the aforementioned and associated source files. **NOTE** There is no need to manually create the generated `dist` files; this, a test run and a linting pass is done automatically every time you make a commit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredbadger%2Fimmutable-cursor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredbadger%2Fimmutable-cursor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredbadger%2Fimmutable-cursor/lists"}