-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add first-party Typescript support #3308
base: unstable
Are you sure you want to change the base?
Conversation
@d2fong, since you have a lot of TS experience I've added you as a reviewer to this PR. Since this is an update of the already-working community definition file, I don't expect any major issues -- but please let us know if you notice any red flags or best practices that aren't being followed. Thanks |
@mikekucera, I've cleaned up the commits for this PR so your WebGL API is in a separate commit (3a9c3a1). Let me know if you notice any discrepancies, or if you plan to change the API before the release. Thanks |
Hi Max, I'd love to give this a proper review, but that might take some time since its a big file and I'm new to TypeScript. Are you ok with waiting for a review from me? |
Sounds good |
@@ -2033,6 +2058,8 @@ declare namespace cytoscape { | |||
includeTargetLabels?: boolean | undefined; | |||
/** A boolean indicating whether to include overlays (such as the one which appears when a node is clicked) in the bounding box (default true). */ | |||
includeOverlays?: boolean | undefined; | |||
/** A boolean indicating whether to include underlays in the bounding box (default: true). */ | |||
includeUnderlays?: boolean | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a minor style nitpick -- when you have optional properties, the general style convention is that you don't need to include the | undefined
part. I noticed that some lines in this community file follow that convention and some don't.
@maxkfranz I reviewed the specific commits that include your additions to the community ts file. I don't see anything that looks out of place. How would you recommend that I test this out? If I install this branch in cytoscape-web, does this mean we shouldn't need to use the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I skimmed the file and made some minor comments. The file is quite large and I'm new to TypeScript so I can't really comment on if the overall structure of all the type definitions are correct. My recommendation is to somehow mark the entire file as provisional so that we can fix any problems when the community finds them. We don't want to be locked into an API like we are with Cytoscape Java, at least until this file gets a decent amount of use from the community.
* The input must be a single edge. | ||
* | ||
* For a output of a function it will always give: | ||
* - Cy.CollectionElements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Cy.Elements? I don't see Cy.CollectionElements anywhere else in this file.
/** | ||
* The [[Stylesheet]] used to style the graph. For convenience, this option can alternatively be specified as a promise that resolves to the stylesheet. | ||
*/ | ||
style?: Stylesheet[] | Promise<Stylesheet[]> | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style property is an array of StyleSheets? This naming seems a bit strange.
For example:
style: [
{ selector: "node",
style: {
width: 20,
height: 20
}
},
{ selector: "edge",
style: {
"curve-style": "unbundled-bezier",
"control-point-weight": 0.5,
"control-point-distance": 20
}
},
],
According to this type definition each object in the array has type Stylesheet. Is that right? Don't we think of the entire array as a Stylesheet? With each element being a style definition or style block.
* The batch size for WebGL. | ||
* (provisional, may change in future releases) | ||
*/ | ||
webglBatchSize?: number | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ also needs a warning
* | ||
* @param name The name of the field to get. | ||
*/ | ||
data(name?: string): any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are declarations for ElementDataDefinition, NodeDataDefinition, EdgeDataDefinition above. Should they be used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also 'data' can't contain values that are non-serializable right? Shouldn't that be captured in the type? The 'any' type seems way too permissive. That's what scratch is for.
* @param name The name of the field to set. | ||
* @param value The value to set for the field. | ||
*/ | ||
data(name: string, value: any): this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value argument can't be any, it has to be serializable Json data right?
* Get the element's plain JavaScript object representation. | ||
* http://js.cytoscape.org/#ele.json | ||
*/ | ||
json(): string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not return a string, it returns a JSON object.
Cross-references to related issues. If there is no existing issue that describes your bug or feature request, then create an issue before making your pull request.
Associated issues:
Notes re. the content of the pull request. Give context to reviewers or serve as a general record of the changes made. Add a screenshot or video to demonstrate your new feature, if possible.
import cytoscape
will use the latest definition file.Checklist
Author:
unstable
. Bug-fix patches can go on eitherunstable
ormaster
.Reviewers:
master
branch and theunstable
branch. Normally, this just requires cherry-picking the corresponding merge commit frommaster
tounstable
-- or vice versa.