Skip to content

Commit

Permalink
Added fallback to localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogball committed Dec 19, 2017
1 parent 73bed16 commit c6a66a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion addon/helpers/storage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Ember from 'ember';
import DS from 'ember-data';
import StoragePromiseMixin from '../mixins/promise';
import { preSerialize } from './utils';

const {
assert,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion addon/serializers/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c6a66a8

Please sign in to comment.