{"id":17349271,"url":"https://github.com/co2-git/follow.js","last_synced_at":"2025-08-03T14:13:34.761Z","repository":{"id":26144329,"uuid":"29589420","full_name":"co2-git/follow.js","owner":"co2-git","description":"Make `Object.observe` emit events","archived":false,"fork":false,"pushed_at":"2015-01-21T13:15:45.000Z","size":128,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T09:44:58.764Z","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/co2-git.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":"2015-01-21T12:55:06.000Z","updated_at":"2015-01-21T13:15:45.000Z","dependencies_parsed_at":"2022-08-01T05:48:36.608Z","dependency_job_id":null,"html_url":"https://github.com/co2-git/follow.js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/co2-git/follow.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Ffollow.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Ffollow.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Ffollow.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Ffollow.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/co2-git","download_url":"https://codeload.github.com/co2-git/follow.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Ffollow.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268554911,"owners_count":24269064,"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-10-15T16:55:12.571Z","updated_at":"2025-08-03T14:13:34.713Z","avatar_url":"https://github.com/co2-git.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"follow.js\n=========\n\n\t      \u003e=\u003e             \u003e=\u003e  \u003e=\u003e                                            \n\t    \u003e\u003e                \u003e=\u003e  \u003e=\u003e                                \u003e=\u003e         \n\t  \u003e=\u003e\u003e \u003e\u003e    \u003e=\u003e      \u003e=\u003e  \u003e=\u003e    \u003e=\u003e     \u003e=\u003e      \u003e=\u003e             \u003e===\u003e  \n\t    \u003e=\u003e    \u003e=\u003e  \u003e=\u003e   \u003e=\u003e  \u003e=\u003e  \u003e=\u003e  \u003e=\u003e   \u003e=\u003e  \u003e  \u003e=\u003e        \u003e=\u003e \u003e=\u003e     \n\t    \u003e=\u003e   \u003e=\u003e    \u003e=\u003e  \u003e=\u003e  \u003e=\u003e \u003e=\u003e    \u003e=\u003e  \u003e=\u003e \u003e\u003e  \u003e=\u003e        \u003e=\u003e   \u003e==\u003e  \n\t    \u003e=\u003e    \u003e=\u003e  \u003e=\u003e   \u003e=\u003e  \u003e=\u003e  \u003e=\u003e  \u003e=\u003e   \u003e=\u003e\u003e  \u003e=\u003e=\u003e        \u003e=\u003e     \u003e=\u003e \n\t    \u003e=\u003e      \u003e=\u003e     \u003e==\u003e \u003e==\u003e    \u003e=\u003e     \u003e==\u003e    \u003e==\u003e \u003e=\u003e    \u003e=\u003e \u003e=\u003e \u003e=\u003e \n\t                                                           \u003e==\u003e      \n\n# Abstract\n\nMake `Object.observe` emit events. Ship whith a shim using `Object.defineProperty` if `Object.observe` not supported. See limitations below.\n\n# Install\n\n```bash\nbower install co2-git/follow.js\n```\n\n# Usage\n\n```html\n\u003cscript src=\"follow.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n\t! function () {\n\t\t'use strict';\n\n\t\tvar model = {\n\t\t\tcounter: 0\n\t\t};\n\n\t\tnew Follow(model)\n\t\t\t.on('update counter', function (counter, info) {\n\t\t\t\tconsole.info('counter updated', counter, info);\n\t\t\t});\n\n\t\tsetInterval(function () {\n\t\t\tmodel.counter ++;\n\t\t}, 2000);\n\n\t} ();\n\u003c/script\u003e\n```\n\n# Observe and emit\n\n`Object.observe` is a nice way to keep track of an object change. Especially helpful in a realtime app, when model is bound to change a lot and view must react to these changes. I've just decided to mix `Object.observe` with Events Emitter using Browserify. It emits the same three events Object.observe listens to:\n\n- add\n- update\n- delete\n\nYou can only follow objects. Everytime a change is observed on the followed object, an event is emitted by with the type of change and the name of the property.\n\n```js\nvar model = {};\n\nnew Follow(model)\n\t\n\t.on('add name', function (name) {\n\t\tconsole.log('added name property', name);\n\t})\n\n\t.on('update name', function (name) {\n\t\tconsole.log('updated name property', name);\n\t})\n\n\t.on('delete name', function (name) {\n\t\tconsole.log('deleted name property', name);\n\t});\n\n// will emit \"add name\" \"abc\" \n\nmodel.name = 'abc';\n\n// will emit \"update name\" \"xyz\"\n\nmodel.name = 'xyz';\n\n// will emit \"delete name\"\n\ndelete model.name;\n```\n\n# Shim\n\n`Object.observe` is not supported by all modern browsers (Firefox). In this case, a shim is supplied that uses `Object.defineProperty`\n\n# Limitations\n\n## Array\n\nThe `update` event will only pick up updates made directly to the array such as:\n\n```js\n// will emit \"add array\" [1]\nmodel.array = [1];\n\n// will emit \"update array\" [2]\nmodel.array = [2];\n\n// will not emit nothing\nmodel.array[1] = 3;\nmodel.array.push(4);\n// and all other Array prototypes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Ffollow.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fco2-git%2Ffollow.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Ffollow.js/lists"}