Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new feature need] 跨页面获取state 或者 全局store #90

Closed
guopeng1994 opened this issue Mar 19, 2019 · 3 comments
Closed

[new feature need] 跨页面获取state 或者 全局store #90

guopeng1994 opened this issue Mar 19, 2019 · 3 comments

Comments

@guopeng1994
Copy link

#43 这个里面有提到过,可以自定义provider 不过我觉得这个功能在app内还是挺常用的,所以后续可以考虑下加入。

@zjuwjf
Copy link
Contributor

zjuwjf commented Mar 19, 2019

全局可以自定义一个单例的store,在这样的场景下 用Provider 似乎也没有任何好处。

@evelynEdison
Copy link

@zjuwjf 请问如何全局定义一个单例的store,能给出具体代码吗?

@hyjfine
Copy link
Contributor

hyjfine commented Mar 21, 2019

类似于这样 @evelynEdison

class StoreUtil {
  static Store<AppState> _globalStore;
  static Store<AppState> get globalStore {
    if (_globalStore == null) {
      _globalStore = createStore<AppState>(AppState(), buildReducer());
    }
    return _globalStore;
  }
}

class AppState implements Cloneable<AppState> {
  @override
  AppState clone() {
    // TODO: implement clone
    return null;
  }
  
}

Reducer<AppState> buildReducer() {
  return asReducer<AppState>(<Object, Reducer<AppState>>{
    AppAction.request: _request,
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants