{"id":15403947,"url":"https://github.com/pluff/angular-identity-map","last_synced_at":"2025-04-16T07:39:46.515Z","repository":{"id":15224680,"uuid":"17953301","full_name":"pluff/angular-identity-map","owner":"pluff","description":"Identity map implementation for AngularJS","archived":false,"fork":false,"pushed_at":"2014-12-16T21:48:32.000Z","size":290,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T17:54:39.393Z","etag":null,"topics":[],"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/pluff.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":"2014-03-20T18:17:05.000Z","updated_at":"2024-09-23T10:21:54.000Z","dependencies_parsed_at":"2022-08-30T16:11:13.478Z","dependency_job_id":null,"html_url":"https://github.com/pluff/angular-identity-map","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluff%2Fangular-identity-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluff%2Fangular-identity-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluff%2Fangular-identity-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluff%2Fangular-identity-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pluff","download_url":"https://codeload.github.com/pluff/angular-identity-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249213879,"owners_count":21231096,"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":[],"created_at":"2024-10-01T16:10:46.381Z","updated_at":"2025-04-16T07:39:46.497Z","avatar_url":"https://github.com/pluff.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## angular-identity-map\n\nAn [identity map pattern](http://en.wikipedia.org/wiki/Identity_map_pattern) implementation for AngularJS applications.\n\n## Requirements\n\nAngularJS v1.0+\ntraverse\n\n## Getting started\n\n### with bower\n\nJust include \"angular-identity-map\" to your dependencies list and run `bower install`\n\n### with npm\n\n`npm install angular-identity-map`\n\n\n### manually\n\nDownload [angular-identity-map.js](https://raw.githubusercontent.com/pluff/angular-identity-map/master/dist/angular-identity-map.min.js) and include it on your page along with AngularJS\nAdd `identity-map` to your module dependencies\n```javascript\nangular.module('myApp', ['identity-map']);\n```\n\n## Usage\n\n### Pre-requirements\nAll objects you want to map must have `id` attribute and `class_name` attribute in order to retrieve object identification pair. This pair (class_name, id) MUST be unique.\nBoth these behaviors can be customized. See Configuration chapter below.\n\n\n### All you need is .map\n\n```javascript\nvar myAppModule = angular.module(\"MyApp\", [\"identity-map\"]);\n\nmyAppModule.controller(\"myController\", function($scope, IdentityMap) {\n  $scope.phoneList = [\n    {id: 1, class_name: 'Phone', name: 'Emergency', value: '911'}\n  ];\n  IdentityMap.map($scope.phoneList);\n  \n  //Let's assume you somehow retrieved new phone list e.g. by using Restangular\n   newPhoneList = [\n     {id: 1, class_name: 'Phone', name: 'Emergency', value: 'call-911'},\n     {id: 2, class_name: 'Phone', name: 'Mommy', value: '12345'}\n   ];\n   IdentityMap.map(newPhoneList); \n   $scope.phoneList[0].value; // \"call-911\"\n   //However your $scope.phoneList still has 1 item, while newPhoneList has 2 items. \n   //Remember, IdentityMap stores objects only.\n}\n```\n\nYou can see and play around with [live demo](http://plnkr.co/edit/jDiMgjnQYitBYTx9Mqth?p=preview)! \n\n### Others methods for those, who want to dig deeply into identity map\n\nThere are several methods available such as `.get`, `.set`, `.detach`, `.clear` etc. \nCheck out the source code for more information.\n\n### Configuration\n\nidentity-map stores and retrieves object using object type and object id.\nBy default object id is retrieved by calling `id` attribute on an object. Object type retrieved by calling `class_name` attribute on an object.\nThese functions are configurable in service provider:\nExample:\n```javascript\napp.config(function(IdentityMapProvider) {\n  //retrieves object type for mapping from object constructor name.\n  IdentityMapProvider.setEntityTypeFn(function(entity) { \n    return entity.constructor.name; \n  });\n  //retrieves object id for mapping by calling \"getGlobalId\" function.\n  IdentityMapProvider.setEntityFn(function(type, entity) { \n      return entity.getGlobalId(); \n    });  \n});\n```\nPlease pay attention to couple requirements for these functions:\n\n1. Any pair of (entityType, entityId) values MUST represent one and only one entity object.\n2. Both functions accept one param which is guaranteed to be an object. If `entity` param is not a mappable object both functions MUST return `undefined`.  \n\nMore examples can be found in spec/IdentityMap_spec.coffee\n\n### Integration with Restangular\n\n\"identity-map\" can be integrated with Restangular easily.\nYou just need to add simple response interceptor to Restangular stack:\n```javascript\nangular.module('myApp', ['restangular', 'identity-map']).run(\nfunction (Restangular, IdentityMap) {\n  Restangular.addResponseInterceptor(\n    function (data, operation, what, url, response, deffered) {\n      return IdentityMap.map(data);\n    }\n  );\n});\n```\nStarting from now any Restangular response with \"mappable\" objects will be mapped automatically.\n\n\n## Development\n\nCode quality is ensured with CoffeeScript, CoffeeLint, and Karma.\n```sh\nnpm install -g grunt-cli\nnpm install \u0026\u0026 bower install\ngrunt\n```\n\n### Live Reloading\n\n```sh\ngrunt karma:unit:start watch\n```\n\n### Build\n\n```sh\ngrunt dist\n```\n\n## TODO\n\nSee [issues list](https://github.com/pluff/angular-identity-map/issues?q=is%3Aopen)\n\n\n## Contribute\n\n1. Fork\n2. Code\n3. Submit PR\n\n## License\n\n[MIT](https://raw.githubusercontent.com/pluff/angular-identity-map/master/LICENSE)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpluff%2Fangular-identity-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpluff%2Fangular-identity-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpluff%2Fangular-identity-map/lists"}