2017-07-17 93 views
2

我已经实现了这一点,但店里没有值(所有未定义):阵营mobx不注门店正常

这是商店:

export default class AppState { 

    // Is authenticated 
    @observable authenticated; 

    @action get authenticated() { 
     return this.authenticated; 
    } 

    doSomethingWithNoDecorator() { 
     return this.authenticated; 
    } 
} 

这是index.js:

const stores = { 
    AppState 
}; 

const renderApp = Component => { 
    render(
     <AppContainer> 

      <Provider { ...stores }> 
       <Router> 
        // Routes 
       </Router> 
      </Provider> 
     </AppContainer>, 
     document.getElementById("root") 
    ); 
}; 

这是组件:

@inject("AppState") 
@observer 
export default class SidebarListItem extends Component { 

    constructor(props) { 
     super(props) 
     this.store = this.props.AppState; 
    } 

    doSomething() { 
     this.store.authenticated(); 
     this.store.doSomethingWithNoDecorator(); 
     this.store.authenticated;   
    } 
} 

商店不是空...我可以看到该功能。但我无法获取任何字段或调用任何方法。

我做错了什么?

问候, Idob

回答

0

您需要初始化您的商店:

const stores = { AppState: new AppState() } 

顺便说一句,@actions不能应用于干将。