Skip to content

Commit 9c7c6bf

Browse files
authored
ref: Avoid enum usage (#16922)
Apart of directly vendored code, we should avoid `enum`, as it has bundle size impact. Also somehow part of #16846
1 parent dbdfe48 commit 9c7c6bf

File tree

3 files changed

+26
-32
lines changed

3 files changed

+26
-32
lines changed

packages/browser/src/integrations/featureFlags/openfeature/types.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ export const StandardResolutionReasons = {
1717
STALE: 'STALE',
1818
ERROR: 'ERROR',
1919
} as const;
20-
export enum ErrorCode {
21-
PROVIDER_NOT_READY = 'PROVIDER_NOT_READY',
22-
PROVIDER_FATAL = 'PROVIDER_FATAL',
23-
FLAG_NOT_FOUND = 'FLAG_NOT_FOUND',
24-
PARSE_ERROR = 'PARSE_ERROR',
25-
TYPE_MISMATCH = 'TYPE_MISMATCH',
26-
TARGETING_KEY_MISSING = 'TARGETING_KEY_MISSING',
27-
INVALID_CONTEXT = 'INVALID_CONTEXT',
28-
GENERAL = 'GENERAL',
29-
}
20+
21+
type ErrorCode =
22+
| 'PROVIDER_NOT_READY'
23+
| 'PROVIDER_FATAL'
24+
| 'FLAG_NOT_FOUND'
25+
| 'PARSE_ERROR'
26+
| 'TYPE_MISMATCH'
27+
| 'TARGETING_KEY_MISSING'
28+
| 'INVALID_CONTEXT'
29+
| 'GENERAL';
30+
3031
export interface Logger {
3132
error(...args: unknown[]): void;
3233
warn(...args: unknown[]): void;

packages/core/src/utils/syncpromise.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
import { isThenable } from './is';
33

44
/** SyncPromise internal states */
5-
const enum States {
6-
/** Pending */
7-
PENDING = 0,
8-
/** Resolved / OK */
9-
RESOLVED = 1,
10-
/** Rejected / Error */
11-
REJECTED = 2,
12-
}
5+
const STATE_PENDING = 0;
6+
const STATE_RESOLVED = 1;
7+
const STATE_REJECTED = 2;
8+
9+
type State = typeof STATE_PENDING | typeof STATE_RESOLVED | typeof STATE_REJECTED;
1310

1411
// Overloads so we can call resolvedSyncPromise without arguments and generic argument
1512
export function resolvedSyncPromise(): PromiseLike<void>;
@@ -46,12 +43,12 @@ type Executor<T> = (resolve: (value?: T | PromiseLike<T> | null) => void, reject
4643
* but is not async internally
4744
*/
4845
export class SyncPromise<T> implements PromiseLike<T> {
49-
private _state: States;
46+
private _state: State;
5047
private _handlers: Array<[boolean, (value: T) => void, (reason: any) => any]>;
5148
private _value: any;
5249

5350
public constructor(executor: Executor<T>) {
54-
this._state = States.PENDING;
51+
this._state = STATE_PENDING;
5552
this._handlers = [];
5653

5754
this._runExecutor(executor);
@@ -135,7 +132,7 @@ export class SyncPromise<T> implements PromiseLike<T> {
135132

136133
/** Excute the resolve/reject handlers. */
137134
private _executeHandlers(): void {
138-
if (this._state === States.PENDING) {
135+
if (this._state === STATE_PENDING) {
139136
return;
140137
}
141138

@@ -147,11 +144,11 @@ export class SyncPromise<T> implements PromiseLike<T> {
147144
return;
148145
}
149146

150-
if (this._state === States.RESOLVED) {
147+
if (this._state === STATE_RESOLVED) {
151148
handler[1](this._value as unknown as any);
152149
}
153150

154-
if (this._state === States.REJECTED) {
151+
if (this._state === STATE_REJECTED) {
155152
handler[2](this._value);
156153
}
157154

@@ -161,8 +158,8 @@ export class SyncPromise<T> implements PromiseLike<T> {
161158

162159
/** Run the executor for the SyncPromise. */
163160
private _runExecutor(executor: Executor<T>): void {
164-
const setResult = (state: States, value?: T | PromiseLike<T> | any): void => {
165-
if (this._state !== States.PENDING) {
161+
const setResult = (state: State, value?: T | PromiseLike<T> | any): void => {
162+
if (this._state !== STATE_PENDING) {
166163
return;
167164
}
168165

@@ -178,11 +175,11 @@ export class SyncPromise<T> implements PromiseLike<T> {
178175
};
179176

180177
const resolve = (value: unknown): void => {
181-
setResult(States.RESOLVED, value);
178+
setResult(STATE_RESOLVED, value);
182179
};
183180

184181
const reject = (reason: unknown): void => {
185-
setResult(States.REJECTED, reason);
182+
setResult(STATE_REJECTED, reason);
186183
};
187184

188185
try {

packages/react/src/types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,7 @@ export type Navigation = NavigationStates[keyof NavigationStates];
197197
export type RouteData = any;
198198
export type Fetcher = any;
199199

200-
export declare enum HistoryAction {
201-
Pop = 'POP',
202-
Push = 'PUSH',
203-
Replace = 'REPLACE',
204-
}
200+
type HistoryAction = 'POP' | 'PUSH' | 'REPLACE';
205201

206202
export interface RouterState {
207203
historyAction: Action | HistoryAction | any;

0 commit comments

Comments
 (0)