{"id":18293718,"url":"https://github.com/museui/muse-model","last_synced_at":"2025-07-22T08:33:12.018Z","repository":{"id":57305543,"uuid":"138164176","full_name":"museui/muse-model","owner":"museui","description":"优化vuex的状态流写法， 按需加载每个模块","archived":false,"fork":false,"pushed_at":"2018-09-13T16:33:58.000Z","size":105,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-03T02:40:27.289Z","etag":null,"topics":[],"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/museui.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":"2018-06-21T11:56:21.000Z","updated_at":"2019-07-29T06:53:06.000Z","dependencies_parsed_at":"2022-09-09T06:11:37.436Z","dependency_job_id":null,"html_url":"https://github.com/museui/muse-model","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/museui/muse-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/museui%2Fmuse-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/museui%2Fmuse-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/museui%2Fmuse-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/museui%2Fmuse-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/museui","download_url":"https://codeload.github.com/museui/muse-model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/museui%2Fmuse-model/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266456245,"owners_count":23931383,"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-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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-11-05T14:25:51.294Z","updated_at":"2025-07-22T08:33:11.991Z","avatar_url":"https://github.com/museui.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# muse-model\n\n对vuex功能的一个增强，简化了状态流程的写法。增加按需引入model的控制\n\n## 安装\n\n```bash\nnpm install muse-model\n```\n\nor\n\n```bash\nyarn add muse-model\n```\n\n## 快速上手\n\n```javascript\n// model.js\nimport Vue from 'vue';\nimport MuseModel, { createMuseModel } from '../../src';\nVue.use(MuseModel);\n\nexport default createMuseModel({\n  strict: true\n});\n```\n\n```javascript\n// main.js\nimport Vue from 'vue';\nimport store from 'model'; // model.js\nimport App from './App';\n\nnew Vue({\n  ...App,\n  store\n}).$mount('app');\n```\n\n```javascript\nimport { Model } from 'muse-model';\n// count.js\nexport default Model({\n  namespace: 'count', // 必须\n  state: {\n    count: 1\n  },\n\n  add () {\n    return {\n      count: this.state.count + 1\n    };\n  },\n\n  sub () {\n    return {\n      count: this.state.count - 1\n    };\n  },\n  doubleAdd () {\n    this.add();\n    return {\n      count: this.state.count + 1\n    }\n  },\n\n  addTimeOut () { // 异步处理\n    return new Promise((resolve, reject) =\u003e {\n      setTimeout(() =\u003e {\n        resolve({\n          count: this.state.count + 1\n        });\n      }, 1000);\n    });\n  }\n});\n```\n\n```html\n\u003ctemplate\u003e\n\u003cdiv\u003e\u003cbutton @click=\"addTimeOut()\"\u003e+\u003c/button\u003e{{count}}\u003cbutton @click=\"sub()\"\u003e-\u003c/button\u003e\u003c/div\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nimport Count from './count';\n\nexport default {\n    connect: Count, // Model / Array\u003cModel\u003e / Function\n    created () {\n      console.log(this.count);\n    }\n});\n\u003c/script\u003e\n```\n\n## Use Class Model\n\n```javascript\nimport { model, action, getter } from 'muse-model';\nexport default class Count {\n  state = {\n    count: 3,\n    list: {\n      loading: false\n    }\n  };\n\n  @action add () {\n    return {\n      count: this.state.count + 1\n    };\n  }\n  @action sub () {\n    return {\n      count: this.state.count - 1\n    };\n  }\n\n  @action addNum (num) {\n    this.add();\n    return {\n      count: this.state.count + num\n    };\n  }\n  @loading('list.loading')\n  @action\n  addTimeOut () {\n    return new Promise((res) =\u003e {\n      setTimeout(() =\u003e {\n        res({\n          count: this.state.count + 1\n        });\n      }, 2000);\n    });\n  }\n\n  @getter\n  computedCount () {\n    return this.state.count + 2;\n  }\n}\n```\n\n## License\n\n [MIT](http://opensource.org/licenses/MIT)\n\n Copyright (c) 2018 myron\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuseui%2Fmuse-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuseui%2Fmuse-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuseui%2Fmuse-model/lists"}