{"id":18832513,"url":"https://github.com/small-tou/s-mobx","last_synced_at":"2025-04-14T04:24:23.706Z","repository":{"id":148529401,"uuid":"89311160","full_name":"small-tou/s-mobx","owner":"small-tou","description":"轻量级mobx实现，仅供参考","archived":false,"fork":false,"pushed_at":"2017-04-25T06:13:16.000Z","size":3366,"stargazers_count":124,"open_issues_count":1,"forks_count":24,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-04T21:12:08.242Z","etag":null,"topics":["javascript","mobx","react"],"latest_commit_sha":null,"homepage":"","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/small-tou.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-04-25T03:01:55.000Z","updated_at":"2024-09-24T10:43:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"8c7e6097-dc0e-468d-9461-d3327a3ed20f","html_url":"https://github.com/small-tou/s-mobx","commit_stats":null,"previous_names":["yootou-dev/s-mobx","small-tou/s-mobx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/small-tou%2Fs-mobx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/small-tou%2Fs-mobx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/small-tou%2Fs-mobx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/small-tou%2Fs-mobx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/small-tou","download_url":"https://codeload.github.com/small-tou/s-mobx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248820184,"owners_count":21166619,"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":["javascript","mobx","react"],"created_at":"2024-11-08T01:58:04.033Z","updated_at":"2025-04-14T04:24:23.689Z","avatar_url":"https://github.com/small-tou.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 原理解析\n\n[如何自己实现一个mobx](./doc/readme.md)\n\n## 使用\n\n`npm install s-mobx --save`\n\n## 优势\n1. 兼容常用的mobx语法\n2. 打包后 6K，GZip后 2.3K(mobx+mobx-react:71K,GZip 20.9K)\n\n\n目前兼容的mobx用法：\n\n* @observable\n* @observer\n* @computed\n* extendObservable\n* createObservable\n* autorun\n\n## 前提\n\nbabel需要配置以下插件才可使用。（.babelrc，react-native项目默认包含此配置）\n```javascript\n\"plugins\": [\n  \"transform-decorators-legacy\",\n  \"transform-class-properties\"\n]\n```\n项目需依赖(package.json)：\n```javascript\n\"babel-plugin-transform-decorators-legacy\": \"*\",\n\"babel-plugin-transform-class-properties\": \"*\", // rn 不需要\n\"babel-preset-es2015\": \"*\" // rn 不需要\n```\n\n## 标注 observable 以及 autorun 的用法\n```javascript\nimport {\n  observable,\n  autorun,\n  computed\n} from 's-mobx';\nclass Person {\n  @observable\n  name = {\n    key:{\n      key:1\n    }\n  };\n  @computed get age() {\n    return this.name.key.key;\n  }\n\n}\nconst person = new Person();\n\nautorun(function(){\n  console.log(person.age);\n})\nperson.name.key.key = 3;\nperson.name.key.key = 4;\n\n```\n## 给React组件设置 observer\n\n```javascript\nimport {\n  observer,\n} from 's-mobx';\n\nimport React, {Component} from 'react';\n\nimport SettingStore from './../../stores/setting';\n\n@observer\nclass Index extends Component {\n    constructor() {\n        this.store = new SettingStore();\n    }\n\n    render() {\n        return (\n            \u003cIndexView store={this.store} /\u003e\n        );\n    }\n}\n\nexport default Index;\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmall-tou%2Fs-mobx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmall-tou%2Fs-mobx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmall-tou%2Fs-mobx/lists"}