On this blog page,Captain Codeman介紹瞭如何使用Polymer 2.x實現Redux。但是,當我使用它時,出現以下錯誤,抱怨變量MyApp
未定義。在哪裏以及如何定義MyApp
變量?如何在Redux-thunk和Polymer 2.x中定義MyApp
我 - 終極版 - store.htmlUncaught ReferenceError: MyApp is not defined
at my-redux-store.html:23
at my-redux-store.html:42
(anonymous) @ my-redux-store.html:23
(anonymous) @ my-redux-store.html:42
user-setter-behavior.html:114 Uncaught ReferenceError: ReduxBehavior is not defined
at user-setter-behavior.html:114
(anonymous) @ user-setter-behavior.html:114
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/polymer-redux/polymer-redux.html">
<link rel="import" href="my-redux-actions.html">
<link rel="import" href="my-redux-middleware.html">
<link rel="import" href="my-redux-reducers.html">
<link rel="import" href="my-redux-selectors.html">
<script>
(function() {
const composeEnhancers = typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: Redux.compose;
const enhancer = composeEnhancers(
Redux.applyMiddleware(...MyApp.middleware),
);
const store = Redux.createStore(MyApp.rootReducer, enhancer);
const reduxMixin = PolymerRedux(store);
/* @mixinFunction */
const actionsMixin = (superClass) => {
return class extends reduxMixin(superClass) {
static get actions() {
return MyApp.actions
}
}
}
/* @mixinFunction */
MyApp.ReduxMixin = Polymer.dedupingMixin(actionsMixin);
}());
</script>