Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added $priority function to AFUnwrappedDataSnapshot #1165

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/database/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface AFUnwrappedDataSnapshot {
$key: string;
$value?: string | number | boolean;
$exists: () => boolean;
$priority: () => string | number;
}

export interface Query {
Expand Down
10 changes: 8 additions & 2 deletions src/database/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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;
}

Expand Down