Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
fix(database): add primitives to object
Browse files Browse the repository at this point in the history
  • Loading branch information
adriancarriger committed May 24, 2017
1 parent 8f4ba84 commit 1588110
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ export function isNil(obj: any): boolean {
* Adds the properies of `$key`, `$value`, `$exists` as required by AngularFire2
*/
export function unwrap(key: string, value: any, exists, priority = null) {
let unwrapped = isNil(value) ? { } : value;
let primitive = (/string|number|boolean/).test(typeof value);
let unwrapped = isNil(value) || primitive ? { } : value;

// Change Nil values to null
if (isNil(value)) {
Object.defineProperty(unwrapped, '$value', {
enumerable: false,
Expand All @@ -391,9 +394,8 @@ export function unwrap(key: string, value: any, exists, priority = null) {
}

let initialValues = { key, value, exists, priority };
let primitive = (/string|number|boolean/).test(typeof value);

return ['exists', 'key', 'priority'].reduce((p, c) => {
return ['value', 'exists', 'key', 'priority'].reduce((p, c) => {
if ((c === 'value' && !primitive ) || !initialValues[c]) { return p; }
Object.defineProperty(p, `$${c}`, {
enumerable: false,
Expand Down

0 comments on commit 1588110

Please sign in to comment.