Skip to content

Commit ca32430

Browse files
committed
fix bug where app-localstorage-document instances update instances with other keys
1 parent 90bc883 commit ca32430

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

app-localstorage/app-localstorage-document.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,13 @@
204204
},
205205

206206
__onAppLocalStorageChanged: function(event) {
207-
if (event.detail === this) {
207+
var target = event.detail;
208+
if (target === this || this.key !== target.key) {
208209
return;
209210
}
210211

211212
this.syncToMemory(function() {
212-
this.set('data', event.detail.data);
213+
this.set('data', target.data);
213214
});
214215
},
215216

test/app-localstorage/app-localstorage-document.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
</app-localstorage-document>
3636
<app-localstorage-document key="app-localstorage-test" data="{}">
3737
</app-localstorage-document>
38+
<app-localstorage-document key="app-localstorage-other" data="{}">
39+
</app-localstorage-document>
3840
</template>
3941
</test-fixture>
4042

@@ -50,7 +52,7 @@
5052

5153
return Promise.resolve(Polymer.Base.get(parts.join('.'), value));
5254
}
53-
});
55+
});
5456
})
5557
</script>
5658
</body>

test/app-storage-compatibility-suite.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,35 @@
221221
suite('syncing storage scenarios', function() {
222222
var storageOne;
223223
var storageTwo;
224+
var storageOther;
224225

225226
setup(function() {
226227
var syncingStorage = fixture('SyncingStorage');
227228

228229
storageOne = syncingStorage[0];
229230
storageTwo = syncingStorage[1];
231+
storageOther = syncingStorage[2];
230232

231233
return Promise.all([
232234
storageOne.transactionsComplete,
233-
storageTwo.transactionsComplete
235+
storageTwo.transactionsComplete,
236+
storageOther.transactionsComplete,
234237
]);
235238
});
236239

237240
teardown(function() {
238241
context.unsetValue(storageOne);
239-
return context.awaitUpdate(storageTwo).then(function() {
240-
expect(storageTwo.data).to.be.eql(storageOne.data);
241-
});
242+
context.unsetValue(storageOther);
243+
return Promise.all([
244+
context.awaitUpdate(storageTwo).then(function() {
245+
expect(storageTwo.data).to.be.eql(storageOne.data);
246+
}),
247+
context.awaitUpdate(storageOther),
248+
]);
242249
});
243250

244251
test('syncs primitives across elements', function() {
252+
storageOther.set('data.other', 'other');
245253
storageOne.set('data.numberProperty', 1);
246254

247255
return Promise.all([
@@ -252,6 +260,11 @@
252260
expect(value).to.be.equal(1);
253261
expect(storageOne.get('data.numberProperty')).to.be.equal(value);
254262
expect(storageTwo.get('data.numberProperty')).to.be.equal(value);
263+
264+
// other key
265+
expect(storageOne.get('data.other')).to.not.be.ok;
266+
expect(storageOther.get('data.numberProperty')).to.not.be.equal(value);
267+
expect(storageOther.get('data.other')).to.be.equal('other');
255268
});
256269
});
257270

0 commit comments

Comments
 (0)