自从 Mobx 3.6 上次更新到 Mobx 4 以来,我的应用程序就停止工作了。我正在使用react-native,并且只是按照说明迁移到最新功能,但我的应用程序不断崩溃,显示以下错误:
[mobx] 有多个活动的 mobx 实例。这可能会导致意外结果:有关详细信息,请参阅https://github.com/mobxjs/mobx/issues/1082。
我刚刚创建了一个简单的可观察对象,代码如下:
import React, { Component } from "react";
import { observable } from "mobx";
const ProductsStore = observable.object(
{
selectedProduct: null,
products: [
{
id: 1,
name: "NVIDIA 1050TI",
desc: "4GB OC",
model: "ASUS",
price: 1050,
quantity: 1
},
{
id: 2,
name: "NVIDIA 1060TI",
desc: "6GB OC",
model: "EVGA",
price: 1050,
quantity: 1
},
{
id: 3,
name: "NVIDIA 1070TI",
desc: "8GB OC", …Run Code Online (Sandbox Code Playgroud) 我是新手,无法解决这个问题。
无法编译您的应用程序,因为无法建立其依赖关系。以下 Dart 文件:/Users/anirudhsharma392/Desktop/flutter/testing/lib/counter/counter.dart ...在导入中引用以下库:/Users/anirudhsharma392/Desktop/flutter/testing/lib/ counter/counter.g.dart 不幸的是,该库似乎不存在于您的文件系统中。
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mobx/mobx.dart';
part 'counter.g.dart';
class Counter = CounterBase with _$Counter;
abstract class CounterBase implements Store {
@observable
int value = 0;
@action
void increment() {
value++;
}
}
class CounterExample extends StatefulWidget {
const CounterExample({Key key}) : super(key: key);
@override
_CounterExampleState createState() => _CounterExampleState();
}
class _CounterExampleState extends State<CounterExample> {
final _counter = Counter();
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Counter'),
),
body: Center(
child: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将多个函数包装在一个函数中。
我有一个这样的模型:
const CookModel = types.actions(self =>({
talkToSousChefs:() => {
// talk to sous-chefs
},
talkToWaiters: () => {
// business logic
},
talkToVendors: () => {
// business logic
},
runTalkRoutine: () => {
// current code
const root = getRoot<typeof CookModel>(self)
root.talkToSousChefs()
root.talkToVendors()
root.talkToWaiters()
// what's the best practice?
}
}))
Run Code Online (Sandbox Code Playgroud)
将这些操作包含在内的最佳方式是什么runTalkRoutine?
我正在从两个文件夹创建 React Web 应用程序,应用程序内的动态路由返回这些错误。静态路由工作得很好。我收到错误: Uncaught SyntaxError: Unexpected token '<' manifest.json:1 Manifest: Line: 1, column: 1, Syntax error。
import React, { Component } from 'react';
import './NavBar.css';
import Axios from 'axios';
import { observer } from 'mobx-react';
import UserStore from '../../src/Stores/UserStore';
class NavBar extends Component {
constructor(props) {
super(props);
this.state = {
results: {},
apiLoading: false,
message: ''
};
}
async componentDidMount() {
try{ //check if the user is logged in
let res = await fetch('/isLoggedIn', {
method: 'post',
headers: { …Run Code Online (Sandbox Code Playgroud) 首先,我不是经验丰富的React开发人员。只是让你知道。
我有一家商店:
import {observable, action, reaction, computed, autorun} from 'mobx';
import scrollTo from 'react-scroll-to-component'
Run Code Online (Sandbox Code Playgroud)
ActivePostsStore类{
@observable _posts = new Map()
@observable _visiblePosts = new Set()
@computed get visiblePosts() {
return this._visiblePosts
}
@action
addPost(uuid, ref) {
// console.log('add post')
this._posts.set(uuid, ref)
}
@action
scrollToPost(uuid) {
// console.log('scroll to post')
scrollTo(this._posts.get(uuid), {})
}
@action
addVisiblePost(uuid) {
console.log('add vis post', this._visiblePosts.values())
this._visiblePosts.add(uuid)
}
@action
removeVisiblePost(uuid) {
console.log('rem vis post', this._visiblePosts.values())
this._visiblePosts = new Set([...this._visiblePosts].filter(el => el !== uuid))
}
// reacts = …Run Code Online (Sandbox Code Playgroud)