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

.d.ts文件版本问题 @types\reflux #525

Open
chenshuai2144 opened this issue Apr 11, 2017 · 3 comments
Open

.d.ts文件版本问题 @types\reflux #525

chenshuai2144 opened this issue Apr 11, 2017 · 3 comments

Comments

@chenshuai2144
Copy link

这样写是错误的

class StatusStore extends Reflux.Store {
    page: string
    constructor() {
        super();
        this.listenables = pageAction;
        this.page = location.hash.replace('#', '')
    }

    onPush(page) {
        if (this.page === page) {
            return false;
        }
        LeftMeunAction.hide();
        this.page = page;
        hashHistory.push(page);
    }
}
@kriscarle
Copy link

The error appears to be related to TypeScript? I don't think the definitions at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/reflux have been updated yet for version 6 of reflux.

Also in version 6+ of Reflux you'll probably need to put your values inside the state object. This is how I would updated it:

class StatusStore extends Reflux.Store {

  constructor() {
    super();
    this.listenables = pageAction;
    this.state = {
      page: location.hash.replace('#', ''),
      hashHistory: []
    }
  }

  onPush(newPage) {
    if (this.state.page === page) {
      return false;
    }
    LeftMeunAction.hide();
    
    var prevPage = this.state.page;
/*
Note: you should also clone hashHistory (treat it as immutable) if you need to detect changes in React components,
for example state.hashHistory.length !== nextState.hashHistory.length in shouldComponentUpdate
JSON.parse(JSON.stringify()) is a hack to clone an object, but there are other ways to do that :)
*/
    var historyClone = JSON.parse(JSON.stringify(this.state.hashHistory));
    historyClone.push(prevPage);
    this.setState({
      page: newPage,
      hashHistory: historyClone
    });
  }
}

@cdscawd
Copy link

cdscawd commented Jul 18, 2017

国际化

@LiangZugeng
Copy link

The type definition for Reflux v6.4 has been updated on Jun 26, 2018, it now supports the new class usage of Reflux.

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