Files
Iris/src/js/services/localstorage/middleware.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

const localstorageMiddleware = (function(){
/**
* The actual middleware inteceptor
**/
return store => next => action => {
// proceed as normal first
// this way, any reducers and middleware do their thing BEFORE we store our new state
next(action);
switch( action.type ){
case 'MOPIDY_SET_CONFIG':
var mopidy = {
host: action.config.host,
port: action.config.port
};
localStorage.setItem('mopidy', JSON.stringify(mopidy));
break;
case 'SPOTIFY_SET_CONFIG':
var spotify = {
country: action.config.country,
locale: action.config.locale
};
localStorage.setItem('spotify', JSON.stringify(spotify));
break;
case 'SPOTIFY_COMPLETE_AUTHORIZATION':
var spotify = {
authorized: true,
access_token: action.data.access_token,
refresh_token: action.data.refresh_token
};
localStorage.setItem('spotify', JSON.stringify(spotify));
break;
}
}
})();
export default localstorageMiddleware