-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added
overrideLocalStorage
; now it is possible to wait for storage …
…to be hydrated before rendering the children
- Loading branch information
Showing
9 changed files
with
162 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { initRefreshService } from './refresh' | ||
import { overrideLocalStorage } from './overrideLocalStorage' | ||
|
||
export { initRefreshService } | ||
export { initRefreshService, overrideLocalStorage } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
/** | ||
* Is it running in a browser? | ||
* @returns | ||
*/ | ||
const isBrowser = () => typeof window !== 'undefined' | ||
export default isBrowser |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sessionStorage from '../session-storage/sessionStorage' | ||
import isBrowser from './isBrowser' | ||
|
||
/** | ||
* Overrides the window.localStorage with the bridge's sessionStorage (Widget's Storage) | ||
*/ | ||
export const overrideLocalStorage = () => { | ||
class BridgeLocalStorage { | ||
setItem(key: string, value: any) { | ||
sessionStorage.setItem(key, value) | ||
} | ||
|
||
getItem(key: string) { | ||
return sessionStorage.getItem(key) | ||
} | ||
|
||
removeItem(key: string) { | ||
sessionStorage.removeItem(key) | ||
} | ||
} | ||
|
||
const myLocalStorage = new BridgeLocalStorage() | ||
|
||
// Assign the newly created instance to localStorage | ||
if (isBrowser()) { | ||
Object.defineProperty(window, 'localStorage', { | ||
value: myLocalStorage, | ||
writable: true, | ||
}) | ||
} | ||
} |
This file contains 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