mobx

How to navigate in mobx store using react navigation?

ⅰ亾dé卋堺 提交于 2019-12-01 11:38:38
问题 I can use this.props.navigation from screen component to navigate. How should I do the similar in mobx store file? Or should I perform navigation in store? I read the Navigating without the navigation prop article, but it seems only works for screen components, right? Someone says use global variable to store a this.props.navigation reference and use it anywhere, but I don't like the idea... 回答1: Yes either: forward the navigation class to the store when calling the method: // add nivagation

Using MobX observable decorators with create-react-app

浪尽此生 提交于 2019-11-30 19:01:01
The MobX docs tell me I must "use the transform plugin transform-decorators-legacy and make sure it is first in the plugins list", in order for the decorators to work. The MobX boilerplate project suggests I need a .babelrc like: { "presets": [ "react", "es2015", "stage-1" ], "plugins": ["transform-decorators-legacy", "react-hot-loader/babel"] } How do I do that with a create-react-app generated project? Any attempt to use @ decorators errors. There is no .babelrc even after the project is 'ejected'. You can not use decorator syntax unless you eject . However, you can use MobX without @ since

面向未来的前端数据流框架 - dob

百般思念 提交于 2019-11-30 14:44:55
我们大部分对内产品,都广泛使用了 dob 管理前端数据流,下面隆重介绍一下。 dob 是利用 proxy 实现的数据依赖追踪工具,利用 dob-react 与 react 结合。 dob 的核心思想大量借鉴了 mobx ,但是从实现原理、使用便捷性,以及调试工具都做了大量优化。 特征 ✅ 支持 ❌ 不支持 📦 生态支持 🤷 不完全支持 功能 redux mobx dob 异步 📦 redux-thunk 等 ✅ ✅ 可回溯 ✅ 📦 mst ✅ 分形 🤷 replaceReducer ✅ ✅ 代码精简 📦 dva 等 ✅ ✅ 函数式 ✅ 🤷 🤷 面向对象 🤷 ✅ ✅ Typescript 支持 🤷 ✅ ✅ 调试工具 ✅ ✅ ✅ 调试工具 action 与 UI 双向绑定 ❌ 🤷 ✅ 严格模式 ✅ ✅ 支持原生 Map 等类型 ❌ ✅ observable 语法自然度 ❌ ✅ store 规范化 ✅ 🤷 ✅ 从依赖追踪开始 dob 自己只实现了依赖追踪功能,其特性非常简单,如下示意图+代码所示: img import { observable, observe } from "dob" const obj = observable({ a : 1 , b : 1 }) observe( () => { console .log(obj.a) }) 一句话描述就是:由

从时间旅行的乌托邦,看状态管理的设计误区

有些话、适合烂在心里 提交于 2019-11-30 14:30:25
Redux 的状态管理理念非常优雅,随之附带的时间旅行调试支持也非常酷炫。但这个特性是否是传说中的银弹,又会给使用者带来什么额外的负担呢?让我们重新思考一下吧。 什么是时间旅行? 在 2015 年的 React Europe 会议上,Dan Abramov 展示了通过 Redux DevTools 让开发者在历史状态中自由穿梭,从而提升调试体验的 Demo ,这个工具的使用体验非常惊艳,也取得了非常好的反响。在此之后,Vuex 与 MobX 等状态管理库也陆续在它们的调试工具中引入了对类似功能的支持。 我们可以认为,前端状态管理领域中,狭义的『时间旅行』概念是在满足了下面这几个前提后,开发时在历史状态中任意回溯的功能: 将局部 state 统一到全局 store 中做状态管理。 开发环境中安装了与状态管理库配套的 DevTools,或引入了特殊的监控组件。 开发环境中启用了 Webpack 的 HMR 热加载。 需要特别注意的是,这个功能完全是 调试时 使用的。不过,由于这个能力给人的印象过于深刻,它也成为了许多人转向 React + Redux 技术栈的主要理由之一:漂亮的概念模型加上漂亮的调试体验,这套方案简直就是神器啊!而正如 React 第一个在浏览器里实现了声明式渲染一样,Redux 也第一个在浏览器里实现了理想中的调试体验,这些原创性的工作对前端领域的贡献是非常大的

Using MobX observable decorators with create-react-app

試著忘記壹切 提交于 2019-11-30 03:19:12
问题 The MobX docs tell me I must "use the transform plugin transform-decorators-legacy and make sure it is first in the plugins list", in order for the decorators to work. The MobX boilerplate project suggests I need a .babelrc like: { "presets": [ "react", "es2015", "stage-1" ], "plugins": ["transform-decorators-legacy", "react-hot-loader/babel"] } How do I do that with a create-react-app generated project? Any attempt to use @ decorators errors. There is no .babelrc even after the project is

How to use mobx in react-native 0.56 (Babel 7) with Decorators

懵懂的女人 提交于 2019-11-30 00:30:28
i've upgraded my RN app from 0.55.4 to 0.56 that use Babel 7. In 0.55.4 to use decorators for MOBX i use "babel-plugin-transform-decorators-legacy" but is not compatible with Babel 7... react-native ver: 0.56.0 mobx ver: 5.0.3 mobx-react ver: 5.2.3 does anyone have the solution? Thanks UPDATE: The app works in DEBUG with this configuration package.json ... "devDependencies": { "@babel/core": "7.0.0-beta.47", "@babel/plugin-proposal-decorators": "7.0.0-beta.47" ... } .babelrc { "presets": [ ["react-native"] ], "plugins": [ ["@babel/plugin-proposal-decorators", { "legacy": true }] ] } But in

Can't call setState on a component that is not yet mounted

拈花ヽ惹草 提交于 2019-11-29 09:18:34
this is the first time I face this warning message. Can't call setState on a component that is not yet mounted. Follows: This is a no-op, but it might indicate a bug in your application. Instead, assign to this.state directly or define a state = {}; class property with the desired state in the MyComponent component. The " not yet mounted " part actually makes little to no sense as the only way to trigger the issue is to call a function by clicking a button from a component that needs to be mounted in order to see the button. The component is not unmounted at any given time neither. This dummy