diff --git a/addon/helpers/storage.js b/addon/helpers/storage.js index 67531b20..c49d0824 100644 --- a/addon/helpers/storage.js +++ b/addon/helpers/storage.js @@ -1,6 +1,7 @@ import Ember from 'ember'; import DS from 'ember-data'; import StoragePromiseMixin from '../mixins/promise'; +import { preSerialize } from './utils'; const { assert, @@ -61,6 +62,11 @@ function tryStorage(name) { } function getStorage(name) { + // Attempt to fall back to localStorage if the provided + // type is not supported, ignoring custom drivers + if (!localforage.supports(drivers[name]) && !customDrivers[name]) { + name = 'local'; + } if (storage[name]) { return storage[name]; } else { @@ -169,7 +175,7 @@ function createStorage(context, key, modelKey, options, FactoryType, preferredKe set(storageObj, '_initialContentString', JSON.stringify(storageObj._initialContent)); set(storageObj, 'content', content); // `content` might have non-serializable items - return storage.setItem(storageKey, JSON.parse(JSON.stringify(content))); + return storage.setItem(storageKey, preSerialize(content)); }).then(() => { return storageObj; }); diff --git a/addon/serializers/serializer.js b/addon/serializers/serializer.js index c5488dfe..a49405bd 100644 --- a/addon/serializers/serializer.js +++ b/addon/serializers/serializer.js @@ -9,7 +9,7 @@ export default JSONAPISerializer.extend({ _shouldSerializeHasMany: function() { return true; }, shouldSerializeHasMany: function() { return true; }, // Ensure that returned data is null if undefined - normalizeResponse(store, modelClass, payload, id, requestType) { + normalizeResponse() { const result = this._super(...arguments); if (result.data === undefined) { result.data = null;