MCPcopy Create free account
hub / github.com/NativeScript/firebase / Reference

Class Reference

packages/firebase-database/index.android.ts:369–555  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369export class Reference extends Query implements IReference {
370 _native: com.google.firebase.database.DatabaseReference;
371 static fromNative(ref: com.google.firebase.database.DatabaseReference) {
372 if (ref instanceof com.google.firebase.database.DatabaseReference) {
373 const reference = new Reference();
374 reference._native = ref;
375 return reference;
376 }
377 return null;
378 }
379
380 get key(): string {
381 return this.native.getKey();
382 }
383 get parent(): Reference {
384 return Reference.fromNative(this.native?.getParent?.());
385 }
386 get ref(): Reference {
387 return Reference.fromNative(this.native?.getRef?.());
388 }
389 get root(): Reference {
390 return Reference.fromNative(this.native?.getRoot?.());
391 }
392
393 get native() {
394 return this._native;
395 }
396 get android() {
397 return this.native;
398 }
399
400 child(path: string): Reference {
401 return Reference.fromNative(this.native.child?.(path));
402 }
403
404 onDisconnect(): OnDisconnect {
405 return OnDisconnect.fromNative(this.native.onDisconnect());
406 }
407
408 push(value?: any, onComplete?: () => void): ThenableReference {
409 const id = this.native.push();
410 const thennablePushRef = Reference.fromNative(id);
411 const pushRef = Reference.fromNative(id);
412 let promise;
413 if (value) {
414 promise = thennablePushRef.set(value, onComplete).then(() => pushRef);
415 } else {
416 promise = Promise.resolve(pushRef);
417 }
418
419 // @ts-ignore
420 thennablePushRef.then = promise.then.bind(promise);
421 // @ts-ignore
422 thennablePushRef.catch = promise.then.bind(promise, undefined);
423
424 if (typeof onComplete === 'function') {
425 promise.catch(() => {});
426 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…