Skip to content

Commit

Permalink
mvc.View: specify SVGElement/HTMLElement type of property el; Vectori…
Browse files Browse the repository at this point in the history
…zer/null type of property vel (#1527)
  • Loading branch information
kumilingus authored Sep 16, 2021
1 parent 92e63d0 commit 19cf86a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion grunt/config/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
noImplicitThis: true,
strictNullChecks: false,
suppressImplicitAnyIndexErrors: true,
noUnusedLocals: true
noUnusedLocals: false
}
}
};
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"lodash": "~4.17.21"
},
"devDependencies": {
"@types/backbone": "~1.4.10",
"@types/backbone": "~1.4.13",
"@types/jquery": "~3.5.5",
"@types/lodash": "~4.14.170",
"@types/dagre": "~0.7.44",
Expand Down
13 changes: 12 additions & 1 deletion test/ts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Typescript sanity check
type AssertExtends<A,B> = A extends B ? true : never;

import * as joint from '../../build/joint';

const graph = new joint.dia.Graph;
Expand Down Expand Up @@ -37,3 +38,13 @@ const cylinder = new joint.shapes.standard.Cylinder({ z: 0 });
cylinder.set({ position: { x: 4, y: 5 }});
cylinder.set('z', cylinder.attributes.z + 1);

const paper = new joint.dia.Paper({
model: graph,
frozen: true
});

const cellView = cell.findView(paper);
cellView.vel.addClass('test-class');

let isHTMLView: AssertExtends<typeof paper.vel, null> = true;
let isSVGView: AssertExtends<typeof cellView.vel, joint.Vectorizer> = true;
29 changes: 14 additions & 15 deletions types/joint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ export namespace dia {
ELEMENT_AVAILABILITY = 'elementAvailability'
}

interface Options<T extends Cell> extends mvc.ViewOptions<T> {
interface Options<T extends Cell> extends mvc.ViewOptions<T, SVGElement> {
id?: string
}

Expand All @@ -632,7 +632,7 @@ export namespace dia {
}
}

abstract class CellViewGeneric<T extends Cell> extends mvc.View<T> {
abstract class CellViewGeneric<T extends Cell> extends mvc.View<T, SVGElement> {

constructor(opt?: CellView.Options<T>);

Expand Down Expand Up @@ -871,7 +871,7 @@ export namespace dia {

}

interface Options extends mvc.ViewOptions<Link> {
interface Options extends mvc.ViewOptions<Link, SVGElement> {
shortLinkLength?: number,
doubleLinkTools?: boolean,
longLinkLength?: number,
Expand Down Expand Up @@ -1472,15 +1472,15 @@ export namespace dia {

namespace ToolsView {

interface Options extends mvc.ViewOptions<undefined> {
interface Options extends mvc.ViewOptions<undefined, SVGElement> {
tools?: dia.ToolView[];
name?: string | null;
relatedView?: dia.CellView;
component?: boolean;
}
}

class ToolsView extends mvc.View<undefined> {
class ToolsView extends mvc.View<undefined, SVGElement> {

constructor(opt?: ToolsView.Options);

Expand All @@ -1506,13 +1506,12 @@ export namespace dia {
}

namespace ToolView {

interface Options {
interface Options extends mvc.ViewOptions<undefined, SVGElement> {
focusOpacity?: number;
}
}

class ToolView extends mvc.View<undefined> {
class ToolView extends mvc.View<undefined, SVGElement> {

name: string | null;
parentView: ToolsView;
Expand Down Expand Up @@ -1551,12 +1550,12 @@ export namespace dia {

type NodeSelector = string | SVGElement | NodeSelectorJSON;

interface Options extends mvc.ViewOptions<undefined> {
interface Options extends mvc.ViewOptions<undefined, SVGElement> {
layer?: dia.Paper.Layers | string | null;
}
}

class HighlighterView<Options = HighlighterView.Options> extends mvc.View<undefined> {
class HighlighterView<Options = HighlighterView.Options> extends mvc.View<undefined, SVGElement> {

constructor(options?: Options);

Expand Down Expand Up @@ -2897,28 +2896,28 @@ export namespace layout {

export namespace mvc {

interface ViewOptions<T extends Backbone.Model> extends Backbone.ViewOptions<T> {
interface ViewOptions<T extends Backbone.Model, E extends Element = HTMLElement> extends Backbone.ViewOptions<T, E> {
theme?: string;
}

interface viewEventData {
[key: string]: any;
}

class View<T extends Backbone.Model> extends Backbone.View<T> {
class View<T extends Backbone.Model, E extends Element = HTMLElement> extends Backbone.View<T, E> {

constructor(opt?: ViewOptions<T>);
constructor(opt?: ViewOptions<T, E>);

UPDATE_PRIORITY: number;
DETACHABLE: boolean;
FLAG_INSERT: number;
FLAG_REMOVE: number;

vel: Vectorizer | null;
vel: E extends HTMLElement ? null : Vectorizer;

svgElement: boolean;

options: ViewOptions<T>;
options: ViewOptions<T, E>;

theme: string;

Expand Down

0 comments on commit 19cf86a

Please sign in to comment.