-
Notifications
You must be signed in to change notification settings - Fork 52
New major version proposal #81
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
Conversation
Use js class, static methods and protected methods for recurring functions.
|
Wow, this is a very invasive change! There are so many changes here, it will take me some time to review it all and consider the consequences of each one. I would prefer smaller isolated PRs that make individual changes so that each one can be considered and evaluated individually. For example, each of the following could be done as separate PRs:
One thing that also comes to mind is that if we go ahead with such invasive changes that require a major version bump, let's tackle #18! Ideally the graph functions would not be all in one monolithic import, but rather separate modules that could be imported and used. The migration to a class-based approach is a huge step in that direction. Perhaps we could adopt a pattern where users of the library can import functions and then bind them to the class somehow? Or maybe they could be functions where the In summary, I may ultimately merge in this PR, but I first need to do a thorough review of all the changes, which will take some time. I'm heading out on a trip now and will be back in July. If you'd like to get changes in sooner, please make smaller PRs. Thanks so much for your contribution! |
hi @curran I didn't expect you to merge this right away 😄 but those are the changes I'm going to need to go forward in one of my project, so I thought I would share them. Note that the breaking changes are clearly identified and contained. It will be easy for users to migrate.
I could have done separate PRs, but that would have induced substantially more work, especially for the TypeScript side of it.
This PR does not go in the right direction for #18 . Tree-shaking is not possible when using classes. We would have import { GraphData, topologicalSort } from 'graph-data-structure';
const graphData = GraphData.deserialize(data);
const sortedNodes = topologicalSort(graphData);This structure would allow tree-shaking, only the imported classes and functions would be included in the app's bundle. |
|
@curran Now you have composition ;) |
findNodes, getNode, getFirstNode
…, getNode, getFirstNode
… to target specific sub-graph or cycles.
… graph traversal
|
@curran have you had some time to review this ? |
|
Oh yeah thank you so much for this! It's been on the back burner, but I really like all the changes here. I'll see if I can put some time into a final review and launch this as the next major revision. |
curran
left a comment
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.
Looks truly fantastic! Thank you so much.
| "prettier": "3.1.0", | ||
| "release-it": "17.0.0", | ||
| "rollup": "4.18.0", | ||
| "rollup-plugin-ts": "3.4.5", |
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.
Maybe we could use Vite as the build system?
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.
AFAIK Vite uses esbuild, which does not support UMD.
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 got it to generate UMD the other day. Here's an example:
https://github.com/curran/d3-rosetta/blob/main/vite.config.js
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 didn't take the time to look into this. Can you give it a shot after 4.0.0 ?
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.
Indeed!
| ? [weight?: EdgeWeight] | ||
| : [weight: EdgeWeight | undefined, linkProps: LinkProps] | ||
| ): this { | ||
| const [weight, linkProps] = opts; |
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.
Using an array here feels strange. Perhaps make it an options object so there's no confusion on ordering? That also would cleanly handle the optionality of linkProps.
| const [weight, linkProps] = opts; | |
| const {weight, linkProps} = opts; |
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.
An option object would definitely be better ; I tried to minimize the breaking changes.
If we change the signature of this function, it will break a lot of projects.
I suggest we offer two signatures :
addEdge(source: Node, target: Node, weight: number): this;
addEdge(source: Node, target: Node, options: { weight?: number; linkProps: LinkProps }): this;WDYT ?
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.
@curran you've merged the PR but I've not heard your opinion on 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.
Ah yes I do like the idea of two signatures. Thanks!
|
OK I took the leap and merged this! All we need to do now is fix some last type errors |
Can you point those type errors ? |
New major version proposal
Breaking changes :
Graphis now a class, so it is instantiated withnew Graph()instead ofGraph().Graph.adjacent()now returns aSet<Node>orundefinedif the node is not found.Graph.nodes()is no longer available. A propertynodes: Set<Node>is now exposed.Graph.serialize()is no longer available. A standalone functionserializeGraphis available instead.Graph.deserialize()is no longer available. A standalone functiondeserializeGraphis available instead.Graph.hasCycle()is no longer available. A standalone functionhasCycleis available instead.graph.topologicalSort()are no longer available. A standalone function is available for each of them.shortestPathalgorithm now returns an object{ nodes: Node[], weight: number }instead of an augmented array.Internal changes :
MapandSetare used instead of records and arrays. Closes Use ES6 Map and Set where appropriate #27idproperty.vitestin order to be able to write tests in TypeScript without troubles..d.ctsand.d.mtsdeclaration files are now distributed.Features :
getNode,getFirstNode,findNodesto help you retrieve node references when they are objects.depthFirstSearchnow accepts a functionshouldFollowas an option, to conditionally follow an edge.Graphnow accept 2 generics to define the type of the nodes and edge properties.deserializeGraph()and the serialization type carries the types with it.Migration
Serialization
Algorithms