Browse Source

Replace types with interfaces

pull/6359/head
mohamedsalem401 1 year ago
parent
commit
d4fe2c3e51
  1. 23
      packages/core/src/data_sources/model/collection_component/types.ts
  2. 2
      packages/core/src/dom_components/index.ts
  3. 14
      packages/core/src/dom_components/model/Component.ts

23
packages/core/src/data_sources/model/collection_component/types.ts

@ -4,12 +4,13 @@ import { ComponentDefinition } from '../../../dom_components/model/types';
import { CollectionVariableDefinition } from '../../../../test/specs/dom_components/model/ComponentTypes'; import { CollectionVariableDefinition } from '../../../../test/specs/dom_components/model/ComponentTypes';
import { DataVariableDefinition } from '../DataVariable'; import { DataVariableDefinition } from '../DataVariable';
type CollectionDataSource = any[] | DataVariableDefinition | CollectionVariableDefinition; export type CollectionDataSource = any[] | DataVariableDefinition | CollectionVariableDefinition;
type CollectionConfig = {
export interface CollectionConfig {
startIndex?: number; startIndex?: number;
endIndex?: number; endIndex?: number;
dataSource: CollectionDataSource; dataSource: CollectionDataSource;
}; }
export enum CollectionStateVariableType { export enum CollectionStateVariableType {
currentIndex = 'currentIndex', currentIndex = 'currentIndex',
@ -21,7 +22,7 @@ export enum CollectionStateVariableType {
remainingItems = 'remainingItems', remainingItems = 'remainingItems',
} }
export type CollectionState = { export interface CollectionState {
[CollectionStateVariableType.currentIndex]: number; [CollectionStateVariableType.currentIndex]: number;
[CollectionStateVariableType.startIndex]: number; [CollectionStateVariableType.startIndex]: number;
[CollectionStateVariableType.currentItem]: any; [CollectionStateVariableType.currentItem]: any;
@ -29,19 +30,19 @@ export type CollectionState = {
[CollectionStateVariableType.collectionName]?: string; [CollectionStateVariableType.collectionName]?: string;
[CollectionStateVariableType.totalItems]: number; [CollectionStateVariableType.totalItems]: number;
[CollectionStateVariableType.remainingItems]: number; [CollectionStateVariableType.remainingItems]: number;
}; }
export type CollectionsStateMap = { export interface CollectionsStateMap {
[key: string]: CollectionState; [key: string]: CollectionState;
}; }
export type CollectionComponentDefinition = { export interface CollectionComponentDefinition extends ComponentDefinition {
[keyCollectionDefinition]: CollectionDefinition; [keyCollectionDefinition]: CollectionDefinition;
} & ComponentDefinition; }
export type CollectionDefinition = { export interface CollectionDefinition {
type: typeof CollectionComponentType; type: typeof CollectionComponentType;
collectionName?: string; collectionName?: string;
config: CollectionConfig; config: CollectionConfig;
block: ComponentDefinition; block: ComponentDefinition;
}; }

2
packages/core/src/dom_components/index.ts

@ -130,7 +130,7 @@ import ComponentConditionalVariable from '../data_sources/model/conditional_vari
import ConditionalComponentView from '../data_sources/view/ComponentDynamicView'; import ConditionalComponentView from '../data_sources/view/ComponentDynamicView';
import CollectionComponent from '../data_sources/model/collection_component/CollectionComponent'; import CollectionComponent from '../data_sources/model/collection_component/CollectionComponent';
import CollectionComponentView from '../data_sources/model/collection_component/CollectionComponentView'; import CollectionComponentView from '../data_sources/model/collection_component/CollectionComponentView';
import { CollectionComponentType } from "../data_sources/model/collection_component/constants"; import { CollectionComponentType } from '../data_sources/model/collection_component/constants';
export type ComponentEvent = export type ComponentEvent =
| 'component:create' | 'component:create'

14
packages/core/src/dom_components/model/Component.ts

@ -56,9 +56,9 @@ import {
import { ComponentDynamicValueWatcher } from './ComponentDynamicValueWatcher'; import { ComponentDynamicValueWatcher } from './ComponentDynamicValueWatcher';
import { DynamicWatchersOptions } from './DynamicValueWatcher'; import { DynamicWatchersOptions } from './DynamicValueWatcher';
export interface IComponent extends ExtractMethods<Component> { } export interface IComponent extends ExtractMethods<Component> {}
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DynamicWatchersOptions { } export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DynamicWatchersOptions {}
export interface ComponentSetOptions extends SetOptions, DynamicWatchersOptions { } export interface ComponentSetOptions extends SetOptions, DynamicWatchersOptions {}
const escapeRegExp = (str: string) => { const escapeRegExp = (str: string) => {
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
@ -229,12 +229,12 @@ export default class Component extends StyleableModel<ComponentProperties> {
return this.frame?.getPage(); return this.frame?.getPage();
} }
preInit() { } preInit() {}
/** /**
* Hook method, called once the model is created * Hook method, called once the model is created
*/ */
init() { } init() {}
/** /**
* Hook method, called when the model has been updated (eg. updated some model's property) * Hook method, called when the model has been updated (eg. updated some model's property)
@ -242,12 +242,12 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @param {*} value Property value, if triggered after some property update * @param {*} value Property value, if triggered after some property update
* @param {*} previous Property previous value, if triggered after some property update * @param {*} previous Property previous value, if triggered after some property update
*/ */
updated(property: string, value: any, previous: any) { } updated(property: string, value: any, previous: any) {}
/** /**
* Hook method, called once the model has been removed * Hook method, called once the model has been removed
*/ */
removed() { } removed() {}
em!: EditorModel; em!: EditorModel;
opt!: ComponentOptions; opt!: ComponentOptions;

Loading…
Cancel
Save