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

Return thenables from Firebase directly #2

Merged
merged 3 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "firebase-unchained",
"version": "1.5.0",
"description": "Promise version of Firebase API without chaining",
"description": "Firebase API without chaining",
"main": "lib/index.js",
"repository": {
"type": "git",
Expand All @@ -17,6 +17,9 @@
},
"author": "Seggy Umboh <sumboh@eta.ai>",
"license": "ISC",
"peerDependencies": {
"firebase": ">= 2.4.0 < 3"
},
"devDependencies": {
"babel-cli": "^6.3.17",
"babel-eslint": "^4.1.6",
Expand Down
29 changes: 6 additions & 23 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export function pauthWithCustomToken (db) {
export function pget (db) {
return (path) => {
const ref = path.once ? path : db.child(path)
return new Promise((resolve, reject) => {
ref.once('value', resolve, reject)
})
return ref.once('value')
}
}

Expand Down Expand Up @@ -58,32 +56,21 @@ export function parray (db) {
export function ppush (db) {
return function ppush (path, value) {
const ref = path.push ? path : db.child(path)
if (arguments.length < 2) {
return Promise.resolve(ref.push())
}
return new Promise((resolve, reject) => {
ref.push(value, (err) => err ? reject(err) : resolve())
})
return ref.push(value)
}
}

export function pset (db) {
return (path, value) => {
const ref = path.set ? path : db.child(path)
return new Promise((resolve, reject) => {
ref.set(value, (err) => err ? reject(err) : resolve())
})
return ref.set(value)
}
}

export function psetWithPriority (db) {
return function (path, value, priority) {
const ref = path.setWithPriority ? path : db.child(path)
return new Promise(function (resolve, reject) {
ref.setWithPriority(value, priority, function (err) {
return err ? reject(err) : resolve()
})
})
return ref.setWithPriority(value, priority)
}
}

Expand All @@ -97,18 +84,14 @@ export function psetPriority (db) {
export function pupdate (db) {
return (path, value) => {
const ref = path.update ? path : db.child(path)
return new Promise((resolve, reject) => {
ref.update(value, (err) => err ? reject(err) : resolve())
})
return ref.update(value)
}
}

export function premove (db) {
return (path) => {
const ref = path.remove ? path : db.child(path)
return new Promise((resolve, reject) => {
ref.remove((err) => err ? reject(err) : resolve())
})
return ref.remove()
}
}

Expand Down