| 347 | } |
| 348 | |
| 349 | export class Reference extends Query implements IReference { |
| 350 | _native: any; |
| 351 | |
| 352 | static fromNative(ref: any) { |
| 353 | if (ref instanceof FIRDatabaseReference) { |
| 354 | const reference = new Reference(); |
| 355 | reference._native = ref; |
| 356 | return reference; |
| 357 | } |
| 358 | return null; |
| 359 | } |
| 360 | |
| 361 | get key(): string { |
| 362 | return this.native.key; |
| 363 | } |
| 364 | |
| 365 | get parent(): Reference { |
| 366 | return Reference.fromNative(this.native.parent); |
| 367 | } |
| 368 | |
| 369 | get ref(): Reference { |
| 370 | return Reference.fromNative(this.native.ref); |
| 371 | } |
| 372 | |
| 373 | get root(): Reference { |
| 374 | return Reference.fromNative(this.native.root); |
| 375 | } |
| 376 | |
| 377 | get native() { |
| 378 | return this._native as any; |
| 379 | } |
| 380 | |
| 381 | get ios() { |
| 382 | return this.native; |
| 383 | } |
| 384 | |
| 385 | child(path: string): Reference { |
| 386 | return Reference.fromNative(this.native.child?.(path)); |
| 387 | } |
| 388 | |
| 389 | onDisconnect(): OnDisconnect { |
| 390 | return OnDisconnect.fromNative(this.native); |
| 391 | } |
| 392 | |
| 393 | push(value?: any, onComplete?: () => void): ThenableReference { |
| 394 | const id = this.native.childByAutoId(); |
| 395 | const thennablePushRef = Reference.fromNative(id); |
| 396 | const pushRef = Reference.fromNative(id); |
| 397 | let promise; |
| 398 | if (value) { |
| 399 | promise = thennablePushRef.set(serialize(value), onComplete).then(() => pushRef); |
| 400 | } else { |
| 401 | promise = Promise.resolve(pushRef); |
| 402 | } |
| 403 | |
| 404 | // @ts-ignore |
| 405 | thennablePushRef.then = promise.then.bind(promise); |
| 406 | // @ts-ignore |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…