Skip to content

Commit

Permalink
simplify AdaptiveStore code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow committed Aug 17, 2016
1 parent d05fecd commit 66e8164
Showing 1 changed file with 21 additions and 42 deletions.
63 changes: 21 additions & 42 deletions addon/session-stores/adaptive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ import Base from 'ember-simple-auth/session-stores/base';
import LocalStorage from 'ember-simple-auth/session-stores/local-storage';
import Cookie from 'ember-simple-auth/session-stores/cookie';

const {
computed
} = Ember;
const { computed } = Ember;

const LOCAL_STORAGE_TEST_KEY = '_ember_simple_auth_test_key';

const proxyToInternalStore = function(property) {
let internalProperty = `_${property}`;
return computed({
get() {
return this.get(internalProperty);
},
set(key, value) {
this.set(internalProperty, value);
let _store = this.get('_store');
if (_store) {
_store.set(property, value);
}
return value;
}
});
};

/**
Session store that persists data in the browser's `localStorage` (see
{{#crossLink "LocalStorageStore"}}{{/crossLink}}) if that is available or in
Expand Down Expand Up @@ -47,19 +62,7 @@ export default Base.extend({
@public
*/
_cookieDomain: null,
cookieDomain: computed({
get() {
return this.get('_cookieDomain');
},
set(key, value) {
this.set('_cookieDomain', value);
let _store = this.get('_store');
if (_store) {
_store.set('cookieDomain', value);
}
return value;
}
}),
cookieDomain: proxyToInternalStore('cookieDomain'),

/**
The name of the cookie to use if `localStorage` is not available.
Expand All @@ -70,19 +73,7 @@ export default Base.extend({
@public
*/
_cookieName: 'ember_simple_auth-session',
cookieName: computed('cookieName', {
get() {
return this.get('_cookieName');
},
set(key, value) {
this.set('_cookieName', value);
let _store = this.get('_store');
if (_store) {
_store.set('cookieName', value);
}
return value;
}
}),
cookieName: proxyToInternalStore('cookieName'),

/**
The expiration time for the cookie in seconds if `localStorage` is not
Expand All @@ -95,19 +86,7 @@ export default Base.extend({
@public
*/
_cookieExpirationTime: null,
cookieExpirationTime: computed({
get() {
return this.get('_cookieExpirationTime');
},
set(key, value) {
this.set('_cookieExpirationTime', value);
let _store = this.get('_store');
if (_store) {
_store.set('cookieExpirationTime', value);
}
return value;
}
}),
cookieExpirationTime: proxyToInternalStore('cookieExpirationTime'),

_isLocalStorageAvailable: computed(function() {
try {
Expand Down

0 comments on commit 66e8164

Please sign in to comment.