Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott J. Miles committed Feb 15, 2014
1 parent 7fd6f17 commit e563c0c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 61 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"authors": [
"Scott J. Miles <[email protected]>"
],
"description": "Element interface to FireBase Web API",
"description": "Element wrapper for the FireBase Web API",
"keywords": [
"Polymer",
"FireBase"
Expand Down
134 changes: 74 additions & 60 deletions fire-base.html
Original file line number Diff line number Diff line change
@@ -1,61 +1,75 @@
<link rel="import" href="../polymer/polymer.html">

<script src='../firebase/firebase.js'></script>

<polymer-element name="fire-base" attributes="location list">

<script>

Polymer('fire-base', {
ready: function() {
},

locationChanged: function() {
var dataRef = new Firebase(this.location);

var job, list = [];

// TODO(sjmiles): this is a really bad way of doing this
dataRef.on('child_added', function(snapshot) {
list.push(snapshot.val());
job = this.job(job, function() {
this.fire('items-added');
});
}, this);

this.list = list;
this.dataRef = dataRef;
},

push: function(item) {
this.dataRef.push(item);
},

remove: function(item) {
// TODO(sjmiles): this is a really bad way of doing this
this.dataRef.once('value', function(snap) {
snap.forEach(function(snap) {
var rec = snap.val();
for (var n in rec) {
if (item[n] !== rec[n]) {
return false;
}
}
snap.ref().remove();
this._removeFromList(item);
return true;
}.bind(this));
}, this);
},

_removeFromList: function(item) {
var index = this.list.indexOf(item);
if (index >= 0) {
this.list.splice(index, 1);
}
}
});

</script>

<link rel="import" href="../polymer/polymer.html">

<!-- depends on `firebase` components -->
<script src='../firebase/firebase.js'></script>

<!--
/**
*
* Element wrapper for the FireBase Web API.
*
* @class fire-base
* @blurb Element wrapper for the FireBase Web API
* @status alpha
* @snap snap.png
*
*/
-->

<polymer-element name="fire-base" attributes="location list">

<script>

Polymer('fire-base', {
ready: function() {
},

locationChanged: function() {
var dataRef = new Firebase(this.location);

var job, list = [];

// TODO(sjmiles): this is a really bad way of doing this
dataRef.on('child_added', function(snapshot) {
list.push(snapshot.val());
job = this.job(job, function() {
this.fire('items-added');
});
}, this);

this.list = list;
this.dataRef = dataRef;
},

push: function(item) {
this.dataRef.push(item);
},

remove: function(item) {
// TODO(sjmiles): this is a really bad way of doing this
this.dataRef.once('value', function(snap) {
snap.forEach(function(snap) {
var rec = snap.val();
for (var n in rec) {
if (item[n] !== rec[n]) {
return false;
}
}
snap.ref().remove();
this._removeFromList(item);
return true;
}.bind(this));
}, this);
},

_removeFromList: function(item) {
var index = this.list.indexOf(item);
if (index >= 0) {
this.list.splice(index, 1);
}
}
});

</script>

</polymer-element>

0 comments on commit e563c0c

Please sign in to comment.