2017-08-10 79 views
1

On this blog page,Captain Codeman介紹瞭如何使用Polymer 2.x實現Redux。但是,當我使用它時,出現以下錯誤,抱怨變量MyApp未定義。在哪裏以及如何定義MyApp變量?如何在Redux-thunk和Polymer 2.x中定義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

我 - 終極版 - 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> 

回答

1

MyApp僅僅是一個全局命名空間,就像Polymer對象。在前面的文章中已經解釋了它是以引用開始的。

MyApp = {} 

,或者,如果您使用的嚴格模式,也許:

window.MyApp = {} 

您還可以創建它,如果它不使用類似定義:

MyApp = MyApp || {} 
相關問題