diff --git a/packages/reactive-dict/package.js b/packages/reactive-dict/package.js index e60d725570..2a5cbc33ac 100644 --- a/packages/reactive-dict/package.js +++ b/packages/reactive-dict/package.js @@ -16,5 +16,6 @@ Package.onTest(function (api) { api.use('tinytest'); api.use('reactive-dict'); api.use('tracker'); + api.use('underscore'); api.addFiles('reactive-dict-tests.js'); }); diff --git a/packages/reactive-dict/reactive-dict-tests.js b/packages/reactive-dict/reactive-dict-tests.js index 1789039a0d..d817a159a3 100644 --- a/packages/reactive-dict/reactive-dict-tests.js +++ b/packages/reactive-dict/reactive-dict-tests.js @@ -1,11 +1,19 @@ +Tinytest.add('ReactiveDict - set to undefined', function (test) { + var dict = new ReactiveDict; + dict.set('foo', undefined); + test.equal(_.keys(dict.all()), ['foo']); + dict.setDefault('foo', 'bar'); + test.equal(dict.get('foo'), undefined); +}); + Tinytest.add('ReactiveDict - all() works', function (test) { var all = {}, dict = new ReactiveDict; Tracker.autorun(function() { all = dict.all(); }); - + test.equal(all, {}); - + dict.set('foo', 'bar'); Tracker.flush(); test.equal(all, {foo: 'bar'}); @@ -15,7 +23,7 @@ Tinytest.add('ReactiveDict - all() works', function (test) { Tinytest.add('ReactiveDict - clear() works', function (test) { var dict = new ReactiveDict; dict.set('foo', 'bar'); - + var val, equals, equalsUndefined, all; Tracker.autorun(function() { val = dict.get('foo'); @@ -29,16 +37,16 @@ Tinytest.add('ReactiveDict - clear() works', function (test) { Tracker.autorun(function() { all = dict.all(); }); - + test.equal(val, 'bar'); test.equal(equals, true); test.equal(equalsUndefined, false); test.equal(all, {foo: 'bar'}); - + dict.clear(); Tracker.flush(); test.isUndefined(val); test.equal(equals, false); test.equal(equalsUndefined, true); test.equal(all, {}); -}); \ No newline at end of file +}); diff --git a/packages/reactive-dict/reactive-dict.js b/packages/reactive-dict/reactive-dict.js index 1a194ea9d1..0ec49cdd87 100644 --- a/packages/reactive-dict/reactive-dict.js +++ b/packages/reactive-dict/reactive-dict.js @@ -50,6 +50,7 @@ _.extend(ReactiveDict.prototype, { var self = this; if ((typeof keyOrObject === 'object') && (value === undefined)) { + // Called as `dict.set({...})` self._setObject(keyOrObject); return; } @@ -60,9 +61,11 @@ _.extend(ReactiveDict.prototype, { value = stringify(value); var oldSerializedValue = 'undefined'; - if (_.has(self.keys, key)) oldSerializedValue = self.keys[key]; - if (value === oldSerializedValue) - return; + if (_.has(self.keys, key)) { + oldSerializedValue = self.keys[key]; + if (value === oldSerializedValue) + return; + } self.keys[key] = value; self.allDeps.changed();