Skip to content

Commit 8be0624

Browse files
committed
handle domain and global
1 parent dee1a47 commit 8be0624

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

packages/react/src/provider/use-context-mutator.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,22 @@ import { OpenFeature, EvaluationContext } from '@openfeature/web-sdk';
22

33
type DomainContextMutator = (domain: string, updatedContext: EvaluationContext) => Promise<void>;
44

5-
type ContextMutatorReturn = {
6-
mutateContext: DomainContextMutator;
7-
}
85
/**
96
*
107
* A hook for accessing context mutating functions.
118
*
12-
* @returns {ContextMutatorReturn}
139
*/
14-
export function useContextMutator(): {
15-
mutateContext: DomainContextMutator;
16-
} {
17-
return {
18-
/**
19-
*
20-
* Mutates the evaluation context for a given domain.
21-
*
22-
* @param {string}domain
23-
* @param {EvaluationContext} updatedContext
24-
*/
25-
mutateContext: async (domain: string, updatedContext: EvaluationContext) => {
26-
await OpenFeature.setContext(domain, updatedContext);
10+
export function useContextMutator() {
11+
12+
async function mutateContext(domainOrUpdatedContext: string | EvaluationContext, updatedContextOrUndefined?: EvaluationContext): Promise<void> {
13+
if (typeof domainOrUpdatedContext === 'string' && updatedContextOrUndefined) {
14+
await OpenFeature.setContext(domainOrUpdatedContext, updatedContextOrUndefined);
15+
} else if (typeof domainOrUpdatedContext !== 'string') {
16+
OpenFeature.setContext(domainOrUpdatedContext);
2717
}
18+
}
19+
20+
return {
21+
mutateContext,
2822
};
2923
}

0 commit comments

Comments
 (0)