Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/deps version upgrade #156

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@nandorojo/swr-firestore",
"name": "@alexandersergan/swr-firestore",
"version": "0.16.0",
"description": "SWR React hooks for Firestore, that you can actually use in production, on every screen.",
"main": "lib/commonjs/index.js",
Expand All @@ -18,43 +18,43 @@
"release": "release-it",
"example": "yarn --cwd example",
"pods": "cd example/ios && node -e \"process.exit(require('os').platform() === 'darwin')\" || pod install",
"bootstrap": "yarn example && yarn && yarn pods"
"bootstrap": "yarn example && yarn"
},
"keywords": [
"react-native",
"ios",
"android"
],
"repository": "https://github.com/nandorojo/swr-firestore",
"author": "Fernando Rojo <[email protected]> (https://github.com/nandorojo)",
"repository": "https://github.com/alexandersergan/swr-firestore",
"author": "Alexander Sergan <[email protected]> (https://github.com/alexandersergan)",
"license": "MIT",
"bugs": {
"url": "https://github.com/nandorojo/swr-firestore/issues"
"url": "https://github.com/alexandersergan/swr-firestore/issues"
},
"homepage": "https://github.com/nandorojo/swr-firestore#readme",
"homepage": "https://github.com/alexandersergan/swr-firestore#readme",
"devDependencies": {
"@commitlint/config-conventional": "^8.3.4",
"@firebase/firestore-types": "^1.10.1",
"@react-native-community/bob": "^0.10.1",
"@react-native-community/eslint-config": "^0.0.7",
"@release-it/conventional-changelog": "^1.1.0",
"@types/jest": "^25.1.2",
"@types/lodash.get": "^4.4.6",
"@types/lodash.set": "^4.3.6",
"@types/react": "^16.9.19",
"@types/react-native": "0.61.10",
"commitlint": "^8.3.4",
"eslint": "^6.8.0",
"eslint-config-nando": "^1.0.9",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"firebase": "^7.14.1",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"react": "~16.9.0",
"react-native": "~0.61.5",
"release-it": "^12.6.3",
"typescript": "^4.1.0-dev.20201015"
"@commitlint/config-conventional": "^17.6.6",
"@firebase/firestore-types": "^3.0.0",
"@react-native-community/bob": "^0.17.1",
"@react-native-community/eslint-config": "^3.2.0",
"@release-it/conventional-changelog": "^7.0.0",
"@types/jest": "^29.5.3",
"@types/lodash.get": "^4.4.7",
"@types/lodash.set": "^4.3.7",
"@types/react": "^18.2.14",
"@types/react-native": "0.72.2",
"commitlint": "^17.6.6",
"eslint": "^8.44.0",
"eslint-config-nando": "^1.1.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
"firebase": "^10.0.0",
"jest": "^29.6.1",
"prettier": "^3.0.0",
"react": "~18.2.0",
"react-native": "~0.72.2",
"release-it": "^16.1.0",
"typescript": "^5.1.6"
},
"peerDependencies": {
"react": "*"
Expand Down Expand Up @@ -105,6 +105,6 @@
"dependencies": {
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"swr": "^0.2.0"
"swr": "^2.2.0"
}
}
2 changes: 1 addition & 1 deletion src/classes/Fuego.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as firebase from 'firebase/app'
import firebase from 'firebase/compat/app'

// import 'firebase/firestore'
// import 'firebase/auth'
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/static-mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ data: ${JSON.stringify(data)}`
)
})

return fuego.db.doc(path).set(data, options)
return fuego.db.doc(path).set(data, options as SetOptions )
}

const update = <
Expand Down
11 changes: 5 additions & 6 deletions src/hooks/use-swr-collection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useSWR, { mutate as mutateStatic, ConfigInterface } from 'swr'
import useSWR, { mutate as mutateStatic, SWRConfiguration, } from 'swr'
import { fuego } from '../context'
import { useRef, useEffect, useMemo, useCallback } from 'react'
// import { useMemoOne as useMemo } from 'use-memo-one'
Expand Down Expand Up @@ -285,7 +285,7 @@ const createListenerAsync = async <Doc extends Document = Document>(

export type CollectionSWROptions<
Doc extends Document = Document
> = ConfigInterface<Doc[] | null>
> = SWRConfiguration<Doc[] | null>
/**
* Call a Firestore Collection
* @template Doc
Expand Down Expand Up @@ -467,9 +467,9 @@ export const useCollection = <

// this MUST be after the previous effect to avoid duplicate initial validations.
// only happens on updates, not initial mounting
const revalidateRef = useRef(swr.revalidate)
const revalidateRef = useRef(swr.mutate)
useEffect(() => {
revalidateRef.current = swr.revalidate
revalidateRef.current = swr.mutate
})

useEffect(() => {
Expand All @@ -491,7 +491,7 @@ export const useCollection = <
if (path) collectionCache.addCollectionToCache(path, memoQueryString)
}, [path, memoQueryString])

const { data, isValidating, revalidate, mutate, error } = swr
const { data, isValidating, mutate, error } = swr

/**
* `add(data)`: Extends the Firestore document [`add` function](https://firebase.google.com/docs/firestore/manage-data/add-data).
Expand Down Expand Up @@ -545,7 +545,6 @@ export const useCollection = <
return {
data,
isValidating,
revalidate,
mutate,
error,
add,
Expand Down
17 changes: 8 additions & 9 deletions src/hooks/use-swr-document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useSWR, { mutate, ConfigInterface } from 'swr'
import useSWR, { mutate, SWRConfiguration } from 'swr'
import type { SetOptions, FieldValue } from '@firebase/firestore-types'
import { fuego } from '../context'
import { useRef, useEffect, useCallback } from 'react'
Expand Down Expand Up @@ -36,7 +36,7 @@ type Options<Doc extends Document = Document> = {
* Default: `true`
*/
ignoreFirestoreDocumentSnapshotField?: boolean
} & ConfigInterface<Doc | null>
} & SWRConfiguration<Doc | null>

type ListenerReturnType<Doc extends Document = Document> = {
initialData: Doc
Expand Down Expand Up @@ -287,18 +287,18 @@ export const useDocument = <
swrOptions
)

const { data, isValidating, revalidate, mutate: connectedMutate, error } = swr
const { data, isValidating, mutate: connectedMutate, error } = swr

// if listen changes,
// we run revalidate.
// we run `mutate()` as `revalidate`.
// This triggers SWR to fetch again
// Why? because we don't want to put listen or memoQueryString
// in the useSWR key. If we did, then we couldn't mutate
// based on path. If we had useSWR(['users', { where: ['name', '==, 'fernando']}]),
// and we updated the proper `user` dictionary, it wouldn't mutate, because of
// the key.
// thus, we move the `listen` and `queryString` options to refs passed to `useSWR`,
// and we call `revalidate` if either of them change.
// and we call `mutate()` as `revalidate` if either of them change.
const mounted = useRef(false)
useEffect(() => {
if (mounted.current) revalidateRef.current()
Expand All @@ -307,9 +307,9 @@ export const useDocument = <

// this MUST be after the previous effect to avoid duplicate initial validations.
// only happens on updates, not initial mount.
const revalidateRef = useRef(swr.revalidate)
const revalidateRef = useRef(swr.mutate)
useEffect(() => {
revalidateRef.current = swr.revalidate
revalidateRef.current = swr.mutate
})

useEffect(() => {
Expand Down Expand Up @@ -345,7 +345,7 @@ export const useDocument = <
})
}
if (!path) return null
return fuego.db.doc(path).set(data, options)
return fuego.db.doc(path).set(data, options as SetOptions)
},
[path, listen, connectedMutate]
)
Expand Down Expand Up @@ -379,7 +379,6 @@ export const useDocument = <
return {
data,
isValidating,
revalidate,
mutate: connectedMutate,
error,
set,
Expand Down
Loading