{"id":26061741,"url":"https://github.com/trackableentities/observable-entities-js","last_synced_at":"2025-04-11T09:57:16.428Z","repository":{"id":44979931,"uuid":"103296404","full_name":"TrackableEntities/observable-entities-js","owner":"TrackableEntities","description":"Base classes that notify observers when properties are updated and objects are added or removed from collections.","archived":false,"fork":false,"pushed_at":"2023-02-28T06:30:39.000Z","size":3038,"stargazers_count":7,"open_issues_count":23,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T10:49:58.905Z","etag":null,"topics":["angular","change-tracking","map","observables","proxies","set"],"latest_commit_sha":null,"homepage":"https://trackableentities.github.io/observable-entities-js","language":"TypeScript","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/TrackableEntities.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":"2017-09-12T16:40:37.000Z","updated_at":"2024-12-21T06:06:17.000Z","dependencies_parsed_at":"2023-02-09T08:46:21.828Z","dependency_job_id":null,"html_url":"https://github.com/TrackableEntities/observable-entities-js","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrackableEntities%2Fobservable-entities-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrackableEntities%2Fobservable-entities-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrackableEntities%2Fobservable-entities-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrackableEntities%2Fobservable-entities-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TrackableEntities","download_url":"https://codeload.github.com/TrackableEntities/observable-entities-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248371731,"owners_count":21093064,"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":["angular","change-tracking","map","observables","proxies","set"],"created_at":"2025-03-08T15:13:18.511Z","updated_at":"2025-04-11T09:57:16.405Z","avatar_url":"https://github.com/TrackableEntities.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# observable-entities-js\n\nBase classes that notify observers when properties are updated and objects are added or removed from collections.\n\n[![Build Status](https://travis-ci.org/TrackableEntities/observable-entities-js.svg?branch=master)](https://travis-ci.org/TrackableEntities/observable-entities-js)\n[![npm version](https://badge.fury.io/js/observable-entities.svg)](https://badge.fury.io/js/observable-entities)\n\nDocs: \u003chttps://trackableentities.github.io/observable-entities-js\u003e\n\nSample application: \u003chttps://github.com/TrackableEntities/observable-entities-js-sample\u003e\n\n\u003e Note: You must change the TypeScript compiler target to \"es2015\" in **ts.config.json**.\n\u003e - Apps using observable-entities can support most modern browsers (Chrome, Firefox, Safari, Edge, etc), but they will not be able to support legacy browsers (Internet Explorer).\n\n## Setup\n\nInstall **observable-entities** as a runtime dependency from npm.\n\n```\nnpm i --save observable-entities\n```\n\n## Usage\n\nTo observe property changes on an object, create a class that extends `ObservableEntity`. Then add a `constructor` that returns `super.proxify(this)`.  For example:\n\n```js\nexport class Product extends ObservableEntity {\n  productId: number;\n  productName: string;\n  unitPrice: number;\n\n  constructor() {\n    super();\n    return super.proxify(this);\n  }\n}\n```\n\n`ObservableEntity` as a `modifyListeners` property of type `Subject\u003cINotifyInfo\u003e[]`.  To listen for property changes, add a listener can call `subscribe` on it.  For example, an Angular component can perform observable-based data binding with an `OnPush` strategy.\n\n```js\n// Trigger binding when item is updated\nthis.modifyListener = new Subject\u003cINotifyInfo\u003e();\nthis.modifyListener.subscribe(info =\u003e {\n  this.cd.markForCheck();\n});\n\n// Add listener to each product\nthis.products.forEach(product =\u003e {\n  product.modifyListeners.push(this.modifyListener);\n});\n```\n\nSimilarly, `ObservableSet` and `ObservableMap` have `addListeners` and `removeListeners` properties, and you can add listeners to trigger data binding when items are added or removed.\n\n```js\n// Trigger data binding when item is added\nthis.addListener = new Subject\u003cINotifyInfo\u003e();\nthis.addListener.subscribe(info =\u003e {\n  this.cd.markForCheck();\n});\n\n// Add listener for adds\nthis.products.addListeners.push(this.addListener);\n\n// Trigger data binding when item is removed\nthis.removeListener = new Subject\u003cINotifyInfo\u003e();\nthis.removeListener.subscribe(info =\u003e {\n  this.cd.markForCheck();\n});\n\n// Add listener for deletes\nthis.products.removeListeners.push(this.removeListener);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackableentities%2Fobservable-entities-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrackableentities%2Fobservable-entities-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackableentities%2Fobservable-entities-js/lists"}