All Projects → stolenng → mobx-easy

stolenng / mobx-easy

Licence: other
MobX made easier

Programming Languages

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

Labels

Projects that are alternatives of or similar to mobx-easy

React Hooks Mobx State Tree
React Hooks + MobX State Tree + TypeScript = 💛
Stars: ✭ 169 (+604.17%)
Mutual labels:  mobx
Wechat Weapp Mobx
微信小程序(wechat weapp) mobx 绑定, 跨页面通信的利器, 现已发布npm包
Stars: ✭ 208 (+766.67%)
Mutual labels:  mobx
Delorean
A MobX-React Time Travel Debugger
Stars: ✭ 238 (+891.67%)
Mutual labels:  mobx
Feathers React Native Chat
A React Native example chat app using feathers
Stars: ✭ 189 (+687.5%)
Mutual labels:  mobx
Wiretap
🔍 A desktop app for inspecting mobx and mobx state tree apps
Stars: ✭ 198 (+725%)
Mutual labels:  mobx
Mobx Task
Makes async function state management in MobX fun.
Stars: ✭ 218 (+808.33%)
Mutual labels:  mobx
Multrin
Organize apps windows in tabs like in abandoned Windows Sets and more
Stars: ✭ 2,107 (+8679.17%)
Mutual labels:  mobx
React Book
《React进阶之路》示例代码
Stars: ✭ 249 (+937.5%)
Mutual labels:  mobx
Saas
Build your own SaaS business with SaaS boilerplate. Productive stack: React, Material-UI, Next, MobX, WebSockets, Express, Node, Mongoose, MongoDB. Written with TypeScript.
Stars: ✭ 2,720 (+11233.33%)
Mutual labels:  mobx
Heard
React Native Enterprise Social Messaging App
Stars: ✭ 234 (+875%)
Mutual labels:  mobx
Alldemo
🍑 2020全栈学习Demo大合集 包含最新 hooks TS 等 还有umi+dva,数据可视化等实战项目 (持续更新中)
Stars: ✭ 189 (+687.5%)
Mutual labels:  mobx
Mobx Share
🔑一个分享mobx的在线演示ppt
Stars: ✭ 196 (+716.67%)
Mutual labels:  mobx
Urban Bot
🤖 The universal chatbot library based on React. Write once, launch Telegram, Facebook, Slack, ... every messenger with chatbots
Stars: ✭ 223 (+829.17%)
Mutual labels:  mobx
Mobx React Lite
Lightweight React bindings for MobX based on React 16.8 and Hooks
Stars: ✭ 2,096 (+8633.33%)
Mutual labels:  mobx
React Cnodejs.org
Material UI version of cnodejs.org, the biggest Node.js Chinese community.
Stars: ✭ 242 (+908.33%)
Mutual labels:  mobx
Taming The State In React
📓Taming the State in React: Your journey to master Redux and MobX
Stars: ✭ 169 (+604.17%)
Mutual labels:  mobx
Mobx Logger
Log Mobx Actions, Reactions, Transactions and Computations
Stars: ✭ 210 (+775%)
Mutual labels:  mobx
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (+212.5%)
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 (+912.5%)
Mutual labels:  mobx
Embed
Pixel-perfect Discord chat widgets for your website 💬
Stars: ✭ 229 (+854.17%)
Mutual labels:  mobx

mobx-easy

mobx-easy is simple library that makes your day to day mobx usage easier and adds some extra abilities.

Full Docs here: http://mobx-easy.georgy-glezer.com/
Examples: https://github.com/stolenng/mobx-easy-examples

Intro

The idea for library came after a while using MobX and understanding i need some extra abilities, Checking out MobX-State-Tree and understanding i don't want to lose MobX simplicity i got.

So i decided to write this libraries and try to get out the maximum of MobX while keeping it simple :)

Article about it: https://levelup.gitconnected.com/introducing-mobx-easy-cd281ace9e6e.

Getting Started

Installation

The library requires MobX, to install simply run this command:

npm i mobx-easy

Wrapping The Root

So in order to start using the library you will need to do 2 things:

  • wrap the root instance of you application
  • add init function to the root instance

For example:

import {wrapRoot} from 'mobx-easy';

Class RootStore {
    init() {
        this.store1 = new Store1();
        this.store2 = new Store2();
    }
}

const env = {
    someService: {},
    someFlag: false
};

const rootStore = wrapRoot({
    RootStore: RootStore,
    env:  env,
    wrapperName?: "SomeName" // optional
})

And then you're ready to use addRoot|addRootByName|getRoot and addEnvironment|addEnvironmentByName|getEnv

wrapRoot

wrapRoot receives options object with this interface:

interface WrapRootOptions<E, R> {
  rootStoreConstructorParams?: RCP; // params to constructor function
  rootStoreInitParams?: RIP; // params to init function
  assignIdsToClasses?: boolean; // let mobx-easy assign its own ids to the classes by the field `mobx_easy_id`
  RootStore: new () => R; // Class Instance
  env: E; // Any Environment object you like
  wrapperName?: string; // Optional Name for multiple wrapping
}

RootStore - Should receives a Class with init function, why ? so we can initialize the class and only then init all other class so we can inject it.
env - Object that will hold the environment for this wrapped root, you can pass what ever you like here and then use it in all of root store context and stores.
wrapperName - For Application which have multiple rootStore, you can pass any name you like and then when using the library functions you just pass the name and you get corresponding root instance or environment object.

Getting The Root

After wrapping the root in the previous step, you can now inject the root instance to all of your stores inside the root you wrapped.

Why is useful? As a project grows and you have more and more stores, you start to write something like this:

Class RootStore {
    constructor(rootStore: RootStore) {
        this.someStore = new SomeStore(rootStore);
    }
}
Class SomeStore {
     constructor(rootStore: RootStore) {
        this.moreStore = new SomeStore(rootStore);
    }
}

and it can get infinite and you get the point.... So lets see the next tools :)

getRoot

Lets take the SomeStore, and add it getRoot from mobx-easy.

import {getRoot} from 'mobx-easy;

Class SomeStore {
     constructor() {
        this.moreStore = new SomeStore(getRoot());
    }
}

getRoot accepts a string, if you passed a name to the wrapper.

@addRoot

Lets take the SomeStore, and add it addRoot decorator from mobx-easy.
The decorator extends the class and adds it a method called getRoot which returns our root instance after it was wrapped.

import {addRoot} from 'mobx-easy;

@addRoot
Class SomeStore {
     constructor() {
        this.moreStore = new SomeStore(this.getRoot());
    }
}

@addRootByName

Same, but with a name passed for people using multiple root stores.

import {addRootByName} from 'mobx-easy;

@addRootByName("wrapperName")
Class SomeStore {
     constructor() {
        this.moreStore = new SomeStore(this.getRoot());
    }
}

removeRoot

For people who want to remove the root wrapped, can be useful when you need to remove the root on application destroy or mount or unmount of application component.

import {removeRoot} from 'mobx-easy';

componentWillUnmount() {
    removeRoot();
    
    removeRoot("wrapperName"); // by name
}

removeRoot - will remove single root or specific one by name.

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].