前端框架选型是企业提升开发效率与用户体验的关键因素
610
2022-10-29
Mirror 是一款基于 React,Redux 和 react-router 的前端框架
Mirror
查看中文
A simple and powerful React framework with minimal API and zero boilerplate. (Inspired by dva and jumpstate)
Painless React and Redux.
Why?
We love React and Redux.
A typical React/Redux app looks like the following:
An actions/ directory to manually create all action types (or action creators)A reducers/ directory and tons of switch clause to capture all action typesApply middlewares to handle async actionsExplicitly invoke dispatch method to dispatch all actionsManually create history to router and/or sync with storeInvoke methods in history or dispatch actions to programmatically changing routes
The problem? Too much boilerplates and a little bit tedious.
In fact, most part of the above steps could be simplified. Like, create actions and reducers in a single method, or dispatch both sync and async actions by simply invoking a function without extra middleware, or define routes without caring about history, etc.
That's exactly what Mirror does, encapsulates the tedious or repetitive work in very few APIs to offer a high level abstraction with efficiency and simplicity, and without breaking the pattern.
Features
Minimal API(only 4 newly introduced)Easy to startActions done easy, sync or asyncSupport code splittingFull-featured hook mechanism
Getting Started
Creating an App
Use create-react-app to create an app:
$ npm i -g create-react-app$ create-react-app my-app
After creating, install Mirror from npm:
$ cd my-app$ npm i --save mirrorx$ npm start
index.js
import React from 'react'import mirror, {actions, connect, render} from 'mirrorx'// declare Redux state, reducers and actions,// all actions will be added to `actions`.mirror.model({ name: 'app', initialState: 0, reducers: { increment(state) { return state + 1 }, decrement(state) { return state - 1 } }, effects: { async incrementAsync() { await new Promise((resolve, reject) => { setTimeout(() => { resolve() }, 1000) }) actions.app.increment() } }})// connect state with componentconst App = connect(state => { return {count: state.app}})(props => (
Demo
Guide
See Guide.
API
See API Reference.
Examples
User-Dashboard (An example similar to dva-user-dashboard)CounterSimple-RouterTodo
Change log
See CHANGES.md.
FAQ
Does Mirror support TypeScript?
Yes, it does.
Does Mirror support Redux DevTools Extension?
Yes, Mirror integrates Redux DevTools by default to make your debugging more easily.
Can I use extra Redux middlewares?
Yes, specify them in mirror.defaults is all you need to do, learn more from the Docs.
I'm really into Redux-Saga, is there any way to use it in Mirror?
Yes of course, take a look at the addEffect option.
Which version of react-router does Mirror use?
react-router v4.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~