Skip to content

Commit

Permalink
big refactor for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
clord committed Apr 20, 2022
1 parent 9ed2a7c commit f844d33
Show file tree
Hide file tree
Showing 113 changed files with 15,629 additions and 6,245 deletions.
177 changes: 177 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
{
"env": {
"es6": true,
"jest": true,
"browser": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"project": "./tsconfig.eslint.json"
},
"plugins": ["react", "@typescript-eslint", "import", "eslint-plugin-import-helpers"],
"settings": {
"react": {
"version": "detect"
}
},
"extends": [
"plugin:react-hooks/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended",
"eslint:recommended",
"plugin:react/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
"rules": {
"react/no-multi-comp": [ "error", { "ignoreStateless": true }],
"react/prefer-stateless-function": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
"varsIgnorePattern": "^__",
"ignoreRestSiblings": true,
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"consistent-return": "error",
"@typescript-eslint/explicit-module-boundary-types": ["error", {
"allowDirectConstAssertionInArrowFunctions": true,
"allowHigherOrderFunctions": true
}],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/indent": "off",
"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/default-param-last": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-dynamic-delete": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/array-type": "off",
"@typescript-eslint/prefer-regexp-exec": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/sort-type-union-intersection-members": "error",
"@typescript-eslint/prefer-ts-expect-error": "error",
"@typescript-eslint/restrict-template-expressions": "error",
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/no-unnecessary-type-constraint": "error",
"@typescript-eslint/no-invalid-void-type": "error",
"@typescript-eslint/no-for-in-array": "error",
"no-unneeded-ternary": "error",
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": ["error", {
"ignoreDeclarationMerge": true
}],
"camelcase": "warn",
"curly": "error",
"no-return-await": "off",
"@typescript-eslint/return-await": "error",
"eqeqeq": ["error", "smart"],
"import/no-unresolved": "error",
"no-implicit-coercion": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-empty-pattern": "error",
"no-eval": "error",
"no-extra-semi": "error",
"no-fallthrough": "error",
"no-shadow": "off",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-unused-expressions": "off",
"no-unused-vars": "off",
"prefer-const": "error",
"react-hooks/exhaustive-deps": "error",
"react/react-in-jsx-scope": "off",
"react-hooks/rules-of-hooks": "error",
"react/boolean-prop-naming": ["error", { "validateNested": true }],
"react/jsx-uses-vars": "error",
"react/prop-types": "off",
"use-isnan": "error",
"valid-typeof": "error",
"@typescript-eslint/strict-boolean-expressions": [
"error",
{
"allowString": false,
"allowNumber": false,
"allowNullableBoolean": false,
"allowNullableObject": false,
"allowNullableString": false,
"allowNullableNumber": false,
"allowAny": false
}
],
"@typescript-eslint/no-shadow": [
"warn",
{
"hoist": "all"
}
],
"no-console": [
"error",
{
"allow": [
"error",
"dir",
"timeLog",
"assert",
"clear",
"count",
"countReset",
"group",
"groupEnd",
"table",
"warn",
"info",
"dirxml",
"groupCollapsed",
"Console",
"profile",
"profileEnd",
"timeStamp",
"context"
]
}
],
"import-helpers/order-imports": [
"warn",
{
"newlinesBetween": "always",
"groups": [
["/^react$/", "/^react-/"],
"module",
["parent", "sibling", "index"]
],
"alphabetize": { "order": "asc", "ignoreCase": true }
}
]
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
"no-undef": "off"
}
}
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.vs/
.DS_Store
node_modules/
*.tgz
lib

27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SHELL := /bin/sh
PATH := ./node_modules/.bin:$(PATH)

.PHONY: build
build: build-css build-js

.PHONY: build-js
build-js:
npm run build-js

.PHONY: build-css
build-css:
npm run build-css

.PHONY: watch-js
watch-js:
npm run watch-js


.PHONY: watch-css
watch-css:
npm run watch-css

.PHONY: watch
watch:
npm run watch

File renamed without changes.
7 changes: 7 additions & 0 deletions dist/Enable.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
export interface EnableProps {
readonly feature?: string[] | string;
readonly allFeatures?: string[];
children: React.ReactNode;
}
export declare function Enable({ feature, allFeatures, children }: EnableProps): JSX.Element | null;
4 changes: 4 additions & 0 deletions dist/EnableContext.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference types="react" />
import { FeatureValue } from './FeatureState';
export declare type EnableContextType = (feature: string) => FeatureValue;
export declare const EnableContext: import("react").Context<EnableContextType>;
12 changes: 12 additions & 0 deletions dist/FeatureContext.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="react" />
import { FeaturesDispatch, FeaturesState } from './FeaturesState';
import { FeatureDescription, FeatureValue } from './FeatureState';
export declare const FeatureContext: import("react").Context<FeatureContextType | null>;
export interface FeatureContextType {
overridesSend: FeaturesDispatch;
defaultsSend: FeaturesDispatch;
featuresDescription: readonly FeatureDescription[];
overridesState: FeaturesState;
defaultsState: FeaturesState;
test: (flag: string) => FeatureValue;
}
55 changes: 55 additions & 0 deletions dist/FeatureState.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { InterpreterFrom, StateFrom } from 'xstate';
export declare type FeatureValue = false | true | undefined;
export declare type FeatureState = StateFrom<typeof FeatureMachine>;
export declare type FeatureDispatch = InterpreterFrom<typeof FeatureMachine>['send'];
export declare function valueForState(featureState: FeatureState): [FeatureValue, boolean];
export interface FeatureDescription<K extends string = string> {
readonly name: K;
readonly description?: string;
readonly onChangeDefault?: (name: K, newValue: FeatureValue) => Promise<FeatureValue>;
readonly force?: boolean;
readonly noOverride?: boolean;
readonly defaultValue?: FeatureValue;
}
interface FeatureContext {
featureDesc?: FeatureDescription;
}
declare type FeatureTypeState = {
value: 'asyncDenabled';
context: FeatureContext;
} | {
value: 'asyncDisabled';
context: FeatureContext;
} | {
value: 'asyncUnspecied';
context: FeatureContext;
} | {
value: 'disabled';
context: FeatureContext;
} | {
value: 'enabled';
context: FeatureContext;
} | {
value: 'initial';
context: never;
} | {
value: 'unspecied';
context: FeatureContext;
};
export declare type FeatureAction = {
type: 'DISABLE';
} | {
type: 'ENABLE';
} | {
type: 'INIT';
feature: FeatureDescription;
} | {
type: 'SET';
value: FeatureValue;
} | {
type: 'TOGGLE';
} | {
type: 'UNSET';
};
export declare const FeatureMachine: import("xstate").StateMachine<FeatureContext, any, FeatureAction, FeatureTypeState, import("xstate").BaseActionObject, import("xstate").ServiceMap, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, FeatureAction, import("xstate").BaseActionObject, import("xstate").ServiceMap>>;
export {};
10 changes: 10 additions & 0 deletions dist/Features.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ReactNode } from 'react';
import { FeatureDescription } from './FeatureState';
interface FeatureProps {
readonly features: readonly FeatureDescription[];
readonly children?: ReactNode;
readonly disableConsole?: boolean;
readonly storage?: Storage;
}
export declare function Features({ children, features, disableConsole, storage, }: FeatureProps): JSX.Element;
export {};
42 changes: 42 additions & 0 deletions dist/FeaturesState.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ActorRefFrom, InterpreterFrom, StateFrom } from 'xstate';
import { FeatureMachine, FeatureDescription, FeatureValue } from './FeatureState';
export interface FeaturesContext {
features: {
[x: string]: ActorRefFrom<typeof FeatureMachine>;
};
}
export declare type FeaturesAction = {
type: 'DE_INIT';
} | {
type: 'DISABLE';
name: string;
} | {
type: 'ENABLE';
name: string;
} | {
type: 'INIT';
features: readonly FeatureDescription[];
} | {
type: 'SET_ALL';
features: {
[key: string]: FeatureValue;
};
} | {
type: 'SET';
name: string;
value: FeatureValue;
} | {
type: 'TOGGLE';
name: string;
} | {
type: 'UNSET';
name: string;
};
export interface FeaturesTypeState {
value: 'ready';
context: FeaturesContext;
}
export declare type FeaturesState = StateFrom<typeof FeaturesMachine>;
export declare type FeaturesDispatch = InterpreterFrom<typeof FeaturesMachine>['send'];
export declare function valueOfFeature(featuresState: FeaturesState, feature: string): [FeatureValue, boolean];
export declare const FeaturesMachine: import("xstate").StateMachine<FeaturesContext, any, FeaturesAction, FeaturesTypeState, import("xstate").BaseActionObject, import("xstate").ServiceMap, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, FeaturesAction, import("xstate").BaseActionObject, import("xstate").ServiceMap>>;
21 changes: 21 additions & 0 deletions dist/GlobalEnable.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FeaturesDispatch } from './FeaturesState';
import { FeatureDescription, FeatureValue } from './FeatureState';
export declare class GlobalEnable {
private readonly featureDesc;
private readonly dispatch;
private readonly testFeature;
constructor(dispatch: FeaturesDispatch, testFeature: (_: string) => FeatureValue, featureDesc: readonly FeatureDescription[]);
toggle(feature: string): void;
enable(feature: string): void;
unset(feature: string): void;
disable(feature: string): void;
setAll(features: {
[key: string]: FeatureValue;
}): void;
listFeatures(): readonly [string, FeatureValue][];
}
declare global {
interface Window {
feature?: GlobalEnable;
}
}
3 changes: 3 additions & 0 deletions dist/ToggleFeatures.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="react" />
export declare function ToggleFeatures(): JSX.Element | null;
export declare function ToggleFeatureUnwrapped(): JSX.Element | null;
Loading

0 comments on commit f844d33

Please sign in to comment.