From 4db51a5b0ed16c0768277482482372c579678bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augustin=20=C5=A0ulc?= Date: Sun, 3 Sep 2023 21:15:14 +0200 Subject: [PATCH] Linter updated and issues fixed --- examples/complexdemo/src/data/backendConnector.ts | 5 ++++- examples/complexdemo/src/data/repositoryBase.ts | 5 ++++- examples/complexdemo/src/main.tsx | 11 ++++++----- examples/navigation/src/main.tsx | 2 +- examples/todolist/src/main.tsx | 2 +- packages/apiclient/src/fetchError.ts | 5 ++++- packages/apiclient/src/restRequestBuilder.ts | 7 +++++-- packages/datascreens/src/filteredList.ts | 4 ++-- packages/dataviews/src/dataRepeater/index.tsx | 4 ++-- packages/dataviews/src/dataTypes.ts | 1 + packages/dirtycheck/src/automaticDirtyWatcher.ts | 6 ++++-- packages/generator/src/inversify/index.ts | 2 +- .../src/inversify/registrationsProcessor.ts | 6 +++++- packages/generator/src/inversify/types.ts | 1 + packages/generator/src/morphHelpers.ts | 2 +- packages/generator/src/openapi/fileGenerator.ts | 6 +++++- .../generator/src/openapi/models/aliasEntity.ts | 6 +++++- .../generator/src/openapi/models/entityProperty.ts | 5 ++++- packages/generator/src/openapi/models/enum.ts | 5 ++++- .../generator/src/openapi/models/externalEntity.ts | 5 ++++- .../generator/src/openapi/models/inheritedEntity.ts | 6 +++++- .../generator/src/openapi/models/objectEntity.ts | 5 ++++- .../generator/src/openapi/models/unionEntity.ts | 5 ++++- .../generator/src/openapi/parsers/openApi2Parser.ts | 6 ++---- .../generator/src/openapi/parsers/openApi3Parser.ts | 11 ++++++----- packages/generator/src/openapi/types.ts | 1 - packages/helpers/__tests__/busyWatcher.test.ts | 1 - packages/helpers/src/path.ts | 4 ++-- packages/helpers/src/types.ts | 2 +- packages/htmlcontrols/src/controls/checkbox.tsx | 2 +- .../src/controls/collectionCheckbox.tsx | 4 ++-- packages/htmlcontrols/src/controls/textbox.tsx | 2 +- packages/validation/src/asyncEntityValidator.ts | 2 +- packages/validation/src/automaticEntityValidator.ts | 6 +++++- packages/validation/src/manualEntityValidator.ts | 11 +++++++++-- packages/validation/src/serverEntityValidator.ts | 11 +++++++++-- packages/views/__tests__/bindingComponent.test.ts | 2 +- packages/views/__tests__/bindingProps.test.ts | 9 ++++----- packages/views/src/binding/bindingComponent.tsx | 2 +- packages/views/src/binding/bindingProps.ts | 4 ++-- packages/views/src/binding/useBinding.tsx | 13 ++++++------- packages/views/src/hooks/useViewModel.ts | 9 ++++++--- packages/views/src/router/router.tsx | 6 +++--- packages/views/src/types.ts | 11 ++++++----- stories/src/fields/Check.tsx | 2 +- stories/src/fields/Input.tsx | 2 +- 46 files changed, 147 insertions(+), 82 deletions(-) diff --git a/examples/complexdemo/src/data/backendConnector.ts b/examples/complexdemo/src/data/backendConnector.ts index a4131e45..0e173b14 100644 --- a/examples/complexdemo/src/data/backendConnector.ts +++ b/examples/complexdemo/src/data/backendConnector.ts @@ -4,7 +4,10 @@ import DeserializingRequestBuilder from "./deserializingRequestBuilder"; import { serializeEntity } from "./helpers"; export default class BackendConnector { - constructor(private baseUrl: string, private apiKey: string) {} + constructor( + private baseUrl: string, + private apiKey: string + ) {} @bound getRequestBuilder() { diff --git a/examples/complexdemo/src/data/repositoryBase.ts b/examples/complexdemo/src/data/repositoryBase.ts index 4b9484d3..c0656f8f 100644 --- a/examples/complexdemo/src/data/repositoryBase.ts +++ b/examples/complexdemo/src/data/repositoryBase.ts @@ -7,7 +7,10 @@ import type DeserializingRequestBuilder from "./deserializingRequestBuilder"; export default abstract class RepositoryBase { protected apiFactory: () => DeserializingRequestBuilder; - constructor(connector: BackendConnector, protected eventBus: EventBus) { + constructor( + connector: BackendConnector, + protected eventBus: EventBus + ) { this.apiFactory = connector.getRequestBuilder; } diff --git a/examples/complexdemo/src/main.tsx b/examples/complexdemo/src/main.tsx index 846ed2ce..37289b1c 100644 --- a/examples/complexdemo/src/main.tsx +++ b/examples/complexdemo/src/main.tsx @@ -1,11 +1,12 @@ import React from "react"; -import ReactDOM from "react-dom"; -import "./index.css"; +import { createRoot } from "react-dom/client"; import App from "./App"; +import "./index.css"; -ReactDOM.render( +const container = document.getElementById("root"); +const root = createRoot(container!); +root.render( - , - document.getElementById("root") + ); diff --git a/examples/navigation/src/main.tsx b/examples/navigation/src/main.tsx index 521ccf61..254ace46 100644 --- a/examples/navigation/src/main.tsx +++ b/examples/navigation/src/main.tsx @@ -58,7 +58,7 @@ declare module "@tanstack/react-router" { } const container = document.getElementById("root"); -// eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const root = createRoot(container!); root.render( diff --git a/examples/todolist/src/main.tsx b/examples/todolist/src/main.tsx index a490cea4..8713a61f 100644 --- a/examples/todolist/src/main.tsx +++ b/examples/todolist/src/main.tsx @@ -26,7 +26,7 @@ declare module "@tanstack/react-router" { } const container = document.getElementById("root"); -// eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const root = createRoot(container!); root.render( diff --git a/packages/apiclient/src/fetchError.ts b/packages/apiclient/src/fetchError.ts index 3f2c308b..8dd314c2 100644 --- a/packages/apiclient/src/fetchError.ts +++ b/packages/apiclient/src/fetchError.ts @@ -1,7 +1,10 @@ export default class FetchError extends Error { handled = false; - constructor(public response: Response, public content?: TContent) { + constructor( + public response: Response, + public content?: TContent + ) { super(response.statusText); } } diff --git a/packages/apiclient/src/restRequestBuilder.ts b/packages/apiclient/src/restRequestBuilder.ts index b9a3d729..76585547 100644 --- a/packages/apiclient/src/restRequestBuilder.ts +++ b/packages/apiclient/src/restRequestBuilder.ts @@ -42,7 +42,11 @@ export class RestRequestBuilder { return this.urlValue; } - constructor(protected apiConnector: IApiConnector, private baseUrl: string, protected params?: RequestInit) { + constructor( + protected apiConnector: IApiConnector, + private baseUrl: string, + protected params?: RequestInit + ) { this.reset(); } @@ -63,7 +67,6 @@ export class RestRequestBuilder { one(path: string, id?: any): this { this.urlValue += "/" + path; if (id !== undefined) { - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions this.urlValue += `/${id}`; } return this; diff --git a/packages/datascreens/src/filteredList.ts b/packages/datascreens/src/filteredList.ts index 379e3e94..6c0de6f1 100644 --- a/packages/datascreens/src/filteredList.ts +++ b/packages/datascreens/src/filteredList.ts @@ -9,7 +9,7 @@ import DataListBase from "./dataListBase"; export default class FilteredList< TEntity, - TFilter extends Record = Record + TFilter extends Record = Record, > extends DataListBase { static defaultPageSize = 30; @@ -40,7 +40,7 @@ export default class FilteredList< constructor( public onLoadData: (filter: TFilter, paging: IPagingFilter) => Awaitable | void>, - private initFilter: () => TFilter = () => ({} as TFilter), + private initFilter: () => TFilter = () => ({}) as TFilter, private defaultPagingFilter: (previous?: Readonly) => IPagingFilter = previous => ({ limit: FilteredList.defaultPageSize, offset: 0, diff --git a/packages/dataviews/src/dataRepeater/index.tsx b/packages/dataviews/src/dataRepeater/index.tsx index 547c91a4..28ec76b1 100644 --- a/packages/dataviews/src/dataRepeater/index.tsx +++ b/packages/dataviews/src/dataRepeater/index.tsx @@ -12,7 +12,7 @@ export interface DataRepeaterProps< THeadCell extends React.ElementType, TBodyWrapper extends React.ElementType, TItemWrapper extends React.ElementType, - TItemCell extends React.ElementType + TItemCell extends React.ElementType, > extends DataTablePropsBase { wrapperType?: TWrapper; wrapperProps?: React.ComponentPropsWithoutRef; @@ -45,7 +45,7 @@ function dataRepeater< THeadCell extends React.ElementType, TBodyWrapper extends React.ElementType, TItemWrapper extends React.ElementType, - TItemCell extends React.ElementType + TItemCell extends React.ElementType, >(props: DataRepeaterProps) { const Wrapper = props.wrapperType ?? "table"; const ItemWrapper = props.bodyWrapperType ?? "tbody"; diff --git a/packages/dataviews/src/dataTypes.ts b/packages/dataviews/src/dataTypes.ts index 4cb5687f..076d7ffd 100644 --- a/packages/dataviews/src/dataTypes.ts +++ b/packages/dataviews/src/dataTypes.ts @@ -16,6 +16,7 @@ export interface ColumnRenderProps> extends ColumnRenderProps { + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents value?: TItem[TProperty] | any; // if we remove any, TS is not able to infer type when multiple columns definitions are defined next to each other :-( item: TItem; } diff --git a/packages/dirtycheck/src/automaticDirtyWatcher.ts b/packages/dirtycheck/src/automaticDirtyWatcher.ts index 9ec954ce..ae0d3662 100644 --- a/packages/dirtycheck/src/automaticDirtyWatcher.ts +++ b/packages/dirtycheck/src/automaticDirtyWatcher.ts @@ -18,7 +18,10 @@ export default class AutomaticDirtyWatcher extends private _results: Readonly, boolean>>>; private _watchedProperties: PropertyName[] = []; - constructor(private target: TEntity, params?: AutomaticDirtyWatcherParams) { + constructor( + private target: TEntity, + params?: AutomaticDirtyWatcherParams + ) { super(params?.isVisible); if (typeof params === "object") { @@ -69,7 +72,6 @@ export default class AutomaticDirtyWatcher extends const propertyName = name as PropertyName; if ( (!this._includedProperties || this._includedProperties.includes(propertyName)) && - // eslint-disable-next-line @typescript-eslint/prefer-optional-chain (!this._excludedProperties || !this._excludedProperties.includes(propertyName)) ) { this._watchedProperties.push(propertyName); diff --git a/packages/generator/src/inversify/index.ts b/packages/generator/src/inversify/index.ts index a457faf2..dfd907dc 100644 --- a/packages/generator/src/inversify/index.ts +++ b/packages/generator/src/inversify/index.ts @@ -92,7 +92,7 @@ export default class IversifyGenerator extends GeneratorBase; tags?: Map; - constructor(name: string, public type: TypeReference) { + constructor( + name: string, + public type: TypeReference + ) { super(name); } diff --git a/packages/generator/src/openapi/models/enum.ts b/packages/generator/src/openapi/models/enum.ts index e265a3eb..77b4e923 100644 --- a/packages/generator/src/openapi/models/enum.ts +++ b/packages/generator/src/openapi/models/enum.ts @@ -1,7 +1,10 @@ import NamedObject from "./namedObject"; export default class Enum extends NamedObject { - constructor(name: string, public items: string[]) { + constructor( + name: string, + public items: string[] + ) { super(name); } } diff --git a/packages/generator/src/openapi/models/externalEntity.ts b/packages/generator/src/openapi/models/externalEntity.ts index 6c4d860a..a9370924 100644 --- a/packages/generator/src/openapi/models/externalEntity.ts +++ b/packages/generator/src/openapi/models/externalEntity.ts @@ -1,7 +1,10 @@ import NamedObject from "./namedObject"; export default class ExternalEntity extends NamedObject { - constructor(name: string, public fullName: string) { + constructor( + name: string, + public fullName: string + ) { super(name); } } diff --git a/packages/generator/src/openapi/models/inheritedEntity.ts b/packages/generator/src/openapi/models/inheritedEntity.ts index 7c14afb1..9105be92 100644 --- a/packages/generator/src/openapi/models/inheritedEntity.ts +++ b/packages/generator/src/openapi/models/inheritedEntity.ts @@ -3,7 +3,11 @@ import ObjectEntity from "./objectEntity"; import type TypeReference from "./typeReference"; export default class InheritedEntity extends ObjectEntity { - constructor(name: string, public baseEntities: TypeReference[], properties: EntityProperty[]) { + constructor( + name: string, + public baseEntities: TypeReference[], + properties: EntityProperty[] + ) { super(name, properties); } } diff --git a/packages/generator/src/openapi/models/objectEntity.ts b/packages/generator/src/openapi/models/objectEntity.ts index 5ab4cca5..0279c513 100644 --- a/packages/generator/src/openapi/models/objectEntity.ts +++ b/packages/generator/src/openapi/models/objectEntity.ts @@ -3,7 +3,10 @@ import NamedObject from "./namedObject"; import type Restriction from "./restriction"; export default class ObjectEntity extends NamedObject { - constructor(name: string, public properties: EntityProperty[]) { + constructor( + name: string, + public properties: EntityProperty[] + ) { super(name); } diff --git a/packages/generator/src/openapi/models/unionEntity.ts b/packages/generator/src/openapi/models/unionEntity.ts index 70f21ee0..8cf17805 100644 --- a/packages/generator/src/openapi/models/unionEntity.ts +++ b/packages/generator/src/openapi/models/unionEntity.ts @@ -2,7 +2,10 @@ import NamedObject from "./namedObject"; import type TypeReference from "./typeReference"; export default class UnionEntity extends NamedObject { - constructor(name: string, public entities: TypeReference[]) { + constructor( + name: string, + public entities: TypeReference[] + ) { super(name); } } diff --git a/packages/generator/src/openapi/parsers/openApi2Parser.ts b/packages/generator/src/openapi/parsers/openApi2Parser.ts index e1b25118..47eb4a80 100644 --- a/packages/generator/src/openapi/parsers/openApi2Parser.ts +++ b/packages/generator/src/openapi/parsers/openApi2Parser.ts @@ -112,7 +112,6 @@ export default class OpenApi2Parser implements ApiModel { } private parseAllOfObject(name: string, definition: OpenAPIV2.SchemaObject) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const subTypes = definition.allOf!; const plainObjects = subTypes.filter( @@ -131,15 +130,14 @@ export default class OpenApi2Parser implements ApiModel { const entity = new InheritedEntity(name, otherParents, properties); - plainObjects.forEach(object => - object.required?.forEach(property => entity.addPropertyRestriction(property, Restriction.required, true)) + plainObjects.forEach( + object => object.required?.forEach(property => entity.addPropertyRestriction(property, Restriction.required, true)) ); return this.setTypeReference(name, entity); } private parseOneOfObject(name: string, definition: OpenAPIV2.SchemaObject) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const subTypes = definition.oneOf!; const innerTypes = subTypes.map((x, i) => this.parseSchemaObject(`${name}Option${i + 1}`, x as OpenAPIV2.SchemaObject | OpenAPIV2.ItemsObject) diff --git a/packages/generator/src/openapi/parsers/openApi3Parser.ts b/packages/generator/src/openapi/parsers/openApi3Parser.ts index 440a4383..e8d109d8 100644 --- a/packages/generator/src/openapi/parsers/openApi3Parser.ts +++ b/packages/generator/src/openapi/parsers/openApi3Parser.ts @@ -20,7 +20,10 @@ export default class OpenApi3Parser implements ApiModel { types = new Map(); endpoints: Endpoint[]; - constructor(private apiDocument: OpenAPIV3.Document, private config?: IApiParserConfig) {} + constructor( + private apiDocument: OpenAPIV3.Document, + private config?: IApiParserConfig + ) {} parse() { if (this.apiDocument.components?.schemas) { @@ -115,7 +118,6 @@ export default class OpenApi3Parser implements ApiModel { } private parseAllOfObject(name: string, definition: OpenAPIV3.SchemaObject) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const subTypes = definition.allOf!; const plainObjects = subTypes.filter( @@ -134,15 +136,14 @@ export default class OpenApi3Parser implements ApiModel { const entity = new InheritedEntity(name, otherParents, properties); - plainObjects.forEach(object => - object.required?.forEach(property => entity.addPropertyRestriction(property, Restriction.required, true)) + plainObjects.forEach( + object => object.required?.forEach(property => entity.addPropertyRestriction(property, Restriction.required, true)) ); return this.setTypeReference(name, entity); } private parseOneOfObject(name: string, definition: OpenAPIV3.SchemaObject) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const subTypes = definition.oneOf!; const innerTypes = subTypes.map((x, i) => this.parseSchemaObject(`${name}Option${i + 1}`, x)); diff --git a/packages/generator/src/openapi/types.ts b/packages/generator/src/openapi/types.ts index 253da63d..7ec45c75 100644 --- a/packages/generator/src/openapi/types.ts +++ b/packages/generator/src/openapi/types.ts @@ -1,6 +1,5 @@ import type { BaseParams } from "../generatorBase"; -// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface IGeneratorParams extends BaseParams {} interface HasExclude { diff --git a/packages/helpers/__tests__/busyWatcher.test.ts b/packages/helpers/__tests__/busyWatcher.test.ts index fb29a3e0..0910971e 100644 --- a/packages/helpers/__tests__/busyWatcher.test.ts +++ b/packages/helpers/__tests__/busyWatcher.test.ts @@ -86,7 +86,6 @@ describe("BusyWatcher", () => { it("clears busy when promise fails", async () => { const watcher = new BusyWatcher(); - // eslint-disable-next-line @typescript-eslint/no-empty-function let handler = () => {}; const promise = new Promise((_resolve, reject) => { handler = reject; diff --git a/packages/helpers/src/path.ts b/packages/helpers/src/path.ts index 1fc9716a..39be885f 100644 --- a/packages/helpers/src/path.ts +++ b/packages/helpers/src/path.ts @@ -112,7 +112,7 @@ export type FieldPathValue + TFieldArrayPath extends FieldArrayPath, > = PathValue; /** @@ -127,7 +127,7 @@ export type FieldArrayPathValue< */ export type FieldPathValues< TFieldValues extends FieldValues, - TPath extends FieldPath[] | readonly FieldPath[] + TPath extends FieldPath[] | readonly FieldPath[], // eslint-disable-next-line @typescript-eslint/ban-types > = {} & { [K in keyof TPath]: FieldPathValue>; diff --git a/packages/helpers/src/types.ts b/packages/helpers/src/types.ts index fb6e0d76..fc1d50a4 100644 --- a/packages/helpers/src/types.ts +++ b/packages/helpers/src/types.ts @@ -26,5 +26,5 @@ export type ExtractTypeRestriction = T extends TypedBindingProperty + TProperty extends TypedBindingProperty, > = TTarget extends Map ? TValue | undefined : TTarget[TProperty] & ExtractTypeRestriction; diff --git a/packages/htmlcontrols/src/controls/checkbox.tsx b/packages/htmlcontrols/src/controls/checkbox.tsx index a9e8d77a..d1104a21 100644 --- a/packages/htmlcontrols/src/controls/checkbox.tsx +++ b/packages/htmlcontrols/src/controls/checkbox.tsx @@ -7,7 +7,7 @@ import React from "react"; export class Checkbox< TRestriction extends boolean | undefined, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, > extends BindingComponent, TRestriction, TTarget, TProperty> { render() { return ( diff --git a/packages/htmlcontrols/src/controls/collectionCheckbox.tsx b/packages/htmlcontrols/src/controls/collectionCheckbox.tsx index 8605700d..7a522c33 100644 --- a/packages/htmlcontrols/src/controls/collectionCheckbox.tsx +++ b/packages/htmlcontrols/src/controls/collectionCheckbox.tsx @@ -13,7 +13,7 @@ function useCollection< TItem, TRestriction extends TItem[] | Set | undefined, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps, TRestriction, TTarget, TProperty>): [boolean, () => void] { const collection = getValue(props.target, props.property); @@ -45,7 +45,7 @@ function collectionCheckbox< TItem, TRestriction extends TItem[] | Set | undefined, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps & ComponentPropsWithoutRef<"input">, TRestriction, TTarget, TProperty>) { const [checked, toggle] = useCollection(props); diff --git a/packages/htmlcontrols/src/controls/textbox.tsx b/packages/htmlcontrols/src/controls/textbox.tsx index 8fbf8815..e4b35f7e 100644 --- a/packages/htmlcontrols/src/controls/textbox.tsx +++ b/packages/htmlcontrols/src/controls/textbox.tsx @@ -8,7 +8,7 @@ import React from "react"; function textbox< TRestriction extends string, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps, TRestriction, TTarget, TProperty>) { const [value, setValue] = useBinding(props); const handleValueChanged = (e: React.ChangeEvent) => setValue(e.target.value as TRestriction); diff --git a/packages/validation/src/asyncEntityValidator.ts b/packages/validation/src/asyncEntityValidator.ts index b6e59079..9705eeee 100644 --- a/packages/validation/src/asyncEntityValidator.ts +++ b/packages/validation/src/asyncEntityValidator.ts @@ -172,7 +172,7 @@ export default class AsyncEntityValidator return [validatorName, debouncedValidation] as [ validatorName: string, - results: (value: unknown, callback: AsyncValidationFunctionCallback) => ValidationResponse + results: (value: unknown, callback: AsyncValidationFunctionCallback) => ValidationResponse, ]; } else { return undefined; diff --git a/packages/validation/src/automaticEntityValidator.ts b/packages/validation/src/automaticEntityValidator.ts index df6cfd06..3308df8d 100644 --- a/packages/validation/src/automaticEntityValidator.ts +++ b/packages/validation/src/automaticEntityValidator.ts @@ -42,7 +42,11 @@ export default class AutomaticEntityValidator exte } getResults(propertyName: PropertyName): ValidationResult[] { - return (this.isEnabled && (get(this._results, propertyName) as ValidationResult[] | undefined)) || emptyResults; + if (!this.isEnabled) { + return emptyResults; + } + + return (get(this._results, propertyName) as ValidationResult[] | undefined) ?? emptyResults; } private buildObservableResults(target: TEntity, entityValidationRules: EntityValidationRules) { diff --git a/packages/validation/src/manualEntityValidator.ts b/packages/validation/src/manualEntityValidator.ts index 5c3c9027..4bb9bd5d 100644 --- a/packages/validation/src/manualEntityValidator.ts +++ b/packages/validation/src/manualEntityValidator.ts @@ -13,7 +13,10 @@ export interface ManualEntityValidatorConfiguration { export default class ManualEntityValidator extends EntityValidatorBase { protected readonly validationResults = observable.map, ValidationResult[]>(); - constructor(isVisible = false, protected configuration: ManualEntityValidatorConfiguration = DefaultConfiguration) { + constructor( + isVisible = false, + protected configuration: ManualEntityValidatorConfiguration = DefaultConfiguration + ) { super(isVisible); makeObservable(this); } @@ -23,7 +26,11 @@ export default class ManualEntityValidator extends EntityValidato } getResults(propertyName: PropertyName): Iterable { - return (this.isEnabled && this.validationResults.get(propertyName)) || emptyResults; + if (!this.isEnabled) { + return emptyResults; + } + + return this.validationResults.get(propertyName) ?? emptyResults; } @action diff --git a/packages/validation/src/serverEntityValidator.ts b/packages/validation/src/serverEntityValidator.ts index a64a0221..5d2170ae 100644 --- a/packages/validation/src/serverEntityValidator.ts +++ b/packages/validation/src/serverEntityValidator.ts @@ -8,7 +8,10 @@ import type { ValidationResult } from "./types"; export default class ServerEntityValidator extends ManualEntityValidator { private _validatedValues = observable.map(undefined, { deep: false }); - constructor(private target: TEntity, configuration?: ManualEntityValidatorConfiguration) { + constructor( + private target: TEntity, + configuration?: ManualEntityValidatorConfiguration + ) { super(true, configuration); makeObservable(this); } @@ -27,7 +30,11 @@ export default class ServerEntityValidator extends } getResults(propertyName: PropertyName): ValidationResult[] { - return (this.isEnabled && this.isPropertyValueSame(propertyName) && this.validationResults.get(propertyName)) || emptyResults; + if (!this.isEnabled || !this.isPropertyValueSame(propertyName)) { + return emptyResults; + } + + return this.validationResults.get(propertyName) ?? emptyResults; } @action diff --git a/packages/views/__tests__/bindingComponent.test.ts b/packages/views/__tests__/bindingComponent.test.ts index 3a0dbe4d..6c1f0bd7 100644 --- a/packages/views/__tests__/bindingComponent.test.ts +++ b/packages/views/__tests__/bindingComponent.test.ts @@ -27,7 +27,7 @@ class ComplexEntity { class TestControl< TRestriction extends string | undefined, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, > extends BindingComponent { readValue() { return this.value; diff --git a/packages/views/__tests__/bindingProps.test.ts b/packages/views/__tests__/bindingProps.test.ts index 2a342caa..70fddee1 100644 --- a/packages/views/__tests__/bindingProps.test.ts +++ b/packages/views/__tests__/bindingProps.test.ts @@ -19,7 +19,7 @@ interface MyProps { function numbersComponent< TRestriction extends number[], TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps) { if (props.property && props.target) { props.onValueChanged?.([99] as PropertyType, props.property, props.target); @@ -41,7 +41,7 @@ function numbersComponent< function textComponent< TRestriction extends string, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps) { const [value, setValue] = useBinding(props); setValue(value); @@ -52,7 +52,7 @@ function textComponent< function nullableComponent< TRestriction extends string | undefined, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps) { const [value, setValue] = useBinding(props); setValue(value); @@ -63,7 +63,7 @@ function nullableComponent< function parentComponent< TRestriction extends Parent[], TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps) { const [value, setValue] = useBinding(props); setValue(value); @@ -124,5 +124,4 @@ describe("BindingProps", () => { }); }); -// eslint-disable-next-line @typescript-eslint/no-empty-function function sink(_input: T) {} diff --git a/packages/views/src/binding/bindingComponent.tsx b/packages/views/src/binding/bindingComponent.tsx index 8ec3b673..121ffa5c 100644 --- a/packages/views/src/binding/bindingComponent.tsx +++ b/packages/views/src/binding/bindingComponent.tsx @@ -25,7 +25,7 @@ export abstract class BindingComponent< TProps, TBindingTypeRestriction, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, > extends React.Component> { constructor(props: WithBindingProps) { super(props); diff --git a/packages/views/src/binding/bindingProps.ts b/packages/views/src/binding/bindingProps.ts index 4293abc0..1541e12e 100644 --- a/packages/views/src/binding/bindingProps.ts +++ b/packages/views/src/binding/bindingProps.ts @@ -12,7 +12,7 @@ import type { BindingTarget, PropertyType, TypedBindingProperty } from "@frui.ts export interface IBindingProps< TTypeRestriction, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, > { /** Target entity for the binding. The entity should be Mobx `observable`. */ target?: TTarget; @@ -36,7 +36,7 @@ export type WithBindingProps< T, TTypeRestriction, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, > = IBindingProps & Omit>; export function omitBindingProps(props: T): ExcludeBindingProps { diff --git a/packages/views/src/binding/useBinding.tsx b/packages/views/src/binding/useBinding.tsx index 2c98559a..2eb96746 100644 --- a/packages/views/src/binding/useBinding.tsx +++ b/packages/views/src/binding/useBinding.tsx @@ -6,15 +6,14 @@ import type { IBindingProps } from "./bindingProps"; export function getValue< TValueRestriction, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(target: TTarget | undefined, property: TProperty | undefined, ensureObservable = true): TValueRestriction { if (!target) { - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions throw new Error(`Cannot read property '${property}', because target has not been set`); } if (property === undefined) { - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - throw new Error(`'property' prop has not been set for target '${target}'`); + // eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions + throw new Error(`'property' prop has not been set for target '${target}'`, { cause: { target, property } }); } if (isObservableMap(target)) { @@ -24,7 +23,7 @@ export function getValue< if (!isObservable(target) || !isObservableProp(target, property)) { if (isMap>(target)) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-non-null-assertion + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return target.get(property)!; } else { const value = target[property as keyof TTarget]; @@ -44,7 +43,7 @@ export function getValue< export function setValue< TValueRestriction, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(target: TTarget | undefined, property: TProperty | undefined, value: PropertyType) { if (target && property) { action(ensureObservableProperty)(target, property, value); @@ -54,7 +53,7 @@ export function setValue< export function useBinding< TValueRestriction, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: IBindingProps) { const value = getValue(props.target, props.property); const setter = (value: TValueRestriction) => { diff --git a/packages/views/src/hooks/useViewModel.ts b/packages/views/src/hooks/useViewModel.ts index 7126f2af..eae4d76c 100644 --- a/packages/views/src/hooks/useViewModel.ts +++ b/packages/views/src/hooks/useViewModel.ts @@ -24,9 +24,12 @@ export function useViewModel>( }; }, []); - useEffect(() => { - void vmManager.current.navigate(currentContext.current); - }, dependencies ?? [context]); + useEffect( + () => { + void vmManager.current.navigate(currentContext.current); + }, + dependencies ?? [context] + ); return { vm: vmManager.current.instance, initialized }; } diff --git a/packages/views/src/router/router.tsx b/packages/views/src/router/router.tsx index 890737c4..eadc927f 100644 --- a/packages/views/src/router/router.tsx +++ b/packages/views/src/router/router.tsx @@ -41,7 +41,7 @@ function buildViewModelOptions< // TRouterContext extends AnyContext = AnyContext, // TChildren = unknown, // TRoutesInfo extends DefaultRoutesInfo = DefaultRoutesInfo, - TViewModel extends IRouteViewModel = IRouteViewModel + TViewModel extends IRouteViewModel = IRouteViewModel, >(vmFactory: () => TViewModel) { const vmManager = new ViewModelLifecycleManager, TViewModel>(vmFactory); @@ -118,7 +118,7 @@ export function buildRoute< // TRouterContext extends AnyContext = AnyContext, // TChildren = unknown, // TRoutesInfo extends DefaultRoutesInfo = DefaultRoutesInfo, - TViewModel extends IRouteViewModel = IRouteViewModel + TViewModel extends IRouteViewModel = IRouteViewModel, >( vmFactory: () => TViewModel, options: RouteOptions< @@ -146,7 +146,7 @@ export function buildRootRoute< TSearchSchema extends AnySearchSchema = {}, TContext extends RouteContext = RouteContext, TRouterContext extends RouterContext = RouterContext, - TViewModel extends IRouteViewModel = IRouteViewModel + TViewModel extends IRouteViewModel = IRouteViewModel, >( vmFactory: () => TViewModel, options: Omit< diff --git a/packages/views/src/types.ts b/packages/views/src/types.ts index f2daa84e..c0f50728 100644 --- a/packages/views/src/types.ts +++ b/packages/views/src/types.ts @@ -1,3 +1,4 @@ +import type { Awaitable } from "@frui.ts/helpers"; import type React from "react"; export interface ISelectItem { @@ -9,11 +10,11 @@ export type ViewProps = { vm: TViewModel }; export type ViewComponent = React.FunctionComponent>; export interface IViewModel { - onInitialize?(context: TContext): Promise | unknown; - onActivate?(context: TContext): Promise | unknown; - onNavigate?(context: TContext): Promise | unknown; - onSearchChanged?(context: TContext): Promise | unknown; - onDeactivate?(context: TContext): Promise | unknown; + onInitialize?(context: TContext): Awaitable; + onActivate?(context: TContext): Awaitable; + onNavigate?(context: TContext): Awaitable; + onSearchChanged?(context: TContext): Awaitable; + onDeactivate?(context: TContext): Awaitable; isVm?: true; } diff --git a/stories/src/fields/Check.tsx b/stories/src/fields/Check.tsx index d18a32b3..8434162b 100644 --- a/stories/src/fields/Check.tsx +++ b/stories/src/fields/Check.tsx @@ -7,7 +7,7 @@ import React from "react"; function check< TRestriction extends boolean | undefined, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps<{ id: string; label: string }, TRestriction, TTarget, TProperty>) { const { label, ...rest } = props; return ( diff --git a/stories/src/fields/Input.tsx b/stories/src/fields/Input.tsx index da2b4c6b..69bac948 100644 --- a/stories/src/fields/Input.tsx +++ b/stories/src/fields/Input.tsx @@ -7,7 +7,7 @@ import React from "react"; function input< TRestriction extends string | undefined, TTarget extends BindingTarget, - TProperty extends TypedBindingProperty + TProperty extends TypedBindingProperty, >(props: WithBindingProps<{ label?: string }, TRestriction, TTarget, TProperty>) { const { label, ...rest } = props; return (