Skip to content

Instantly share code, notes, and snippets.

@mitrakmt
Forked from anantn/firebase_remove_pushed.js
Last active September 2, 2015 04:42
Show Gist options
  • Save mitrakmt/4c5244491ed00591bd37 to your computer and use it in GitHub Desktop.
Save mitrakmt/4c5244491ed00591bd37 to your computer and use it in GitHub Desktop.
Firebase: Removing an item you've pushed. This snippet shows how to remove an object that you just added using push().
function pushSomething(ref) {
// Let's push something. push() returns a reference that you can hold onto!
var justPushed = ref.push({test: "push"});
// We return a reference, but you can also return the name of the newly
// created object with .name().
return justPushed;
}
function removeItem(ref) {
// Now we can get back to that item we just pushed via .child().
ref.remove(function(error) {
alert(error ? "Uh oh!" : "Success!");
});
}
function go() {
var testRef = new Firebase("https://example.firebaseIO.com/");
var newRef = pushSomething(testRef);
// Later... should popup an alert that says "null" (No Error).
removeItem(newRef);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment