1

我喜欢 mobx,并在一些平板电脑上实现了一个小应用程序,但在 Android WebView 上遇到了旧 javascript 的问题(由于平板电脑的年龄,我无法升级)。

Android 平板电脑:Nexus 4.4(棒棒糖)

错误如下,尽管 mobx.js 文件(下面的函数)中的 2740 左右看起来与旧 javascript 引擎的 @observables 存在问题。

我目前正在使用 webpack(见下文)来转换我的 js。对此的任何帮助将不胜感激,因为我真的很想继续使用 mobx。

真诚的,克里斯

mobx.js 中的第 2740 行

function isES6Map (thing) {
  if (thing instanceof getGlobal().Map) {
    return true;
  }
  return false;
}

控制台错误:

[mobx] 捕获了由反应或观察者组件引发的未捕获异常,在:'Reaction[CustomerFeedback#0.render()] 类型错误消息:“在 instanceof 检查中期待一个函数,但得到了位置页面”堆栈:(. ..) get stack: function () { [native code] } set stack: function () { [native code] } proto: Error mobx.js:1284 Reaction.reportExceptionInDerivation

网络包:

'use strict';

const autoprefixer = require('autoprefixer');
const copyWebpackPlugin = require('copy-webpack-plugin');
const extractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');

const scssLoaders = [
  'css-loader',
  'postcss-loader',
  'sass-loader?indentedSyntax=false&includePaths[]=' + path.resolve(__dirname, './application')
];

const config = {
  debug: true,
  devtool: 'source-map',
  entry: ['babel-polyfill', './index.js'],
  module: {
    loaders: [
      {
        test: /.(js|jsx)$/,
        exclude: /node_modules/,
        loader: ['babel-loader'],
        query: {
          cacheDirectory: true,
          plugins: [
            'transform-decorators-legacy',
            'transform-class-properties',
            'mobx-deep-action'
          ],
          presets: ['es2015', 'stage-0', 'react'],
          babelrc: false
        }
      },
      {
        test: /.scss$/,
        loader: extractTextPlugin.extract('style-loader', scssLoaders.join('!'))
      },
      {
        test: /.(svg|jpg|png)$/,
        loader: 'file-loader?name=/media/[name].[ext]'
      }
    ]
  },

  output: {
    path: path.join(__dirname, './build'),
    publicPath: '/build',
    filename: '[name].js'
  },

  plugins: [
    new extractTextPlugin('[name].css')

  ],

  postcss: [
    autoprefixer({
      browsers: ['last 2 versions']
    })
  ],

  resolve: {
    extensions: ['', '.js', '.jsx', '.scss'],
    modulesDirectories: ['./node_modules/'],
    root: [path.join(__dirname, './application')]
  }
};

module.exports = config;

应用状态文件:

import { action, computed, extendObservable, toJS } from 'mobx';

class CustomerFeedbackState {
  constructor() {
    // Initializes all observables
    this.initializeStoreData();
  }

  /* ACTIONS */
  // Initialize the store's state, allowing a reinitialization of the app as needed (reset to default state)
  @action initializeStoreData() {
    extendObservable(this, {
      // Keeps track of what page the user is on - 'locations-page' is the start page
      currentPageName: 'locations-page',

      // Keeps track of what question is being asked
      currentQuestionNumber: 0,

      // Set to true when the JSON data comes back successful
      dataFetched: false,

      // sets the active state for the next button
      disableNextPage: true,

      // Keeps track of page history
      lastPageVisitedArray: [],

      // Current Location Id
      locationId: 0,

      // Mood link active states
      moodLinkHappyIsActive: false,
      moodLinkNeutralIsActive: false,
      moodLinkSadIsActive: false,

      // Next page available
      nextPage: '',

      // User mood
      userMood: ''
    });
  },
  // ...
}
4

1 回答 1

2

上周的 3.0.2 版本修复了这个问题(根据 mobx 开发人员的反馈)。

于 2017-02-03T15:06:50.587 回答