{"id":13399056,"url":"https://github.com/dntzhang/oba","last_synced_at":"2025-03-23T20:31:23.219Z","repository":{"id":148969631,"uuid":"149544505","full_name":"dntzhang/oba","owner":"dntzhang","description":"Observe any object's any change","archived":false,"fork":false,"pushed_at":"2018-09-25T07:21:31.000Z","size":106,"stargazers_count":103,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-07-31T19:17:56.893Z","etag":null,"topics":["observable","observer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/dntzhang.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}},"created_at":"2018-09-20T03:14:06.000Z","updated_at":"2022-08-18T02:33:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"f35e00ce-ef74-4ed9-9066-9b2051365a33","html_url":"https://github.com/dntzhang/oba","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dntzhang%2Foba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dntzhang%2Foba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dntzhang%2Foba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dntzhang%2Foba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dntzhang","download_url":"https://codeload.github.com/dntzhang/oba/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245164965,"owners_count":20571217,"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":["observable","observer"],"created_at":"2024-07-30T19:00:33.805Z","updated_at":"2025-03-23T20:31:22.907Z","avatar_url":"https://github.com/dntzhang.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"## oba.js\n\n[![Build Status](https://secure.travis-ci.org/dntzhang/oba.png?branch=master)](https://travis-ci.org/dntzhang/oba)\n\n用于观察任意对象的任意变化的类库，以轻巧、实用、强大而闻名。\n\nps:源代码未压缩版仅仅只有158行代码:)\n\n### 安装\n\n```js\nnpm install obajs\n```\n\n## 3分钟精通observe.js\n\n### 对象字面量\n```javascript\nvar obj = { a: 1 };\nobserve(obj, function (name, value , old) {\n    console.log(name + \"__\" + value + \"__\" + old);\n});\nobj.a = 2; //a__2__1 \n```\n\n### 数组\n```javascript\nvar arr = [1, 2, 3];\nobserve(arr, function (name, value, old) {\n    console.log(name + \"__\" + value+\"__\"+old);\n});\narr.push(4);//Array-push__[1,2,3,4]__[1,2,3] \narr[3] = 5;//3__5__4\n```\n\n### 复杂对象\n```javascript\nvar complexObj = { a: 1, b: 2, c: [{ d: [4] }] };\nobserve(complexObj, function (name, value , old, path) {\n    console.log(name + \"__\" + value + \"__\" + old);   //d__100__4 \n\tconsole.log(path)\t                             //#-c-0\n});\ncomplexObj.c[0].d = 100;\n```\n### 普通对象\n```javascript\nvar User = function (name, age) {\n    this.name = name;\n    this.age = age;\n    //只监听name\n    observe(this, [\"name\"], function (name, value, oldValue) {\n        console.log(name + \"__\" + value + \"__\" + oldValue);\n    });\n}\nvar user = new User(\"lisi\", 25);\nuser.name = \"wangwu\";//name__wangwu__lisi \nuser.age= 20; //什么都输出，因为没有监听age\n```\n\n\nThis content is released under the (http://opensource.org/licenses/MIT) MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdntzhang%2Foba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdntzhang%2Foba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdntzhang%2Foba/lists"}