javascript - 如何在 mobx 商店,react-native 中启用严格模式
问题描述
如何在我的 react-native 地图中为我的 mobx 商店启用严格模式,我使用 mobx 商店以及反应上下文 API 和钩子。在阅读文档严格模式后,我只能更改操作中的可观察状态。
/contexts/index.js
import React from 'react'
import { ThemeStore } from '../stores/ThemeStore.js'
import { PostStore } from '../stores/PostStore.js'
export const storesContext = React.createContext({
postStore: new PostStore(),
themeStore: new ThemeStore(),
})
/stores/PostStore.js
import { observable, computed, action, flow } from "mobx";
import axios from 'axios';
export class PostStore
{
@observable postMessage = 'Nothing to see here';
@observable post = {};
@observable posts = [];
@observable pagination = {};
@observable postCount = 0;
@computed get visiblePosts()
{
return this.posts.filter( post => post.isVisible);
};
}
解决方案
如果我理解正确的话,你想在你的 mobx 商店中强制执行严格模式。那个命令是
import { configure } from 'mobx';
configure({ enforceActions: "observed" })
这将不允许您修改外部操作的状态。设置时,它会在活动的 mobx 实例上设置全局行为。
你可以在这里找到更多信息: https ://mobx.js.org/refguide/api.html#configure
推荐阅读
- algorithm - Omnet++:获取相邻路口列表
- java - 如何使用 JpaRepository 使用动态 batch_size 进行批量插入,即 batch_size 未知
- node.js - 问题以角度加密信息并在节点中解密
- javascript - 如何在两个 CSS 文档之间切换
- c++ - 避免将转换运算符复制到基类的子集
- python - pylint R1720: Unnecessary "elif" after "raise" (no-else-raise)
- windows-10 - 运行 datadog 命令时访问被拒绝
- java - 为什么`javac -cp`不需要`.`,而`java -cp`需要?
- ios - 当服务器远离时,AVPlayer 流式传输时间过长
- c# - CS0103 C# 当前上下文中不存在名称“ViewBag”和“Url”