{"id":22505277,"url":"https://github.com/azer/watch-array","last_synced_at":"2025-08-03T11:33:02.896Z","repository":{"id":8093768,"uuid":"9508114","full_name":"azer/watch-array","owner":"azer","description":"Lets you subscribe to any changes on native JavaScript arrays.","archived":false,"fork":false,"pushed_at":"2013-05-14T23:39:56.000Z","size":123,"stargazers_count":59,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-17T03:04:29.951Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-17T21:35:58.000Z","updated_at":"2022-11-08T16:02:43.000Z","dependencies_parsed_at":"2022-09-13T14:21:40.131Z","dependency_job_id":null,"html_url":"https://github.com/azer/watch-array","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/azer/watch-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fwatch-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fwatch-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fwatch-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fwatch-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azer","download_url":"https://codeload.github.com/azer/watch-array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fwatch-array/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268537902,"owners_count":24266287,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-12-07T00:17:05.111Z","updated_at":"2025-08-03T11:33:02.658Z","avatar_url":"https://github.com/azer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## watch-array\n\nLets you subscribe to any changes made by **mutator methods** on native JavaScript arrays. \nIf you're looking for a safer \u0026 complete abstraction: [new-list](http://github.com/azer/new-list)\n\n```js\nwatchArray = require('watch-array')\n\npeople = ['Joe', 'Smith']\n\nwatchArray(people, function(update){ // or watchArray.once(people, function(update){\n\n    update.add\n    // =\u003e { 1: Taylor, 2: Brown }\n\n    update.remove\n    // =\u003e [0]\n    \n    update.sort\n    // =\u003e undefined\n\n})\n\npeople.shift()\npeople.push('Taylor', 'Brown')\n```\n\n## Install\n\n```bash\n$ npm install array\n```\n\n## Subscribing To Deeper Changes\n\nYou can easily define your custom type of updates and distribute them using the minimalistic pubsub interface mixed to\nany array that you watch *(see [new-list](http://github.com/azer/new-list) for defining native arrays with Pub/Sub by default):*\n\n```js\npeople = [{ name: 'Joe', age: 27 }, { name: 'Smith', age: 19 }]\n\nwatchArray(people, function(update){\n    \n  if (update.person) {\n\n    update.index\n    // =\u003e 1\n    update.person\n    // =\u003e { name: 'Smith', age: 20 }\n\n  }\n  \n})\n\npeople[1].age = 20\n\npeople.publish({ person: people[1], index: 1 })\n```\n\n## How It Works?\n\n* It mixes the given array with [new-pubsub](http://github.com/azer/pubsub). \n* It overrides mutable methods like `push`, `splice` etc to emit the changes.\n\n## Caveats\n\nFollowing changes won't be catched;\n\n```js\npeople[people.length] = \"Fred\";\npeople[0] = \"Barney\";\ndelete people[0];\n```\n\n\n![](https://dl.dropboxusercontent.com/s/vg71zdk29kckx04/npmel_12.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazer%2Fwatch-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazer%2Fwatch-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazer%2Fwatch-array/lists"}