{"id":26061744,"url":"https://github.com/trackableentities/trackable-entities-js","last_synced_at":"2025-04-11T09:57:17.428Z","repository":{"id":25211407,"uuid":"103461308","full_name":"TrackableEntities/trackable-entities-js","owner":"TrackableEntities","description":"Base classes that track change state when properties are updated and objects are added or removed objects from collections.","archived":false,"fork":false,"pushed_at":"2023-02-27T16:42:09.000Z","size":4515,"stargazers_count":11,"open_issues_count":34,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T13:40:56.791Z","etag":null,"topics":["angular","change-tracking","map","observables","proxies","set"],"latest_commit_sha":null,"homepage":"","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-13T23:16:51.000Z","updated_at":"2023-08-14T21:18:19.000Z","dependencies_parsed_at":"2025-03-08T15:13:21.292Z","dependency_job_id":"44c66c15-4e93-464d-bcfa-f0d60411c958","html_url":"https://github.com/TrackableEntities/trackable-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%2Ftrackable-entities-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrackableEntities%2Ftrackable-entities-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrackableEntities%2Ftrackable-entities-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrackableEntities%2Ftrackable-entities-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TrackableEntities","download_url":"https://codeload.github.com/TrackableEntities/trackable-entities-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248371733,"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.694Z","updated_at":"2025-04-11T09:57:17.395Z","avatar_url":"https://github.com/TrackableEntities.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trackable-entities-js\n\nBase classes that track change state when properties are updated and objects are added or removed objects from collections.\n\n[![Build Status](https://travis-ci.org/TrackableEntities/trackable-entities-js.svg)](https://travis-ci.org/TrackableEntities/trackable-entities-js)\n[![npm version](https://badge.fury.io/js/trackable-entities.svg)](https://badge.fury.io/js/trackable-entities)\n\nDocs: \u003chttps://trackableentities.github.io/trackable-entities-js\u003e\n\nSample application: \u003chttps://github.com/TrackableEntities/trackable-entities-js-sample.git\u003e\n\n\u003e Note: You must change the TypeScript compiler target to \"es2015\" in **ts.config.json**.\n\u003e - Apps using trackable-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 **trackable-entities** as a runtime dependency from npm.\n\n```\nnpm i --save trackable-entities\n```\n\n## Usage\n\nTo track property changes on an object, create a class that extends `TrackableEntity`. Then add a `constructor` that returns `super.proxify(this)`.  For example:\n\n```js\nexport class Product extends TrackableEntity {\n  productId: number;\n  productName: string;\n  unitPrice: number;\n\n  constructor() {\n    super();\n    return super.proxify(this);\n  }\n}\n```\n\nThen set the `tracking` property to `true`.  Modifying property values will change the `trackingState` from `Unchanged` to `Modified` and will populate the `modifiedProperties` collection with the names of properties that were changed, so that partial updates (PATCH) may be performed by an API that knows how to apply changes to a persistence store such as a database.\n\n```js\n// Product extends TrackableEntity\nproduct = new Product(1, 'Bacon', 1);\n\n// Turn on change tracking\nproduct.tracking = true;\n\n// Modify a property\nproduct.productName = 'Peas';\n\n// Tracking state is set to Modified\nexpect(product.trackingState).toEqual(TrackingState.Modified);\n\n// Name of modified properties are tracked\nexpect(product.modifiedProperties.has('productName')).toBeTruthy();\n```\n\nThere are two collections that support change tracking: `TrackableSet` which extends `Set\u003cT\u003e`, and `TrackableMap` which extends `Map\u003cK, V\u003e`. When items are added their `trackingState` is set to `Added`, and when items are deleted their `trackingState` is set to `Deleted`.\n\n```js\n// Create a new TrackableSet of products\nconst products = [\n  new Product(1, 'Bacon', 1),\n  new Product(2, 'Lettuce', 2),\n  new Product(3, 'Tomatoes', 3),\n];\nconst trackableProducts = new TrackableSet\u003cProduct\u003e(...products);\n\n// Turn on change tracking\nproduct.tracking = true;\n\n// Add an entity\nconst addedProduct = new Product(4, 'Carrots', 4);\ntrackableProducts.add(addedProduct);\n\n// Tracking state is set to Added\nexpect(addedProduct.trackingState).toEqual(TrackingState.Added);\n\n// Remove an entity\nconst removedProduct = new Product(4, 'Carrots', 4);\ntrackableProducts.delete(removedProduct);\n\n// Tracking state is set to Added\nexpect(removedProduct.trackingState).toEqual(TrackingState.Deleted);\n```\n\n## Persistence\n\nOnce the tracking state of entities have been set, you can pass them to a Web API where they can be persisted to a data store.  [Trackable Entities](http://trackableentities.github.io) has a server-side [NuGet package](https://www.nuget.org/packages/TrackableEntities.EF.6) for persisting changes to a relational data store using [Entity Framework](https://docs.microsoft.com/en-us/ef/). The current version supports the full .NET Framework with EF 6, and a future version will support [.NET Core](https://www.microsoft.com/net/core) and EF Core as a [NetStandard](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) library.\n\n## Roadmap\n\nWe are currently developing the full API for **trackable-entities**.  See the project [roadmap](https://github.com/TrackableEntities/trackable-entities-js/wiki/Roadmap) for more information.\n\n## Contributing\n\nIf you'd like to help with this project, please contact @tonysneed via email (tony@tonysneed.com) or twitter (@tonysneed).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackableentities%2Ftrackable-entities-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrackableentities%2Ftrackable-entities-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackableentities%2Ftrackable-entities-js/lists"}