[js][database] _handleCancelEvent completed - now correctly handles cancellation events from .on()
This commit is contained in:
parent
98ebd8bf66
commit
dedfa48aa0
|
@ -8,6 +8,7 @@ import Reference from './reference';
|
|||
import Snapshot from './snapshot';
|
||||
import TransactionHandler from './transaction';
|
||||
import ModuleBase from './../../utils/ModuleBase';
|
||||
import { nativeToJSError } from './../../utils';
|
||||
|
||||
/**
|
||||
* @class Database
|
||||
|
@ -36,8 +37,15 @@ export default class Database extends ModuleBase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Routes native database 'on' events to their js equivalent counterpart.
|
||||
* If there is no longer any listeners remaining for this event we internally
|
||||
* call the native unsub method to prevent further events coming through.
|
||||
*
|
||||
* @param event
|
||||
* @private
|
||||
*/
|
||||
_handleOnEvent(event) {
|
||||
console.log('>>>ON-event>>>', event);
|
||||
const { queryKey, body, refId } = event;
|
||||
const { snapshot, previousChildName } = body;
|
||||
|
||||
|
@ -64,8 +72,21 @@ export default class Database extends ModuleBase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Routes native database query listener cancellation events to their js counterparts.
|
||||
*
|
||||
* @param event
|
||||
* @private
|
||||
*/
|
||||
_handleCancelEvent(event) {
|
||||
console.log('>>>CANCEL-event>>>', event);
|
||||
const { queryKey, code, message, path, refId, appName } = event;
|
||||
const remainingListeners = this.listeners(`${queryKey}:cancelled`);
|
||||
|
||||
if (remainingListeners && remainingListeners.length) {
|
||||
const error = nativeToJSError(code, message, { path, queryKey, refId, appName });
|
||||
this.emit(`${queryKey}:cancelled`, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,14 +119,6 @@ export default class Database extends ModuleBase {
|
|||
ref(path: string) {
|
||||
return new Reference(this, path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* INTERNALS
|
||||
*/
|
||||
|
||||
// todo handleDbEvent
|
||||
// todo handleDbError
|
||||
}
|
||||
|
||||
export const statics = {
|
||||
|
|
Loading…
Reference in New Issue