Browse Source

Parse Json passed to key watchers

Rafał Pitoń 10 years ago
parent
commit
38c7ddbce9

+ 5 - 4
misago/emberapp/app/services/local-store.js

@@ -15,9 +15,10 @@ export default Ember.Service.extend({
   }.on('init'),
   }.on('init'),
 
 
   _handleStorageEvent: function(e) {
   _handleStorageEvent: function(e) {
+    var newValueJson = JSON.parse(e.newValue);
     Ember.$.each(this.get('_watchers'), function(i, watcher) {
     Ember.$.each(this.get('_watchers'), function(i, watcher) {
       if (watcher.keyName === e.key && e.oldValue !== e.newValue) {
       if (watcher.keyName === e.key && e.oldValue !== e.newValue) {
-        watcher.callback(e.newValue);
+        watcher.callback(newValueJson);
       }
       }
     });
     });
   },
   },
@@ -31,9 +32,9 @@ export default Ember.Service.extend({
   },
   },
 
 
   getItem: function(keyName) {
   getItem: function(keyName) {
-    var itemJson = this.get('_storage').getItem(this.prefixKey(keyName));
-    if (itemJson) {
-      return JSON.parse(itemJson);
+    var itemString = this.get('_storage').getItem(this.prefixKey(keyName));
+    if (itemString) {
+      return JSON.parse(itemString);
     } else {
     } else {
       return null;
       return null;
     }
     }

+ 6 - 2
misago/emberapp/tests/acceptance/local-store-test.js

@@ -39,9 +39,13 @@ test('registered watcher is fired', function(assert) {
     done();
     done();
   });
   });
 
 
-  service._handleStorageEvent({key: 'unwatchedKey'});
+  service._handleStorageEvent({
+    key: 'unwatchedKey',
+    newValue: JSON.stringify('nope')
+  });
+
   service._handleStorageEvent({
   service._handleStorageEvent({
     key: service.prefixKey(testKey),
     key: service.prefixKey(testKey),
-    newValue: testValue
+    newValue: JSON.stringify(testValue)
   });
   });
 });
 });