Guest User

Untitled

a guest
Aug 25th, 2019
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export interface Storage {
  2. getItem: (key: string) => string | null
  3. setItem: (key: string, value: string) => void
  4. removeItem: (key: string) => void
  5. }
  6.  
  7. const fallback: Storage = {
  8. getItem: (key: string): string | null => {
  9. console.log(`This is fallback key "${key}" cannot be readed`)
  10.  
  11. return null
  12. },
  13. setItem: (key: string, value: string): void => {
  14. console.log(`This is fallback key "${key}" with value "${value}" cannot be writen`)
  15. },
  16. removeItem: (key: string): void => {
  17. console.log(`This is fallback key "${key}" cannot be removed`)
  18. },
  19. }
  20.  
  21. export const localStorage = typeof window !== 'undefined' ? window.localStorage : fallback
RAW Paste Data