Configure typescript

This commit is contained in:
Paulo Gustavo Veiga 2021-12-29 09:51:04 -08:00
parent ef3984cfd0
commit 29f3e41fa3
4 changed files with 17 additions and 21 deletions

View File

@ -1,5 +1,5 @@
import Exporter from "src/components/export/Exporter"; import Exporter from "./Exporter";
import Mindmap from "src/components/model/Mindmap"; import Mindmap from "../model/Mindmap";
class TextExporter implements Exporter { class TextExporter implements Exporter {

View File

@ -2,41 +2,36 @@ import { $assert } from '@wisemapping/core-js';
import IconModel from './IconModel'; import IconModel from './IconModel';
import LinkModel from './LinkModel'; import LinkModel from './LinkModel';
import NoteModel from './NoteModel'; import NoteModel from './NoteModel';
import FeatureModel from './FeatureModel';
const FeatureModelFactory = { class FeatureModelFactory {
Icon: {
private static modelById = [{
id: IconModel.FEATURE_TYPE, id: IconModel.FEATURE_TYPE,
model: IconModel, model: IconModel,
}, }, {
Link: {
id: LinkModel.FEATURE_TYPE, id: LinkModel.FEATURE_TYPE,
model: LinkModel, model: LinkModel,
}, }, {
/** the note object */
Note: {
id: NoteModel.FEATURE_TYPE, id: NoteModel.FEATURE_TYPE,
model: NoteModel, model: NoteModel,
}, }] as const;
createModel(type, attributes) { static createModel(type: string, attributes): FeatureModel {
$assert(type, 'type can not be null'); $assert(type, 'type can not be null');
$assert(attributes, 'attributes 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]; .filter((elem) => elem.id === type)[0];
return new Model(attributes); return new Model(attributes);
}, }
/** /**
* @param id the feature metadata id * @param id the feature metadata id
* @return {Boolean} returns true if the given id is contained in the metadata array * @return {Boolean} returns true if the given id is contained in the metadata array
*/ */
isSupported(id) { static isSupported(type: string): boolean {
return FeatureModelFactory._featuresMetadataById.some((elem) => elem.id === id); return FeatureModelFactory.modelById.some((elem) => elem.id === type);
}, }
}; };
FeatureModelFactory._featuresMetadataById = [FeatureModelFactory.Icon, FeatureModelFactory.Link, FeatureModelFactory.Note];
export default FeatureModelFactory; export default FeatureModelFactory;

View File

@ -2,7 +2,7 @@ import TxtExporter from '../../src/components/export/TxtExporter';
import Mindmap from '../../src/components/model/Mindmap'; import Mindmap from '../../src/components/model/Mindmap';
test('adds 1 + 2 to equal 3', () => { test('adds 1 + 2 to equal 3', () => {
const m = new Mindmap(); const m = new Mindmap(1);
const exporter = new TxtExporter(); const exporter = new TxtExporter();
console.log(exporter.export(m)); console.log(exporter.export(m));

View File

@ -4,6 +4,7 @@
"sourceMap": true, "sourceMap": true,
"noImplicitAny": false, "noImplicitAny": false,
"module": "es6", "module": "es6",
"moduleResolution": "Node",
"target": "es6", "target": "es6",
"allowJs": true, "allowJs": true,
"esModuleInterop": true "esModuleInterop": true