All Projects → HeskeyBaozi → umi-plugin-mobx

HeskeyBaozi / umi-plugin-mobx

Licence: MIT license
😍 use mobx-state-tree gracefully in umijs.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to umi-plugin-mobx

umi-plugins
Umi Plugins
Stars: ✭ 14 (-57.58%)
Mutual labels:  umi, umi-plugin
umi-plugin-menus
将 umi 生成的 routes 转换成 tree 结构 menus 数据,开发中可直接引入该文件来进行导航菜单的生成
Stars: ✭ 29 (-12.12%)
Mutual labels:  umi, umi-plugin
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (+127.27%)
Mutual labels:  mobx, mobx-state-tree
mst-effect
💫 Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-42.42%)
Mutual labels:  mobx, mobx-state-tree
umi-react-native
umi preset plugins for react-native
Stars: ✭ 54 (+63.64%)
Mutual labels:  umi, umi-plugin
umi-plugin-electron-builder
umi的electron插件
Stars: ✭ 115 (+248.48%)
Mutual labels:  umi, umi-plugin
mobx-state-tree-router
State-based router for React and MobX State Tree
Stars: ✭ 18 (-45.45%)
Mutual labels:  mobx, mobx-state-tree
umi-plugin-md
🍚 Markdown(*.md) component plugin for umi.
Stars: ✭ 16 (-51.52%)
Mutual labels:  umi, umi-plugin
react-mobx-router
Create React App with React Router 4 and MobX + Internationalization
Stars: ✭ 90 (+172.73%)
Mutual labels:  mobx, mobx-state-tree
Mobx State Tree
Full-featured reactive state management without the boilerplate
Stars: ✭ 6,317 (+19042.42%)
Mutual labels:  mobx, mobx-state-tree
mobx-easy
MobX made easier
Stars: ✭ 24 (-27.27%)
Mutual labels:  mobx
simpleCMS
simpleCMS是一款开源cms系统, 主要为个人/团队快速开发博客或者知识共享平台, 类似于hexo, worldpress, 但是他们往往需要复杂的搭建过程, 我们将复杂度降到最低, 并且有详细的部署教程, 你只需要有一台服务器, 就能轻松拥有一个属于你的博客平台.
Stars: ✭ 74 (+124.24%)
Mutual labels:  umi
FlutterSupportChat
App flutter demonstrando o uso das seguintes tecnologias: Firebase, MobX e Flutter Modular.
Stars: ✭ 23 (-30.3%)
Mutual labels:  mobx
Pulse
✨ Pulse is a global state and logic framework for reactive Typescript & Javascript applications. Supporting frameworks like VueJS, React and React Native.
Stars: ✭ 243 (+636.36%)
Mutual labels:  mobx
React Book
《React进阶之路》示例代码
Stars: ✭ 249 (+654.55%)
Mutual labels:  mobx
React Cnodejs.org
Material UI version of cnodejs.org, the biggest Node.js Chinese community.
Stars: ✭ 242 (+633.33%)
Mutual labels:  mobx
mobx-router5
Router5 integration with mobx
Stars: ✭ 22 (-33.33%)
Mutual labels:  mobx
egg-view-assets
Manage frontend assets in development and production.
Stars: ✭ 51 (+54.55%)
Mutual labels:  umi
Delorean
A MobX-React Time Travel Debugger
Stars: ✭ 238 (+621.21%)
Mutual labels:  mobx
taro-ts-mobx-boilerplate
Taro 脚手架 Typescript/ Mobx / icon font / Jest
Stars: ✭ 12 (-63.64%)
Mutual labels:  mobx

😍 use mobx-state-tree with umi gracefully.

NPM version NPM downloads

中文文档 Docs Chinese version

Features

  • Automatically wrap route components with state tree nodes.
  • Support dynamic import state tree nodes by using umi/dynamic.
  • Use Mobx ecosystem rather than Redux.
  • Resolve rules are same with umi-plugin-dva, so you just export a state tree node by default.

🚀 Install

yarn add umi-plugin-mobx

🛠 Usage

Add plugin

Add plugin to .umirc.js file, to ignore the model folders which are named stores or other custom name, you need to install umi-plugin-routes to tell umi to ignore them.

Install umi-plugin-routes.

yarn add umi-plugin-routes
// .umirc.js

export default {
  plugins: [
    ['umi-plugin-mobx', {
      modelName: 'store', // or "stores", defaults to "store", you can set "model" like dva.
      exclude: [/^\$/, (filename) => filename.includes('__')]
    }],
    ['umi-plugin-routes', {
      exclude: [/stores/] // ignore **/stores/**/*.*, you can set /models/ like dva.
    }]
  ]
}

[Deprecated] You can also just use page.jsx or page.tsx to skip umijs dirctory resolving.

  • options
interface PluginOptions {
  modelName?: string;
  exclude?: Excludes;
}

type Excludes = (RegExp | TestFn)[];
type TestFn = (filename: string) => boolean;

Config Mobx

Mobx config documents.

// src/mobx.ts
// or src/mobx.js
export function config() {
  return {
    enforceActions: true // or 'strict' for strict-mode
  };
}

📦 Examples

How to run examples?

If you want to run user-dashboard...

git clone https://github.com/HeskeyBaozi/umi-plugin-mobx
cd umi-plugin-mobx
yarn install
yarn link
cd examples/user-dashboard
yarn install
yarn link "umi-plugin-mobx"
yarn start

MST Node Example:

// examples/user-dashboard/src/pages/users/stores/users.ts
// mobx-state-tree version like dva's model.
// dva version: https://github.com/umijs/umi-dva-user-dashboard/blob/master/src/pages/users/models/users.js

import { AxiosResponse } from 'axios';
import { applyAction, flow, types } from 'mobx-state-tree';
import { Loading } from '../../../stores/$loading';
import { $ } from '../../../utils';
import { User } from './$user';

const Users = types
  .compose(Loading, types.model({
    list: types.array(User),
    total: types.maybe(types.number),
    page: types.maybe(types.number)
  }))
  .named('users')
  .volatile((self) => {
    return {
      PAGE_SIZE: 5
    };
  })
  .actions((self) => {
    return {
      fetchAsync: flow(function* fetchAsync({ page }: { page: number }) {
        const { data, headers }: AxiosResponse<any[]> = yield $.get(`/users?_page=${page}&_limit=${self.PAGE_SIZE}`);
        self.list.clear();
        self.list.push(...data);
        self.total = Number.parseInt(headers['x-total-count']);
        self.page = page;
      }),
      removeAsync: flow(function* removeAsync({ id }: { id: number }) {
        yield $.delete(`/users/${id}`);
      }),
      updateAsync: flow(function* updateAsync({ id, values }: { id: number, values: object }) {
        yield $.patch(`/users/${id}`, JSON.stringify(values));
      }),
      createAsync: flow(function* createAsync({ values }: { values: object }) {
        yield $.post(`/users`, JSON.stringify(values));
      })
    };
  });

export type UsersType = typeof Users.Type;
export default Users.create({
  list: [],
  total: null
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].