From 6a8749adb899761f47ff3ee393cb8ab4126a638e Mon Sep 17 00:00:00 2001 From: Matt Lyons Date: Mon, 25 Sep 2017 15:53:20 +1000 Subject: [PATCH] Added $priority function to AFUnwrappedDataSnapshot --- src/database/interfaces.ts | 1 + src/database/utils.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/database/interfaces.ts b/src/database/interfaces.ts index c0a58beb4..4d675f17c 100644 --- a/src/database/interfaces.ts +++ b/src/database/interfaces.ts @@ -12,6 +12,7 @@ export interface AFUnwrappedDataSnapshot { $key: string; $value?: string | number | boolean; $exists: () => boolean; + $priority: () => string | number; } export interface Query { diff --git a/src/database/utils.ts b/src/database/utils.ts index 03c998eed..963219db8 100644 --- a/src/database/utils.ts +++ b/src/database/utils.ts @@ -47,11 +47,11 @@ export interface CheckUrlRef { } /** - * Unwraps the data returned in the DataSnapshot. Exposes the DataSnapshot key and exists methods through the $key and $exists properties respectively. If the value is primitive, it is unwrapped using a $value property. The $ properies mean they cannot be saved in the Database as those characters are invalid. + * Unwraps the data returned in the DataSnapshot. Exposes the DataSnapshot key, exists method and getPriority method through the $key, $exists and $priority properties respectively. If the value is primitive, it is unwrapped using a $value property. The $ properies mean they cannot be saved in the Database as those characters are invalid. * @param {DataSnapshot} snapshot - The snapshot to unwrap * @return AFUnwrappedDataSnapshot * @example - * unwrapMapFn(snapshot) => { name: 'David', $key: 'david', $exists: Function } + * unwrapMapFn(snapshot) => { name: 'David', $key: 'david', $exists: Function, $priority: Function } */ export function unwrapMapFn (snapshot:firebase.database.DataSnapshot): AFUnwrappedDataSnapshot { var unwrapped = !isNil(snapshot.val()) ? snapshot.val() : { $value: null }; @@ -70,6 +70,12 @@ export function unwrapMapFn (snapshot:firebase.database.DataSnapshot): AFUnwrapp }, enumerable: false }); + Object.defineProperty(unwrapped, '$priority', { + value: () => { + return snapshot.getPriority(); + }, + enumerable: false + }); return unwrapped; }