Skip to content

Commit 9ec098f

Browse files
committed
chore: add copywrite declarations
1 parent d9ad3fe commit 9ec098f

File tree

10 files changed

+164
-14
lines changed

10 files changed

+164
-14
lines changed

packages/auth/src/mutations.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import {
218
ActionCodeInfo,
319
ActionCodeSettings,

packages/auth/src/useAuthFetchSignInMethodsForEmail.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import {
218
QueryKey,
319
useQuery,

packages/auth/src/useAuthGetRedirectResult.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import {
218
QueryKey,
319
useQuery,

packages/auth/src/useAuthIdToken.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import { QueryKey, UseQueryOptions, UseQueryResult } from "react-query";
218
import { Auth, AuthError, IdTokenResult } from "firebase/auth";
319
import { useSubscription } from "../../utils/src/useSubscription";

packages/auth/src/useAuthUser.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import { QueryKey, UseQueryOptions, UseQueryResult } from "react-query";
218
import { Auth, AuthError, NextOrObserver, User } from "firebase/auth";
319
import { useSubscription } from "../../utils/src/useSubscription";

packages/database/__test__/useDatabaseSnapshot.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ describe("Database", () => {
166166
await hook2.waitFor(() => hook2.result.current.isSuccess, {
167167
timeout: 5000,
168168
});
169-
console.log(mock2.mock.calls.map((call) => call[0]));
170169

171170
expect(mock1.mock.calls.length).toBe(1);
172171

@@ -395,7 +394,6 @@ describe("Database", () => {
395394
await hook2.waitFor(() => hook2.result.current.isSuccess, {
396395
timeout: 5000,
397396
});
398-
console.log(mock2.mock.calls.map((call) => call[0]));
399397

400398
expect(mock1.mock.calls.length).toBe(1);
401399

packages/database/src/useDatabaseMutation.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import {
218
useMutation,
319
UseMutationOptions,

packages/database/src/useDatabaseSnapshot.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import { QueryKey, UseQueryOptions, UseQueryResult } from "react-query";
218
import { DatabaseReference, onValue, DataSnapshot } from "firebase/database";
319
import { useCallback } from "react";

packages/firestore/src/namedQuery.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import {
218
Firestore,
319
Query,

packages/utils/src/useSubscription.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
import { Unsubscribe as AuthUnsubscribe } from "firebase/auth";
218
import { Unsubscribe as FirestoreUnsubscribe } from "firebase/firestore";
319
import { Unsubscribe as DatabaseUnsubscribe } from "firebase/database";
@@ -31,31 +47,29 @@ type UseSubscriptionOptions<TData, TError, R> = UseQueryOptions<
3147
fetchFn?: () => Promise<TData>;
3248
};
3349

50+
/**
51+
* Utility hook to subscribe to events, given a function that returns an observer callback.
52+
* @param queryKey The react-query queryKey
53+
* @param subscriptionKey A hashable key to store the subscription
54+
* @param subscribeFn Returns an unsubscribe function to the event, the argument of subscribeFn is a callback to set data.
55+
* @param options
56+
* @returns
57+
*/
3458
export function useSubscription<TData, TError, R = TData>(
3559
queryKey: QueryKey,
3660
subscriptionKey: QueryKey,
3761
subscribeFn: (cb: (data: TData | null) => Promise<void>) => Unsubscribe,
3862
options?: UseSubscriptionOptions<TData, TError, R>
3963
): UseQueryResult<R, TError> {
40-
useEffect(() => {
41-
if (!options?.onlyOnce) {
42-
observerCount[subscriptionHash] += 1;
43-
return () => {
44-
observerCount[subscriptionHash] -= 1;
45-
cleanupSubscription(subscriptionHash);
46-
};
47-
}
48-
}, []);
49-
5064
const hashFn = options?.queryKeyHashFn || hashQueryKey;
5165
const subscriptionHash = hashFn(subscriptionKey);
66+
const queryClient = useQueryClient();
5267

5368
if (!options?.onlyOnce) {
69+
// if it's a subscription, we have at least one observer now
5470
observerCount[subscriptionHash] ??= 1;
5571
}
5672

57-
const queryClient = useQueryClient();
58-
5973
function cleanupSubscription(subscriptionHash: string) {
6074
if (observerCount[subscriptionHash] === 1) {
6175
const unsubscribe = unsubscribes[subscriptionHash];
@@ -64,6 +78,16 @@ export function useSubscription<TData, TError, R = TData>(
6478
}
6579
}
6680

81+
useEffect(() => {
82+
if (!options?.onlyOnce) {
83+
observerCount[subscriptionHash] += 1;
84+
return () => {
85+
observerCount[subscriptionHash] -= 1;
86+
cleanupSubscription(subscriptionHash);
87+
};
88+
}
89+
}, []);
90+
6791
let resolvePromise: (data: TData | null) => void = () => null;
6892

6993
const result: CancellablePromise<TData | null> = new Promise<TData | null>(

0 commit comments

Comments
 (0)