Skip to content

Commit e37a66c

Browse files
committed
Merge pull request #60 from GoogleWebComponents/guard-local-changes
Guard local changes
2 parents 837d0ad + 285937e commit e37a66c

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

firebase-collection.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ <h4>[[dinosaur.__firebaseKey__]]</h4>
326326
this.remove(removed);
327327
}, this);
328328

329-
this.data.splice(splice.index, splice.addedCount);
330-
331329
added.forEach(function(added) {
332330
this.add(added);
333331
}, this);

firebase-query-behavior.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
},
7575

7676
_applyRemoteDataChange: function(applyChange) {
77+
if (this._applyingLocalDataChanges) {
78+
return;
79+
}
7780
this._receivingRemoteChanges = true;
7881
applyChange.call(this);
7982
this._receivingRemoteChanges = false;
@@ -84,7 +87,9 @@
8487
return;
8588
}
8689

90+
this._applyingLocalDataChanges = true;
8791
this._applyLocalDataChanges(changes);
92+
this._applyingLocalDataChanges = false;
8893
},
8994

9095
_queryChanged: function(query, oldQuery) {

test/firebase-collection.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,51 @@
6464
</template>
6565
</test-fixture>
6666

67+
<test-fixture id="BoundCollection">
68+
<template>
69+
<section>
70+
<!-- TODO(cdata): Add support for elements like `dom-bind` at the root
71+
of the template to `test-fixture`, so that we can remove this
72+
wrapping `section`. -->
73+
<template is="dom-bind">
74+
<template is="dom-repeat" items="{{data}}">
75+
<div>[[item.value]]</div>
76+
</template>
77+
<firebase-collection
78+
location="https://fb-element-demo.firebaseio.com/test/empty"
79+
data="{{data}}"
80+
log>
81+
</firebase-collection>
82+
</template>
83+
</section>
84+
</template>
85+
</test-fixture>
86+
6787
<script>
6888
suite('<firebase-collection>', function() {
6989
var firebase;
7090

91+
suite('collection manipulation', function() {
92+
var domBind;
93+
var dom;
94+
95+
setup(function() {
96+
dom = fixture('BoundCollection');
97+
domBind = dom.querySelector('[is=dom-bind]');
98+
firebase = dom.querySelector('firebase-collection');
99+
});
100+
101+
test('added values reflect 1-to-1 in the DOM', function(done) {
102+
waitForEvent(firebase, 'firebase-value').then(function() {
103+
waitForEvent(firebase, 'firebase-child-added').then(function() {
104+
expect(dom.querySelectorAll('div').length).to.be.equal(firebase.data.length);
105+
done();
106+
});
107+
domBind.unshift('data', { value: 'blah' });
108+
});
109+
});
110+
});
111+
71112
suite('basic usage', function() {
72113
setup(function() {
73114
firebase = fixture('TrivialCollection');

0 commit comments

Comments
 (0)