firebase realtime database once vs on?

前端 未结 1 474
南笙
南笙 2021-01-26 03:44

Im using firebase realtime database on node js like database for API.

What\'s the different between once() and on()?

My code with

相关标签:
1条回答
  • 2021-01-26 04:20

    From the docs:

    once:

    once(eventType: EventType, successCallback?: function, failureCallbackOrContext?: function | Object | null, context?: Object | null): Promise<DataSnapshot>

    Listens for exactly one event of the specified event type, and then stops listening.

    This is equivalent to calling on(), and then calling off() inside the callback function. See on() for details on the event types.

    on:

    on(eventType: EventType, callback: function, cancelCallbackOrContext?: Object | null, context?: Object | null): function

    Listens for data changes at a particular location.

    This is the primary way to read data from a Database. Your callback will be triggered for the initial data and again whenever the data changes. Use off( ) to stop receiving updates.

    off() is used to detach a callback previously attached with on()

    You can check the reference:

    https://firebase.google.com/docs/reference/js/firebase.database.Reference.html

    0 讨论(0)
提交回复
热议问题