Skip to content

Commit

Permalink
Prepare v3.0.0 release (#32)
Browse files Browse the repository at this point in the history
* Eliminate any usage

* Update JSDoc documentation

* Add CHANGELOG.md

* Bump version
  • Loading branch information
adams85 committed Jun 14, 2023
1 parent 8d481a7 commit b5096f5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please check the [Github Releases](https://github.com/configcat/react-sdk/releases) page for the changelog of the ConfigCat SDK for React applications.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "configcat-react",
"version": "2.3.0",
"version": "3.0.0",
"scripts": {
"build": "npm run build:esm && npm run build:cjs",
"build:esm": "tsc -p tsconfig.build.esm.json && gulp esm",
Expand Down
10 changes: 5 additions & 5 deletions src/ConfigCatHOC.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { IConfigCatClient, User } from "configcat-common";
import type { IConfigCatClient, SettingTypeOf, SettingValue, User } from "configcat-common";
import React from "react";
import type { ConfigCatContextData } from "./ConfigCatContext";
import ConfigCatContext from "./ConfigCatContext";

export type GetValueType = (
export type GetValueType = <T extends SettingValue>(
key: string,
defaultValue: any,
defaultValue: T,
user?: User
) => Promise<any>;
) => Promise<SettingTypeOf<T>>;

const getValueFunction = (client: IConfigCatClient) => {
return async function name(key: string, defaultValue: any, user?: User) {
return async function <T extends SettingValue>(key: string, defaultValue: T, user?: User) {
return await client.getValueAsync(key, defaultValue, user);
};
};
Expand Down
8 changes: 4 additions & 4 deletions src/ConfigCatHooks.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { IConfigCatClient, User } from "configcat-common";
import type { IConfigCatClient, SettingTypeOf, SettingValue, User } from "configcat-common";
import { useContext, useEffect, useState } from "react";
import ConfigCatContext from "./ConfigCatContext";

function useFeatureFlag(key: string, defaultValue: any, user?: User | undefined): {
value: any;
function useFeatureFlag<T extends SettingValue>(key: string, defaultValue: T, user?: User): {
value: SettingTypeOf<T>;
loading: boolean;
} {
const configCatContext = useContext(ConfigCatContext);

if (configCatContext === void 0) throw Error("useFeatureFlag hook must be used in ConfigCatProvider!");

const [featureFlagValue, setFeatureFlag] = useState(defaultValue);
const [featureFlagValue, setFeatureFlag] = useState(defaultValue as SettingTypeOf<T>);
const [loading, setLoading] = useState(true);

useEffect(() => {
Expand Down
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@ import withConfigCatClient from "./ConfigCatHOC";
import { useConfigCatClient, useFeatureFlag } from "./ConfigCatHooks";
import ConfigCatProvider from "./ConfigCatProvider";

/**
* Creates an instance of `ConfigCatConsoleLogger`.
* @param logLevel Log level (the minimum level to use for filtering log events).
*/
export function createConsoleLogger(logLevel: LogLevel): IConfigCatLogger {
return configcatcommon.createConsoleLogger(logLevel);
}

/**
* Creates an instance of `FlagOverrides` that uses a map data source.
* @param map The map that contains the overrides.
* @param behaviour The override behaviour.
* Specifies whether the local values should override the remote values
* or local values should only be used when a remote value doesn't exist
* or the local values should be used only.
*/
export function createFlagOverridesFromMap(map: { [name: string]: NonNullable<SettingValue> }, behaviour: OverrideBehaviour): FlagOverrides {
return new FlagOverrides(new MapOverrideDataSource(map), behaviour);
}

/** Options used to configure the ConfigCat SDK in the case of Auto Polling mode. */
export type IReactAutoPollOptions = IAutoPollOptions;

/** Options used to configure the ConfigCat SDK in the case of Lazy Loading mode. */
export type IReactLazyLoadingOptions = ILazyLoadingOptions;

/** Options used to configure the ConfigCat SDK in the case of Manual Polling mode. */
export type IReactManualPollOptions = IManualPollOptions;

export type IReactConfigCatLogger = IConfigCatLogger;
Expand Down

0 comments on commit b5096f5

Please sign in to comment.