如何在 Redux-thunk 和 Polymer 中定义 MyApp 2.x
How to define MyApp in Redux-thunk and Polymer 2.x
On this blog page,Codeman 队长描述了如何用Polymer 实现Redux 2.x。但是,当我使用它时,出现以下错误,抱怨变量 MyApp
未定义。我应该在哪里以及如何定义 MyApp
变量?
Uncaught 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
我的-redux-store.html
<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>
MyApp
只是一个全局命名空间,就像 Polymer
对象一样。在上一篇文章中有说明,它是从引用开始的。
MyApp = {}
或者,如果您使用的是严格模式,也许:
window.MyApp = {}
如果未使用类似以下内容定义,您也可以创建它:
MyApp = MyApp || {}
On this blog page,Codeman 队长描述了如何用Polymer 实现Redux 2.x。但是,当我使用它时,出现以下错误,抱怨变量 MyApp
未定义。我应该在哪里以及如何定义 MyApp
变量?
我的-redux-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>
MyApp
只是一个全局命名空间,就像 Polymer
对象一样。在上一篇文章中有说明,它是从引用开始的。
MyApp = {}
或者,如果您使用的是严格模式,也许:
window.MyApp = {}
如果未使用类似以下内容定义,您也可以创建它:
MyApp = MyApp || {}