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

Child_added supported in sync? -> Adding to Documentation #84

Closed
ReactNativeBlog opened this issue Dec 27, 2017 · 4 comments
Closed

Child_added supported in sync? -> Adding to Documentation #84

ReactNativeBlog opened this issue Dec 27, 2017 · 4 comments

Comments

@ReactNativeBlog
Copy link

First of all: Great Work!

I'm currently wondering which data is transferred on a sync in case a child was added/remove/... in the realtime database?
Is the whole data/ref transferred or only the delta?

Many thanks for clarification.

@n6g7
Copy link
Owner

n6g7 commented Dec 27, 2017

Thanks!

Yes, the database.sync method currently uses the value event so it will send the whole data in the ref.

If you want to only receive new or deleted children you can choose the event you want to use (child_added, child_removed , child_changed or child_moved , see the Reference.on docs for more details), in the database.channel method:

function * syncAddedChildren () {
  const channel = yield call(rsf.database.channel, 'items', 'child_added') // 👈 add a third argument here 😉

  while (true) {
    const data = yield take(channel)
    yield put(actionCreator(data))
  } catch (err) {
    yield put(failureActionCreator(err))
  } finally {
    if (yield cancelled()) channel.close()
  }
}

It never occurred to me that there was a strong use case for this but if that's the case for you we can definitely add an API to make this a lot simpler. :)
I'm thinking of something like:

function * syncAddedChildren () {
  yield fork(
    rsf.database.sync,
    'items', 
    { successActionCreator: ..., failureActionCreator: ... },
    'child_added' // 👈 we could add a third argument here 🙂
  )
}

Please let me know if that would be interesting to you! :)

@ReactNativeBlog
Copy link
Author

ReactNativeBlog commented Dec 30, 2017

Great !!!
Possible scenarios for such an API are

  • chat system
  • events with bad wifi and >10.000 app users

Thanks for the clearance.
And yes, this is interesting ;-D

Kind Regards

BTW: I'm using this in react native - firebase sync & saga is super easy due to your library!

@n6g7
Copy link
Owner

n6g7 commented Dec 31, 2017

Thanks for the feedback, this is much appreciated. :D

Possible scenarios for such an API are

  • chat system
  • events with bad wifi and >10.000 app users

That sounds reasonable, I'll keep this issue open and notify you when this is ready. :)

@n6g7 n6g7 mentioned this issue Jan 1, 2018
@n6g7 n6g7 closed this as completed in #87 Jan 1, 2018
@n6g7
Copy link
Owner

n6g7 commented Jan 1, 2018

@ReactNativeBlog I've just released v0.8.0 with this change!
Run yarn upgrade redux-saga-firebase@latest (there's no breaking changes) and you should be able to use the new database.sync event argument in your code. 🎉

Let me know how it works for you! :D

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

No branches or pull requests

2 participants