Created
August 3, 2018 16:13
-
-
Save whisher/bc00aca961aa2ea9a005c842eececbbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const customStorage: Storage = { | |
| length: 0, | |
| clear: function(): void { | |
| if (window && window.localStorage) { | |
| window.localStorage.clear(); | |
| this.length = window.localStorage.length; | |
| } | |
| }, | |
| getItem: function(key: string): string | null { | |
| try { | |
| return window.localStorage.getItem(key); | |
| } catch (err) { | |
| return null; | |
| } | |
| }, | |
| key: function(index: number): string | null { | |
| try { | |
| return window.localStorage.key(index); | |
| } catch (err) { | |
| return null; | |
| } | |
| }, | |
| removeItem: function(key: string): void { | |
| try { | |
| window.localStorage.removeItem(key); | |
| this.length = window.localStorage.length; | |
| } catch (err) { | |
| return; | |
| } | |
| }, | |
| setItem: function(key: string, data: string): void { | |
| try { | |
| window.localStorage.setItem(key, data); | |
| this.length = window.localStorage.length; | |
| } catch (err) { | |
| return; | |
| } | |
| } | |
| }; | |
| export function localStorageSyncReducer(reducer: ActionReducer<any>): ActionReducer<any> { | |
| return localStorageSync({ | |
| keys: [{auth:['status','account']}], | |
| rehydrate: true, | |
| storage: customStorage | |
| })(reducer); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment