Skip to content

Commit 89acb49

Browse files
committed
expand use of setStateProperty to all cases
1 parent f3ae661 commit 89acb49

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

packages/app-check/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
PartialObserver
2424
} from './public-types';
2525
import { ERROR_FACTORY, AppCheckError } from './errors';
26-
import { getState, setState, AppCheckState, getDebugState } from './state';
26+
import { getState, setState, AppCheckState, getDebugState, setStateProperty } from './state';
2727
import { FirebaseApp, getApp, _getProvider } from '@firebase/app';
2828
import { getModularInstance, ErrorFn, NextFn } from '@firebase/util';
2929
import { AppCheckService } from './factory';
@@ -134,7 +134,7 @@ function _activate(
134134
newState.provider = provider; // Read cached token from storage if it exists and store it in memory.
135135
newState.cachedTokenPromise = readTokenFromStorage(app).then(cachedToken => {
136136
if (cachedToken && isValid(cachedToken)) {
137-
setState(app, { ...getState(app), token: cachedToken });
137+
setStateProperty(app, 'token', cachedToken);
138138
// notify all listeners with the cached token
139139
notifyTokenListeners(app, { token: cachedToken.token });
140140
}
@@ -178,7 +178,7 @@ export function setTokenAutoRefreshEnabled(
178178
state.tokenRefresher.stop();
179179
}
180180
}
181-
setState(app, { ...state, isTokenAutoRefreshEnabled });
181+
setStateProperty(app, 'isTokenAutoRefreshEnabled', isTokenAutoRefreshEnabled);
182182
}
183183
/**
184184
* Get the current App Check token. Attaches to the most recent

packages/app-check/src/recaptcha.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { FirebaseApp } from '@firebase/app';
19-
import { getState, setState } from './state';
19+
import { getState, setStateProperty } from './state';
2020
import { Deferred } from '@firebase/util';
2121
import { getRecaptcha, ensureActivated } from './util';
2222

@@ -28,10 +28,9 @@ export function initializeV3(
2828
app: FirebaseApp,
2929
siteKey: string
3030
): Promise<GreCAPTCHA> {
31-
const state = getState(app);
3231
const initialized = new Deferred<GreCAPTCHA>();
3332

34-
setState(app, { ...state, reCAPTCHAState: { initialized } });
33+
setStateProperty(app, 'reCAPTCHAState', { initialized });
3534
const divId = makeDiv(app);
3635

3736
const grecaptcha = getRecaptcha(false);
@@ -54,10 +53,9 @@ export function initializeEnterprise(
5453
app: FirebaseApp,
5554
siteKey: string
5655
): Promise<GreCAPTCHA> {
57-
const state = getState(app);
5856
const initialized = new Deferred<GreCAPTCHA>();
5957

60-
setState(app, { ...state, reCAPTCHAState: { initialized } });
58+
setStateProperty(app, 'reCAPTCHAState', { initialized });
6159
const divId = makeDiv(app);
6260

6361
const grecaptcha = getRecaptcha(true);
@@ -148,12 +146,9 @@ function renderInvisibleWidget(
148146

149147
const state = getState(app);
150148

151-
setState(app, {
152-
...state,
153-
reCAPTCHAState: {
154-
...state.reCAPTCHAState!, // state.reCAPTCHAState is set in the initialize()
155-
widgetId
156-
}
149+
setStateProperty(app, 'reCAPTCHAState', {
150+
...state.reCAPTCHAState!, // state.reCAPTCHAState is set in the initialize()
151+
widgetId
157152
});
158153
}
159154

0 commit comments

Comments
 (0)