mobx-react

How can I access mobx store in another mobx store?

你说的曾经没有我的故事 提交于 2020-12-30 08:35:11
问题 Assume following structure stores/ RouterStore.js UserStore.js index.js each of ...Store.js files is a mobx store class containing @observable and @action . index.js just exports all stores, so import router from "./RouterStore"; import user from "./UserStore"; export default { user, router }; What is correct way to access one store inside another? i.e. inside my UserStore, I need to dispatch action from RouterStore when users authentication changes. I tired import store from "./index" inside

How can I access mobx store in another mobx store?

假装没事ソ 提交于 2020-12-30 08:34:26
问题 Assume following structure stores/ RouterStore.js UserStore.js index.js each of ...Store.js files is a mobx store class containing @observable and @action . index.js just exports all stores, so import router from "./RouterStore"; import user from "./UserStore"; export default { user, router }; What is correct way to access one store inside another? i.e. inside my UserStore, I need to dispatch action from RouterStore when users authentication changes. I tired import store from "./index" inside

How to determine when mobx computed variable is called.?

倾然丶 夕夏残阳落幕 提交于 2020-05-28 04:45:26
问题 I have been playing with mobx computed, but I am having trouble understanding what is happening with the following code: import React, { Component } from "react"; import { render } from "react-dom"; import { observable, computed } from "mobx"; import { observer } from "mobx-react"; @observer class Counter extends Component { @observable count = 0; @observable secondCount = 0; @computed get countString() { console.log("countString Computed"); return `${this.count} ${this.secondCount}`; }

redux 和 mobx 调研结果- mobx

帅比萌擦擦* 提交于 2020-03-19 12:44:18
3 月,跳不动了?>>> 调研方向 设计思想/基本用法/生态环境/性能优化 总结 设计思想 mobx 的设计思想我总结之后,主要有以下两点: 函数响应式编程; 任何源自应用状态的东西都应该自动地获得; mobx 不同于 redux 的单一数据源的统一管理,它可以有多个 store, 为了便于维护 ,每一个 store 都是一个类,这样便于维护和扩展; 同时,为了使数据可以自动更新,使用了响应式编程(异步数据流), 它使用了观察者模式和 装饰器模式 ,将 state 包裹成observable; 当state 有改变时(自己改变或是 action 触发), 就会相应的去更新由这个state 推导出来的 computed value 以及 reaction;(数据的更新主要由装饰器模式中的对类的修改 ); 它的工作流大致是这样子: 基本用法 mobx 与redux 一样也是单向数据流,核心概念是 state,computed value,reaction,action 等。它们的大概功能为: state: 包裹为 observable 的 的数据; computed values: 从当前 state 中计算出的值,类似与 vue 中的computed; reactions: 是当 state 改变时需要自动发生的副作用。比如打印到控制台、网络请求、递增地更新 React 组件树以修补

How to save Mobx state in sessionStorage

南楼画角 提交于 2020-03-17 10:32:05
问题 Trying to essentially accomplish this https://github.com/elgerlambert/redux-localstorage which is for Redux but do it for Mobx. And preferably would like to use sessionStorage. Is there an easy way to accomplish this with minimal boilerplate? 回答1: The easiest way to approach this would be to have a mobx "autorun" triggered whenever any observable property changes. To do that, you could follow my answer to this question. I'll put some sample code here that should help you get started: function

mobx 初试小结

倖福魔咒の 提交于 2020-02-27 11:39:17
在属性改变的瞬间,做处理;(只需要执行一次)使用 when;这个在检测属性变化时操作很有效;可以和 react 中state de preValue, currentValue 改写而成; componentDidMount() { when(() => this.props.taskStore!.settingVisible, () => this.getRobotInfo()); } 这里表示的是一旦settingVisible 为true,则执行后面的操作;使用 reaction() 不符合条件; Store 注入组件接口的形式必须是可选的 import { inject, observer } from 'mobx-react'; @inject('store’) @observer Class TodayTask extends React.Component <{**taskStore?: TaskStore**}>{} 实践后的总体感觉 mobx 灵活性好,但不好管理,状态不够清晰,如果组件内的状态使用 mobx 有点大材小用,不如 state, 如果比较大的项目使用 mobx, 并不会比 redux 节省代码,并且没有 redux 统一好管理;初次使用觉得有点鸡肋吧。 来源: oschina 链接: https://my.oschina.net/hyzccc

mobx react action binding

こ雲淡風輕ζ 提交于 2020-02-02 13:11:28
问题 For those who has written apps with mobx + react , I'm wondering if there's a better way to handle context issue (eg. this. returns undefined in mobx store) when using onClick event handler inside a react component w/ inject & observer . I have been writing the handler like onClick={actionFromStore.bind(this.props.theStore)} to resolve that issue, but it seems like there should be more concise way to do this that I'm not aware of. I'm not a mobx expert, any advice would be appreciated! The

mobx react action binding

旧街凉风 提交于 2020-02-02 13:11:23
问题 For those who has written apps with mobx + react , I'm wondering if there's a better way to handle context issue (eg. this. returns undefined in mobx store) when using onClick event handler inside a react component w/ inject & observer . I have been writing the handler like onClick={actionFromStore.bind(this.props.theStore)} to resolve that issue, but it seems like there should be more concise way to do this that I'm not aware of. I'm not a mobx expert, any advice would be appreciated! The