Skip to content

Commit

Permalink
Add array converting
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhduong committed Apr 28, 2018
1 parent 2395c9b commit 7fedc79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/drivers/linq-fns-firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ export class FireBaseQueryale {
new Promise<T[]>((resolve, reject) => {
if (!predicate)
ref.on(action, (snapshot) => {
resolve(snapshot.val());
resolve(this.convert(snapshot.val()));
});
else {
const query = predicate(ref);
query.on(action, (snapshot) => {
resolve(snapshot.val());
resolve(this.convert(snapshot.val()));
});
}
}));
}

private convert<T>(objData: Object): T[] {
return Object.keys(objData).map(prop => {
objData[prop]['__id'] = prop;
return objData[prop];
});
}

private getRefObject(name: string): database.Reference {
if (!name) throw new Error(`name cannot empty`);

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"target": "es5",
"importHelpers": true,
"sourceMap": true,
"outDir": "./dist",
Expand All @@ -23,7 +23,7 @@
]
},
"baseUrl": "./",
// "declaration": true,
"declaration": true,
},
"exclude": [
"demo",
Expand Down

0 comments on commit 7fedc79

Please sign in to comment.