Skip to content

Conversation

@dopry
Copy link

@dopry dopry commented May 31, 2025

This is a pseudo code to illustrate the concept. I'm not very good with JSDoc these days. I personally find it easier just to work with typescript so TSC and VS code do all the heavy lifting to generate my types.

This implementation refactors Input and Output with a base class of Port.

applies to #229

@dopry dopry force-pushed the fix/Input-Output-Polymorphism branch from ad94c84 to e7b6942 Compare May 31, 2025 00:39
@djipco djipco self-assigned this Jun 1, 2025
src/Port.js Outdated
import { WebMidi } from "./WebMidi.js";

/**
* The `Input` class represents a single MIDI input port. This object is automatically instantiated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation seems to have been copied from Input. Needs to be adjusted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the documentation. I also hoisted common property declarations from the constructor to the class and added the private prefix, '#' to _port.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the # I'd need to change the eslint config to support it and it's ES2022. I don't want to dig into the bable config to figure out if it would transpile it down, so sticking to the approach that avoids changing eslint and adds legacy compatibility risk.

@djipco
Copy link
Owner

djipco commented Jun 1, 2025

Thanks a lot for your work on this. However, before I can merge it, the documentation needs to be carefully reviewed. The auto-generated documentation on the website relies on jsdoc being correct. From casual perusal, I can see that the Port object's documentation has probably been copied over from the Input object and carries over several references that are no longer valid.

Unfortunately, I do not have time right now to do this myself.

@dopry dopry force-pushed the fix/Input-Output-Polymorphism branch 5 times, most recently from e4b93a8 to ee6af46 Compare June 1, 2025 16:28
src/Port.js Outdated
}

/**
* Destroys the `Input` by removing all listeners, emptying the [`channels`](#channels) array and
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change Input for Port

src/Port.js Outdated

if (e.port.connection === "open") {
/**
* Event emitted when the `Input` has been opened by calling the [`open()`]{@link #open}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change Input for Port

@djipco
Copy link
Owner

djipco commented Jun 2, 2025

Thanks so much for your work on this. However, a quick search still reveals many references to Input in the documentation for Port.

refactor with a base class of Port for common code.
@dopry dopry force-pushed the fix/Input-Output-Polymorphism branch from ee6af46 to 07b870f Compare June 3, 2025 12:51
@dopry
Copy link
Author

dopry commented Jun 3, 2025

done

@djipco
Copy link
Owner

djipco commented Jun 4, 2025

Again, thanks for your work on this. However, there is still a part that is missing: the unit tests. As far as I know, this library has been pretty stable and I do not want to introduce any forms of regression.

So, we would need a new test file in /test for the Port object and the Input and Output tests may need to be adjusted.

@dopry
Copy link
Author

dopry commented Jun 5, 2025

Cool. Probably beyond my availability for additional work on this issue. We're actually moving away from WebMidi.js to just use the Wed MIDI API directly in our use cases. Thanks for entertaining it. Feel free to wrap it up if you're interested or close it if you're not.

@djipco
Copy link
Owner

djipco commented Jul 5, 2025

I dont' really have time to work on this currently. I'll leave it open and, hopefully, I can fin some time. If someone else wants to take a stab at updating the tests, that would be awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants