question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any issues with using mapStoreToState to replicate Reflux.connect named state properties?

See original GitHub issue

Specifically, we’re working with a codebase that still uses Reflux.connect in mixins to connect to stores. Reflux.connect had the requirement to provide a property to map the store to.

We’ve upgraded to the latest Reflux version and the old behavior is still supported. However, now that we’re using ES6 classes and can’t use mixins, all of the properties from the stores are just copied verbatim to the component state and doesn’t seem to provide an ability to map them to a specific property like before. This was causing some problems.

Yesterday I tried using this.mapStoreToState in the constructor in the following manner to replicate the old behavior and it seems to be working on the surface. e.g.

this.mapStoreToState(userStore, (store) => this.state.users = store);

This isn’t how mapStoreToState seems to be meant for use according to the documentation, but it is working.

Are there any problems with this technique that I’m not aware of?

EDIT UPDATE

I read the docs over again and I feel like the following might be the actual right way to do what I’m intending. Feedback is appreaciated.

this.mapStoreToState(userStore, (store) => {users: store});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
geuiscommented, Apr 26, 2017

@aziz So we ended up writing a helper function:

connect = (instance, store, property) => {
  instance.mapStoreToState(store, () => ({
    [property]: store.getInitialState()
  }));
}

And its used like this in the class constructor:

class OurComponent extends Reflux.component {
  constructor (props) {
    super(props);

    connect(this, ourStore, 'ourstoreProp');
  }
}
1reaction
BryanGrezeszakcommented, Feb 16, 2017

I don’t really know what’s in your store, or where you’re trying to get that in your component. So I can’t really give you a verbatim solution. I can only explain how mapStoreToState works for you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect: Extracting Data with mapStateToProps
The first argument to a mapStateToProps function is the entire Redux store state (the same value returned by a call to store.getState() )....
Read more >
api documentation for reflux (v6.4.1) - GitHub Pages
Using Reflux.connect If all you want to do is update the state of your ... it will only * utilized state property names...
Read more >
Gastroesophageal Reflux Disease (GERD) - PMC - NCBI - NIH
Successful treatment of GERD symptoms has been associated with significant improvement in quality of life, including decreased physical pain, increased vitality ...
Read more >
Gastroesophageal reflux disease (GERD) - Symptoms and ...
GERD, in which stomach acid moves into the esophagus, causes discomfort and may lead to precancerous changes in the lining of the esophagus....
Read more >
Gastroesophageal Reflux Disease
It results from reflux (backward flow) of the stomach contents into the esophagus and causes trouble symptoms at least two times a week....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found