This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Scott J. Miles
committed
Feb 15, 2014
1 parent
7fd6f17
commit e563c0c
Showing
2 changed files
with
75 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |