Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement