Skip to content

Commit

Permalink
Merge pull request #13 from SchematicHQ/ben/sch-679-js-listener
Browse files Browse the repository at this point in the history
Add flag listener option to enable react useEffect
  • Loading branch information
bpapillon authored Jan 25, 2024
2 parents d3edd75 + d3ac57a commit d977897
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
"test": "jest --config jest.config.js"
},
"types": "dist/schematic.d.ts",
"version": "0.1.0"
"version": "0.1.1"
}
7 changes: 7 additions & 0 deletions js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type StoragePersister = {
};

type SchematicOptions = {
flagListener?: (values: Record<string, boolean>) => void;
storage?: StoragePersister;
useWebSocket?: boolean;
};
Expand All @@ -83,11 +84,13 @@ export class Schematic {
private storage: StoragePersister | undefined;
private useWebSocket: boolean = false;
private values: Record<string, Record<string, boolean>> = {};
private flagListener?: (values: Record<string, boolean>) => 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;
Expand Down Expand Up @@ -332,6 +335,10 @@ export class Schematic {
{},
);

if (this.flagListener) {
this.flagListener(this.values[contextString(context)]);
}

if (!resolved) {
resolved = true;
resolve();
Expand Down
21 changes: 21 additions & 0 deletions react/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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/*"]
}
6 changes: 3 additions & 3 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit d977897

Please sign in to comment.