mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-28 06:55:31 +08:00
[js][android] Support multiple listeners on a single ref
This commit is contained in:
@@ -9,47 +9,41 @@ import Reference from './reference.js';
|
||||
* @class Query
|
||||
*/
|
||||
export default class Query extends ReferenceBase {
|
||||
static ref: Reference;
|
||||
modifiers: Array<DatabaseModifier>;
|
||||
|
||||
static modifiers: Array<string>;
|
||||
|
||||
ref: Reference;
|
||||
|
||||
constructor(ref: Reference, path: string, existingModifiers?: Array<string>) {
|
||||
constructor(ref: Reference, path: string, existingModifiers?: Array<DatabaseModifier>) {
|
||||
super(ref.database, path);
|
||||
this.log.debug('creating Query ', path, existingModifiers);
|
||||
this.ref = ref;
|
||||
this.modifiers = existingModifiers ? [...existingModifiers] : [];
|
||||
}
|
||||
|
||||
setOrderBy(name: string, key?: string) {
|
||||
if (key) {
|
||||
this.modifiers.push(`${name}:${key}`);
|
||||
} else {
|
||||
this.modifiers.push(name);
|
||||
}
|
||||
orderBy(name: string, key?: string) {
|
||||
this.modifiers.push({
|
||||
type: 'orderBy',
|
||||
name,
|
||||
key,
|
||||
});
|
||||
}
|
||||
|
||||
setLimit(name: string, limit: number) {
|
||||
this.modifiers.push(`${name}:${limit}`);
|
||||
limit(name: string, limit: number) {
|
||||
this.modifiers.push({
|
||||
type: 'limit',
|
||||
name,
|
||||
limit,
|
||||
});
|
||||
}
|
||||
|
||||
setFilter(name: string, value: any, key?:string) {
|
||||
if (key) {
|
||||
this.modifiers.push(`${name}:${value}:${typeof value}:${key}`);
|
||||
} else {
|
||||
this.modifiers.push(`${name}:${value}:${typeof value}`);
|
||||
}
|
||||
filter(name: string, value: any, key?:string) {
|
||||
this.modifiers.push({
|
||||
type: 'filter',
|
||||
name,
|
||||
value,
|
||||
valueType: typeof value,
|
||||
key,
|
||||
});
|
||||
}
|
||||
|
||||
getModifiers(): Array<string> {
|
||||
getModifiers(): Array<DatabaseModifier> {
|
||||
return [...this.modifiers];
|
||||
}
|
||||
|
||||
getModifiersString(): string {
|
||||
if (!this.modifiers || !Array.isArray(this.modifiers)) {
|
||||
return '';
|
||||
}
|
||||
return this.modifiers.join('|');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user