From 29f3e41fa3020b75e565d6e494b097c218508214 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 29 Dec 2021 09:51:04 -0800 Subject: [PATCH] Configure typescript --- .../src/components/export/TxtExporter.ts | 4 +-- ...ModelFactory.js => FeatureModelFactory.ts} | 31 ++++++++----------- .../test/unit/TxTExportTestSuite.test.ts | 2 +- packages/mindplot/tsconfig.json | 1 + 4 files changed, 17 insertions(+), 21 deletions(-) rename packages/mindplot/src/components/model/{FeatureModelFactory.js => FeatureModelFactory.ts} (60%) diff --git a/packages/mindplot/src/components/export/TxtExporter.ts b/packages/mindplot/src/components/export/TxtExporter.ts index 144b510e..2b45e548 100644 --- a/packages/mindplot/src/components/export/TxtExporter.ts +++ b/packages/mindplot/src/components/export/TxtExporter.ts @@ -1,5 +1,5 @@ -import Exporter from "src/components/export/Exporter"; -import Mindmap from "src/components/model/Mindmap"; +import Exporter from "./Exporter"; +import Mindmap from "../model/Mindmap"; class TextExporter implements Exporter { diff --git a/packages/mindplot/src/components/model/FeatureModelFactory.js b/packages/mindplot/src/components/model/FeatureModelFactory.ts similarity index 60% rename from packages/mindplot/src/components/model/FeatureModelFactory.js rename to packages/mindplot/src/components/model/FeatureModelFactory.ts index 125ab9ac..8f871c09 100644 --- a/packages/mindplot/src/components/model/FeatureModelFactory.js +++ b/packages/mindplot/src/components/model/FeatureModelFactory.ts @@ -2,41 +2,36 @@ import { $assert } from '@wisemapping/core-js'; import IconModel from './IconModel'; import LinkModel from './LinkModel'; import NoteModel from './NoteModel'; +import FeatureModel from './FeatureModel'; -const FeatureModelFactory = { - Icon: { +class FeatureModelFactory { + + private static modelById = [{ id: IconModel.FEATURE_TYPE, model: IconModel, - }, - - Link: { + }, { id: LinkModel.FEATURE_TYPE, model: LinkModel, - }, - - /** the note object */ - Note: { + }, { id: NoteModel.FEATURE_TYPE, model: NoteModel, - }, + }] as const; - createModel(type, attributes) { + static createModel(type: string, attributes): FeatureModel { $assert(type, 'type can not be null'); $assert(attributes, 'attributes can not be null'); - const { model: Model } = FeatureModelFactory._featuresMetadataById + const { model: Model } = FeatureModelFactory.modelById .filter((elem) => elem.id === type)[0]; return new Model(attributes); - }, + } /** * @param id the feature metadata id * @return {Boolean} returns true if the given id is contained in the metadata array */ - isSupported(id) { - return FeatureModelFactory._featuresMetadataById.some((elem) => elem.id === id); - }, + static isSupported(type: string): boolean { + return FeatureModelFactory.modelById.some((elem) => elem.id === type); + } }; -FeatureModelFactory._featuresMetadataById = [FeatureModelFactory.Icon, FeatureModelFactory.Link, FeatureModelFactory.Note]; - export default FeatureModelFactory; diff --git a/packages/mindplot/test/unit/TxTExportTestSuite.test.ts b/packages/mindplot/test/unit/TxTExportTestSuite.test.ts index ddc3b461..1a17bfe5 100644 --- a/packages/mindplot/test/unit/TxTExportTestSuite.test.ts +++ b/packages/mindplot/test/unit/TxTExportTestSuite.test.ts @@ -2,7 +2,7 @@ import TxtExporter from '../../src/components/export/TxtExporter'; import Mindmap from '../../src/components/model/Mindmap'; test('adds 1 + 2 to equal 3', () => { - const m = new Mindmap(); + const m = new Mindmap(1); const exporter = new TxtExporter(); console.log(exporter.export(m)); diff --git a/packages/mindplot/tsconfig.json b/packages/mindplot/tsconfig.json index efef29bd..71cc099f 100644 --- a/packages/mindplot/tsconfig.json +++ b/packages/mindplot/tsconfig.json @@ -4,6 +4,7 @@ "sourceMap": true, "noImplicitAny": false, "module": "es6", + "moduleResolution": "Node", "target": "es6", "allowJs": true, "esModuleInterop": true