{"id":15363324,"url":"https://github.com/i5ting/stateview","last_synced_at":"2025-04-15T07:30:58.950Z","repository":{"id":44797571,"uuid":"410195326","full_name":"i5ting/stateview","owner":"i5ting","description":"Stateview is a react render solution for Multi-State View.","archived":false,"fork":false,"pushed_at":"2021-12-28T07:09:12.000Z","size":1083,"stargazers_count":43,"open_issues_count":6,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T18:13:40.414Z","etag":null,"topics":["react","state","ui"],"latest_commit_sha":null,"homepage":"https://stackblitz.com/github/i5ting/stateview","language":"TypeScript","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/i5ting.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-25T06:29:17.000Z","updated_at":"2025-01-10T06:10:46.000Z","dependencies_parsed_at":"2022-09-02T17:22:53.242Z","dependency_job_id":null,"html_url":"https://github.com/i5ting/stateview","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i5ting%2Fstateview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i5ting%2Fstateview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i5ting%2Fstateview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i5ting%2Fstateview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i5ting","download_url":"https://codeload.github.com/i5ting/stateview/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249026700,"owners_count":21200493,"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":["react","state","ui"],"created_at":"2024-10-01T13:05:27.014Z","updated_at":"2025-04-15T07:30:58.533Z","avatar_url":"https://github.com/i5ting.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":" \n\u003cdiv\u003e\n  简体中文 ｜ \u003ca href=\"./README_EN.md\"\u003eEnglish\u003c/a\u003e\n\u003c/div\u003e\n\n\u003ch1 align=\"center\"\u003e Stateview \u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://img.alicdn.com/imgextra/i3/O1CN01ukckHc1yE7ND85M1s_!!6000000006546-2-tps-1088-970.png\" width=\"300\" /\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cstrong\u003e a react render solution for Multi-State View.\u003c/strong\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://badge.fury.io/js/stateview\"\u003e\u003cimg src=\"https://badge.fury.io/js/stateview.svg\" alt=\"npm version\" height=\"18\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://npmcharts.com/compare/stateview\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/stateview\" alt=\"download\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://standardjs.com\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/code_style-standard-brightgreen.svg\" alt=\"standardjs\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/i5ting/stateview\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/vue.svg\" alt=\"License\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/zhangyuang/i5ting/stateview\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/node-%3E=12-green.svg\" alt=\"Node\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\n## Features\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://img.alicdn.com/imgextra/i3/O1CN01mspQkq1mGc9AnkL9V_!!6000000004927-2-tps-2448-1372.png\"/\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\n- Compatible with JSX ([React](https://reactjs.org/)/[Remax](https://github.com/remaxjs/remax)/[Taro](https://github.com/NervJS/taro)/[Eva.js](https://github.com/eva-engine/eva.js))\n- Built-in the Multi-State View with {Stateview , Layer, setViewState }\n- Customize Data Dispatch via React Component props.data\n- Support the Nested Stateview\n\n## 预览\n\n可以通过[StackBlitz](http://stackblitz.com/)进行线上预览:\n\n[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/i5ting/stateview)\n\n## 安装\n\n    $ npm install --save stateview\n\n## 用法\n\n下面是3个示例，展示Stateview在多状态视图切换功能上的抽象和能力。\n\n- 示例1：最小示例，只有Logined和UnLogin二个状态，纯UI展示型，通过stateview.show切换视图\n- 示例2：数据示例，通过stateview.datashow切换状态来控制视图展示，视图组件在切换的时候，根据props.data进行渲染\n- 示例3：嵌套示例，主要演示复杂场景里多状态视图切换。\n- 示例4：分组示例，主要演示复杂场景同时存在多个Stateview命名空间冲突问题。\n\n### 最小示例\n\n最小示例，只有Logined和UnLogin二个状态。\n\n```js\nimport React from 'react';\n\nimport { Stateview, Layer, setViewState } from 'stateview';\n\n/**\n * 最简单的Demo：2个状态切换 \n */\nexport default () =\u003e {\n\n  function unlogin() {\n    setViewState('unlogin')\n  }\n\n  function logined() {\n    setViewState('logined')\n  }\n\n  return (\n    \u003cStateview default='unlogin'\u003e\n      \u003cLayer state='logined'\u003e\n        \u003ch1\u003eLogined, \u003cbutton onClick={unlogin}\u003ego to UnLogin\u003c/button\u003e\u003c/h1\u003e\n      \u003c/Layer\u003e\n      \u003cLayer state='unlogin'\u003e\n        \u003ch1 \u003eUnLogin, \u003cbutton onClick={logined}\u003ego to Logined\u003c/button\u003e\u003c/h1\u003e\n      \u003c/Layer\u003e\n    \u003c/Stateview\u003e\n  );\n}\n\n```\n\n### 数据示例\n\n```js\nimport React from 'react';\n\nimport { Stateview, Layer, setViewState } from 'stateview';\n\nconst Logined = (props: any) =\u003e {\n  function unlogin() {\n    setViewState('unlogin', { name: 'unlogin i5ting' })\n  }\n  return (\u003ch1\u003eLogined, \u003cbutton onClick={unlogin}\u003e{props.data.name}\u003c/button\u003e\u003c/h1\u003e)\n}\n\nconst UnLogin = (props: any) =\u003e {\n  return (\u003ch1 \u003eUnLogin, \u003cbutton onClick={props.action}\u003e{props.data.name}\u003c/button\u003e\u003c/h1\u003e)\n}\n\nexport default (props: any) =\u003e {\n\n  function logined() {\n    setViewState('logined', { name: 'logined i5ting' })\n  }\n\n  return (\n    \u003cspan\u003e\n      \u003cStateview default='unlogin' data={{ name: 'somename' }}\u003e\n        \u003cLayer state='logined' component={\u003cLogined /\u003e} /\u003e\n        \u003cLayer state='unlogin' component={\u003cUnLogin action={logined} /\u003e} /\u003e\n      \u003c/Stateview\u003e\n    \u003c/span\u003e\n  );\n}\n```\n\n### 嵌套示例\n\n带嵌套的3个状态示例\n\n```js\n- root\n    - 已登录logined\n        - 可领 candraw\n        - 次数不足 notdraw\n    - 未登录unlogin\n```\n\nentry\n\n```js\nimport React from 'react';\n\nimport { Stateview, Layer } from 'stateview';\nimport { Logined, UnLogin } from '../layers/1';\n\nexport default () =\u003e {\n  return (\n    \u003cStateview default='unlogin'\u003e\n      \u003cLayer state='logined' component={\u003cLogined name='跳转到未登录状态' /\u003e} /\u003e\n      \u003cLayer state='unlogin' component={\u003cUnLogin name='跳转到登录状态' /\u003e} /\u003e\n    \u003c/Stateview\u003e\n  );\n}\n```\n\nunlogin\n\n```js\nimport React from 'react';\nimport { setViewState } from 'stateview';\n\nexport function UnLogin(props: any) {\n\n  function sayHello() {\n    setViewState('logined')\n  }\n\n  return \u003ch1 \u003eUnLogin, \u003cbutton onClick={sayHello}\u003e{props.name}\u003c/button\u003e\u003c/h1\u003e;\n}\n```\n\nlogined\n\n```js\nimport React from 'react';\nimport { Stateview, Layer, setViewState } from 'stateview';\nimport { CanDraw, NotDraw } from './logined/index';\n\nexport function Logined(props: any) {\n\n  function sayHello() {\n    setViewState('unlogin')\n  }\n\n  return \u003c\u003e\n    \u003ch1\u003eLogined, \u003cbutton onClick={sayHello}\u003e{props.name}\u003c/button\u003e\u003c/h1\u003e\n    \u003cStateview default='notdraw'\u003e\n      \u003cLayer state='candraw' component={\u003cCanDraw name='跳转到未登录状态' /\u003e} /\u003e\n      \u003cLayer state='notdraw' component={\u003cNotDraw name='跳转到可领状态' /\u003e} /\u003e\n    \u003c/Stateview\u003e\n  \u003c/\u003e;\n}\n```\n\n### 分组示例\n\n分组表达，主要解决复杂场景同时存在多个Stateview命名空间冲突问题。通过window.stateview['alfred']，具体方法和window.stateview上的一样。\n\n```js\nimport React from 'react';\n\nimport { Stateview, Layer, getStateview } from 'stateview';\n\n/**\n * 最简单的分组Demo：2个状态切换 \n */\nexport default (props: any) =\u003e {\n\n  function unlogin() {\n    getStateview('alfred').setViewState('unlogin')\n  }\n\n  function logined() {\n    getStateview('alfred').setViewState('logined')\n  }\n\n  return (\n    \u003cStateview default='unlogin' group='alfred'\u003e\n      \u003cLayer state='logined'\u003e\n        \u003ch1\u003eLogined, \u003cbutton onClick={unlogin}\u003ego to UnLogin\u003c/button\u003e\u003c/h1\u003e\n      \u003c/Layer\u003e\n      \u003cLayer state='unlogin'\u003e\n        \u003ch1 \u003eUnLogin, \u003cbutton onClick={logined}\u003ego to Logined\u003c/button\u003e\u003c/h1\u003e\n      \u003c/Layer\u003e\n    \u003c/Stateview\u003e\n  );\n}\n\n```\n\n## 文档\n\n- [Introduction](./docs/introduction.md)\n- [Quick Start](./docs/quick-start.md)\n- [API](./docs/api.md)\n- [Concept](./docs/concept.md)\n- [Design](./docs/design.md)\n- [Data](./docs/data.md)\n- [Examples](./example)\n\n## 运行示例方法\n\n```shell\n$ npm i \n$ npm run dev\n```\n\n## 参与贡献\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\nRefer to the [CONTRIBUTING](./CONTRIBUTING.md).\n\n## License\n\nCopyright © i5ting. All rights reserved.\n\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi5ting%2Fstateview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi5ting%2Fstateview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi5ting%2Fstateview/lists"}