From d3ac57a5254b1346a55db494aafb43320c9f090e Mon Sep 17 00:00:00 2001 From: Ben Papillon Date: Wed, 24 Jan 2024 21:43:57 -0500 Subject: [PATCH] Add flag listener option to enable react useEffect --- .eslintrc.json => js/.eslintrc.json | 0 js/package.json | 2 +- js/src/index.ts | 7 +++++++ react/.eslintrc.json | 21 +++++++++++++++++++++ react/package.json | 6 +++--- 5 files changed, 32 insertions(+), 4 deletions(-) rename .eslintrc.json => js/.eslintrc.json (100%) create mode 100644 react/.eslintrc.json diff --git a/.eslintrc.json b/js/.eslintrc.json similarity index 100% rename from .eslintrc.json rename to js/.eslintrc.json diff --git a/js/package.json b/js/package.json index 7646bd7c..f818deb1 100644 --- a/js/package.json +++ b/js/package.json @@ -44,5 +44,5 @@ "test": "jest --config jest.config.js" }, "types": "dist/schematic.d.ts", - "version": "0.1.0" + "version": "0.1.1" } diff --git a/js/src/index.ts b/js/src/index.ts index 0c573907..ddb39d50 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -64,6 +64,7 @@ type StoragePersister = { }; type SchematicOptions = { + flagListener?: (values: Record) => void; storage?: StoragePersister; useWebSocket?: boolean; }; @@ -83,11 +84,13 @@ export class Schematic { private storage: StoragePersister | undefined; private useWebSocket: boolean = false; private values: Record> = {}; + private flagListener?: (values: Record) => void; constructor(apiKey: string, options?: SchematicOptions) { this.apiKey = apiKey; this.eventQueue = []; this.useWebSocket = options?.useWebSocket ?? false; + this.flagListener = options?.flagListener; if (options?.storage) { this.storage = options.storage; @@ -332,6 +335,10 @@ export class Schematic { {}, ); + if (this.flagListener) { + this.flagListener(this.values[contextString(context)]); + } + if (!resolved) { resolved = true; resolve(); diff --git a/react/.eslintrc.json b/react/.eslintrc.json new file mode 100644 index 00000000..6ebb9ccc --- /dev/null +++ b/react/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { "project": ["./tsconfig.json"] }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "@typescript-eslint/strict-boolean-expressions": [ + 2, + { + "allowString" : false, + "allowNumber" : false + } + ] + }, + "ignorePatterns": ["src/**/*.test.ts", "src/frontend/generated/*"] +} diff --git a/react/package.json b/react/package.json index e67fa6e1..c8a8d992 100644 --- a/react/package.json +++ b/react/package.json @@ -7,7 +7,7 @@ "@microsoft/api-extractor": "^7.38.3", "@types/jest": "^29.5.11", "@types/react": "^18.2.48", - "@typescript-eslint/eslint-plugin": "^6.13.2", + "@typescript-eslint/eslint-plugin": "^6.19.1", "@typescript-eslint/parser": "^6.13.2", "esbuild": "^0.19.9", "esbuild-jest": "^0.5.0", @@ -32,8 +32,8 @@ }, "scripts": { "build": "npx tsc && yarn clean && yarn build:cjs && yarn build:esm && yarn build:types", - "build:cjs": "npx esbuild src/index.ts --bundle --format=cjs --outfile=dist/schematic-react.cjs.js --platform=neutral", - "build:esm": "npx esbuild src/index.ts --bundle --format=esm --outfile=dist/schematic-react.esm.js --platform=neutral", + "build:cjs": "npx esbuild src/index.tsx --bundle --format=cjs --outfile=dist/schematic-react.cjs.js --platform=neutral", + "build:esm": "npx esbuild src/index.tsx --bundle --format=esm --outfile=dist/schematic-react.esm.js --platform=neutral", "build:types": "npx tsc && npx api-extractor run", "clean": "rm -rf dist", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --fix",