{"id":18723612,"url":"https://github.com/windygex/royjs","last_synced_at":"2025-04-12T14:53:56.963Z","repository":{"id":38240324,"uuid":"142239245","full_name":"windyGex/royjs","owner":"windyGex","description":"Royjs is only 4.8kb mvvm framework for React","archived":false,"fork":false,"pushed_at":"2022-06-23T02:43:19.000Z","size":7020,"stargazers_count":54,"open_issues_count":4,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T17:15:30.381Z","etag":null,"topics":["framework","mvvm","react","state-management"],"latest_commit_sha":null,"homepage":"https://www.yuque.com/xiaoshengbuxiao/royjs/yb1k9u","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/windyGex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-07-25T02:54:08.000Z","updated_at":"2023-09-26T11:52:15.000Z","dependencies_parsed_at":"2022-09-04T22:11:47.835Z","dependency_job_id":null,"html_url":"https://github.com/windyGex/royjs","commit_stats":null,"previous_names":["windygex/roy"],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windyGex%2Froyjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windyGex%2Froyjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windyGex%2Froyjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windyGex%2Froyjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/windyGex","download_url":"https://codeload.github.com/windyGex/royjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586238,"owners_count":21128995,"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":["framework","mvvm","react","state-management"],"created_at":"2024-11-07T13:49:15.105Z","updated_at":"2025-04-12T14:53:56.944Z","avatar_url":"https://github.com/windyGex.png","language":"JavaScript","readme":"# Roy  ![buildStatus](https://travis-ci.org/windyGex/royjs.svg?branch=master)\n\nA powerful mvvm framework for react.\n\n## Install\n\n```shell\nnpm install @royjs/core --save\n```\n\n## Motive\n\n![image](https://img.alicdn.com/tfs/TB1rzpgGHGYBuNjy0FoXXciBFXa-627-241.png)\n\nThe state management is nothing more than changing the state from partial to partial sharing, so in an application, each component can be managed corresponding to a state, and only when this part needs to be shared, it is extracted.\n\n## Usage\n\n### Basic Usage\n\n```js\nimport {Store, inject} from '@royjs/core';\n\nconst store = new Store({\n    state: {\n        count: 0\n    },\n    actions: {\n        add(state, payload) {\n            state.count++;\n        },\n        reduce(state, payload) {\n            state.count--;\n        }\n    }\n});\n\n@inject(store)\nclass App extends React.Component {\n    render() {\n        const {count} = this.props.state;\n        return \u003cdiv onClick={() =\u003e this.props.dispatch('add')}\u003e{count}\u003c/div\u003e\n    }\n}\n\n```\n\n### Centralized Store\n\n```js\nimport {Store, connect} from '@royjs/core';\n\nconst store = new Store({}, {\n    plugins: [devtools]\n});\n\nstore.create('module1', {\n    state: {\n        name: 'module1'\n    },\n    actions: {\n        change(state, payload){\n            state.name = payload;\n        }\n    }\n});\n\nstore.create('module2', {\n    state: {\n        name: 'module2'\n    },\n    actions: {\n        change(state, payload){\n            state.name = payload;\n        }\n    }\n});\n\n@connect(state =\u003e state.module1)\nclass App extends React.Component {\n    onClick = () =\u003e {\n        this.props.dispatch('module2.change', 'changed name from module1');\n    }\n    render() {\n        return \u003cdiv onClick={this.onClick}\u003e{this.props.name}\u003c/div\u003e\n    }\n}\n\n@connect(state =\u003e state.module2)\nclass App2 extends React.Component {\n    render() {\n        return \u003cdiv\u003e{this.props.name}\u003c/div\u003e\n    }\n}\n```\n\n### Merge localStore to globalStore\n\n```js\nimport {Store, inject, connect} from '@royjs/core';\n\nconst store = new Store();\n\nconst subModuleStore = new Store({\n    state: {\n        name: 'subModule'\n    },\n    actions: {\n        change(state) {\n            state.name = 'subModuleChanged';\n        }\n    }\n})\n@inject(subModuleStore)\nclass SubModule extends React.Component {\n    render() {\n        return \u003cdiv onClick={() =\u003e this.props.dispatch('change')}\u003e{this.props.state.name}\u003c/div\u003e\n    }\n}\n\nstore.mount('subModule', subModuleStore);\n\n@connect(state =\u003e state.subModule)\nclass App extends React.Component {\n    render() {\n        return \u003cdiv\u003e{this.props.name}\u003c/div\u003e\n    }\n}\n```\n\n### Async Request\n\n```js\nimport {Store, inject} from '@royjs/core';\n\nconst store = new Store({\n    state: {\n        count: 0\n    },\n    actions: {\n        add(state, payload) {\n            state.count++;\n        },\n        reduce(state, payload) {\n            state.count--;\n        },\n        fetch(state, payload) {\n            this.request('./url').then(ret =\u003e {\n                state.dataSource = ret.ds;\n            });\n        }\n    }\n});\n\n@inject(store)\nclass App extends React.Component {\n    componentDidMount() {\n        this.props.dispatch('fetch');\n    }\n    render() {\n        const {dataSource} = this.props.state;\n        return \u003cdiv onClick={() =\u003e this.props.dispatch('add')}\u003e{dataSource}\u003c/div\u003e\n    }\n}\n```\n\n## Benchmark\n\nTest on my macbook pro (Intel Core i7 2.2GHz)\n\n![benchmark](https://img.alicdn.com/tfs/TB1n.LgIuSSBuNjy0FlXXbBpVXa-786-140.png)\n\n```shell\ntnpm run benchmark\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindygex%2Froyjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindygex%2Froyjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindygex%2Froyjs/lists"}