{"id":16456735,"url":"https://github.com/zeekay/referential","last_synced_at":"2025-03-23T10:32:50.531Z","repository":{"id":57352045,"uuid":"47583213","full_name":"zeekay/referential","owner":"zeekay","description":"🕶️ Mutable state container for sharing data safely in a functional or reactive programming style.","archived":false,"fork":false,"pushed_at":"2019-01-19T17:18:58.000Z","size":332,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-01T10:36:14.139Z","etag":null,"topics":["datastructures","events","mutable-state","reactive","references","state","tree"],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","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/zeekay.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-12-07T22:27:45.000Z","updated_at":"2024-02-10T12:44:15.000Z","dependencies_parsed_at":"2022-08-29T13:30:44.169Z","dependency_job_id":null,"html_url":"https://github.com/zeekay/referential","commit_stats":null,"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeekay%2Freferential","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeekay%2Freferential/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeekay%2Freferential/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeekay%2Freferential/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeekay","download_url":"https://codeload.github.com/zeekay/referential/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245090864,"owners_count":20559296,"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":["datastructures","events","mutable-state","reactive","references","state","tree"],"created_at":"2024-10-11T10:27:42.333Z","updated_at":"2025-03-23T10:32:50.223Z","avatar_url":"https://github.com/zeekay.png","language":"CoffeeScript","readme":"# referential\n\n[![npm][npm-img]][npm-url]\n[![build][build-img]][build-url]\n[![dependencies][dependencies-img]][dependencies-url]\n[![downloads][downloads-img]][downloads-url]\n[![license][license-img]][license-url]\n[![chat][chat-img]][chat-url]\n\n\u003e Refer to mutable state safely.\n\nReferential makes it easy to share mutable state safely. A `Ref` to an object\nor subtree always refers to the same underlying data regardless how it's\nmutated.\n\nHeavily optimized for reads.\n\n### Motivating example\n```javascript\nvar state = {a: {b: {c: \"world\"}}}\n\nvar render = (function() {\n    var template = state.a.b.c;\n    return function() {\n        return \"Hello \" + template\n    }\n}())\n\nstate.a.b.c = \"This will be lost on you.\"\n\nconsole.log(render()) // Hello world\n```\n\n## Install\n```bash\n$ npm install referential --save\n```\n\n## Usage\n```javascript\nrefer = require('referential')\n\n// Create a reference\nref = refer({a: 1})\n\n// Get underlying value of reference\nref()    // {a: 1}\nref('a') // 1\n\n// Mutate state\nref.set('b', 2) // {a: 1, b: 2}\nref.set({c: 3}) // {a: 1, b: 2, c: 3}\n\n// Extend state\nref.extend({c: {d: 1, e: 2}}) // {a: 1, b: 2, c: {d: 1, e: 2}}\nref.extend({c: {d: 3}})       // {a: 1, b: 2, c: {d: 3, e: 2}}\n\n// Create entire tree as needed\nref.set('d.e.f', 4) // {a: 1, b: 2, c: 3, d: {e: {f: 4}}}\n\n// Get reference to subtree\nref2 = ref.refer('d.e')\nref2() // {f: 4}\n\n// Mutate subtree (and update parent)\nref2.set('g', 5)\nref2() // {f: 4, g: 5}\n\n// Mutate parent (and update subtree)\nref.set('d.e.f', 6)\nref()  // {a: 1, b: 2, c: 3, d: {e: {f: 6, g: 5}}}\nref2() // {f: 6, g: 5}\n\n// Clone ref, create new tree\nref3 = ref2.clone()\nref3.set('g', 6)\nref3() // {f: 6, g: 6}\nref2() // {f: 6, g: 5}\n\n// Bind to update event, should print `x was set to 2 from 1`\nref4 = refer({x: 1})\nref4.on('set', function(name, newValue, oldValue) {\n    console.log(name + ' was set to ' + newValue + ' from ' + oldValue)\n})\nref4.set('x', 2)\n```\n\nCheck the tests for [more examples][examples].\n\n## License\n[MIT][license-url]\n\n[examples]:         https://github.com/zeekay/referential/blob/master/test/test.coffee\n\n[build-img]:        https://img.shields.io/travis/zeekay/referential.svg\n[build-url]:        https://travis-ci.org/zeekay/referential\n[chat-img]:         https://badges.gitter.im/join-chat.svg\n[chat-url]:         https://gitter.im/zeekay/hi\n[coverage-img]:     https://coveralls.io/repos/zeekay/referential/badge.svg?branch=master\u0026service=github\n[coverage-url]:     https://coveralls.io/github/zeekay/referential?branch=master\n[dependencies-img]: https://david-dm.org/zeekay/referential.svg\n[dependencies-url]: https://david-dm.org/zeekay/referential\n[downloads-img]:    https://img.shields.io/npm/dm/referential.svg\n[downloads-url]:    http://badge.fury.io/js/referential\n[license-img]:      https://img.shields.io/npm/l/referential.svg\n[license-url]:      https://github.com/zeekay/referential/blob/master/LICENSE\n[npm-img]:          https://img.shields.io/npm/v/referential.svg\n[npm-url]:          https://www.npmjs.com/package/referential\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeekay%2Freferential","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeekay%2Freferential","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeekay%2Freferential/lists"}