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

Using Queries w/ syncState wipes out everything not queried #252

Open
taykcrane opened this issue Mar 23, 2018 · 4 comments
Open

Using Queries w/ syncState wipes out everything not queried #252

taykcrane opened this issue Mar 23, 2018 · 4 comments

Comments

@taykcrane
Copy link

taykcrane commented Mar 23, 2018

Hey Tyler,

Ran into an issue with re-base I can't seem to overcome. I have an array in state called "concerns", and when I sync it with firebase using the below code, and then make any Write operation, it wipes out everything not synced, i.e. anything that wasn't in my query.

componentWillMount = () => {
    base.syncState("concerns", {
      context: this,
      state: "concerns",
      asArray: true,
      queries: {
        orderByChild: "userId",
        equalTo: this.props.user.uid,
      },
    });
};

In your documentation under "Using Firebase Queries", your example uses syncState and limits by a query. I don't understand how this works if, after syncing, firebase deletes all the unsynced queries. Seems to make the feature entirely useless. I hope I'm missing an easy fix here, can you please help?

"re-base": "^3.2.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
@qwales1
Copy link
Collaborator

qwales1 commented Mar 23, 2018

@taykcrane Thanks for reporting this. I think that might be a bug in syncState because I believe in previous versions of the re-base that did work. I am not 100% sure but will check the tests to make sure that was covered at some point and figure out what happened. Sorry about that. Until I can sort that out, I would recommend using bindToState or listenTo for reading and then have separate methods for writes (using push, update, or remove as needed) over syncState when dealing with lists/collections.

@taykcrane
Copy link
Author

@qwales1 damn, I was hoping I missed something simple. I love the simplicity of syncState, so instead of separate methods for reading/writing, I may hold out and see if you indeed find a bug in syncState. Appreciate you looking into this so quickly. LMK if you need any more code from me.

@maxisix
Copy link

maxisix commented Apr 6, 2018

Did you find a way ? I have a similar problem, i have this architecture

  • tweet
    • 0
      • user
        • screen_name: 'maxisix'

this.ref = base.syncState(tweet, {
context: this,
state: "tweet",
queries: {
orderByChild: "user",
orderByChild: "screen_name",
equalTo: "maxisix"
}
});

@taykcrane
Copy link
Author

@maxisix I did not find a way. Any updates @qwales1?

I solved this problem by making users my top-level node, syncing the whole node, and abandoning queries entirely. Couldn't get it to work.

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

3 participants