Skip to content

Commit

Permalink
Strict check on browser side code (#137)
Browse files Browse the repository at this point in the history
* Strict check on browser side code
  • Loading branch information
tom-quiltt authored Nov 2, 2023
1 parent 3820053 commit ab55ccb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/small-shoes-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@quiltt/core": patch
"@quiltt/react": patch
"@quiltt/react-test-nextjs": patch
---

Skip browser code when in expo app
6 changes: 3 additions & 3 deletions ECMAScript/core/src/Storage/Local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class LocalStorage<T> {
private observers: { [key: string]: Observer<T>[] } = {}

constructor() {
if (typeof window !== 'undefined') {
if (typeof window !== 'undefined' && !window?.expo) {
window.addEventListener('storage', this.handleStorageEvent.bind(this))
}
}
Expand All @@ -29,7 +29,7 @@ export class LocalStorage<T> {
isDisabled = (): boolean => !this.isEnabled()

get = (key: string): Maybe<T> | undefined => {
if (typeof window === 'undefined') return undefined
if (typeof window === 'undefined' || !!window.expo) return undefined

try {
const state = window.localStorage.getItem(`quiltt.${key}`)
Expand All @@ -41,7 +41,7 @@ export class LocalStorage<T> {
}

set = (key: string, state: Maybe<T> | undefined): void => {
if (typeof window === 'undefined') return
if (typeof window === 'undefined' || !!window.expo) return

try {
if (state) {
Expand Down
5 changes: 5 additions & 0 deletions ECMAScript/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ export type Nullable<T> = { [K in keyof T]: T[K] | null }
export type Mutable<Type> = { -readonly [Key in keyof Type]: Type[Key] }
export type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T
export type DeepReadonly<T> = T extends object ? { [P in keyof T]: DeepReadonly<T[P]> } : T
declare global {
interface Window {
expo: any
}
}

0 comments on commit ab55ccb

Please sign in to comment.