-
Notifications
You must be signed in to change notification settings - Fork 20
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 missing types to client events, light properties, product details #45
base: main
Are you sure you want to change the base?
Conversation
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.
Nice improvements, thanks! I've added a few comments.
I've renamed the PR to better reflect the changes. |
import {EventEmitter} from 'eventemitter3'; | ||
import {AddressInfo} from 'net'; | ||
|
||
export class ClientOptions { |
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.
Thanks for defining these also but this shold definately be an interface as it's passed in as a plain object.
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.
Rationale for Utilizing ClientOptions
as a Class
1. Encapsulation:
- Having
ClientOptions
as a class allows for the encapsulation of default values alongside the option attributes. - This encapsulation makes it straightforward to manage default values in a centralized location, thereby reducing the complexity in the
init
method where these options are utilized.
2. Ease of Use:
- The class constructor can easily merge user-provided options with default values, providing a clean, intuitive interface for consumers.
- This also streamlines the code in the
init
method, as it can assume that all necessary options are properly initialized.
3. Type Safety:
- The class structure ensures type safety for the configuration options while allowing for partial overriding of default values.
- This is beneficial for maintaining code integrity and reducing potential runtime errors.
export class ClientOptions {
/** The IPv4 address to bind to */
address: string = '0.0.0.0';
/** The port to bind to */
port: number = 0;
/** Show debug output */
debug: boolean = false;
// ... other properties with default values ...
constructor(options?: Partial<ClientOptions>) {
Object.assign(this, options);
}
}
const options = new ClientOptions({ address: '127.0.0.1', debug: true });
* @param {Function} [callback] Called after initialation | ||
*/ | ||
init(options: any, callback: any): any; | ||
/** Creates a new socket and starts discovery */ |
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.
Please revert this back. The JSDoc's are shown in IDE's when you hover over the function.
*/ | ||
light(identifier: any): any; | ||
light(identifier: string): Light | false; |
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.
Please revert the JSDoc as it was. It's simpler to have the same text here as in the code. The types in JSDocs are unnecessary though, so you're welcome to remove them if you wish.
import {AddressInfo} from 'net'; | ||
|
||
export class ClientOptions { | ||
/** The IPv4 address to bind to */ |
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.
At least WebStorm doesn't seem to show these when I hover over client.init
so these aren't much of use here. See my comments on the client interface.
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.
They should. It does in vscode.
*/ | ||
color(hue: any, saturation: any, brightness: any, kelvin: any, duration: any, callback: any): void; | ||
color(hue: number, saturation: number, brightness: number, kelvin: number, duration: number, callback: (err: Error) => void): void; |
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.
👍
* @param apply apply changes immediately or leave pending for next apply | ||
* @param callback called when light did receive message | ||
*/ | ||
colorZones(startIndex: number, endIndex: number, hue: number, saturation: number, brightness: number, kelvin: number, duration: number, apply: boolean, callback: (err: Error, msg: any, rinfo: RemoteInfo) => void): void; |
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.
👍
saturation: number; | ||
} | ||
|
||
export class constants { |
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.
Revert this back to const
as that's what it is. We're not instantiating it anywhere. This could also break someones code ( I think).
export class Client { | ||
import {RemoteInfo} from 'dgram'; | ||
import {EventEmitter} from 'eventemitter3'; | ||
import {AddressInfo} from 'net'; |
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.
If we're referencing types from other packages, I believe we should have them as dev dependencies in package.json also.
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.
Here's a clarification:
-
Core Node Modules (
dgram
andnet
):- These are included with Node.js, and their types are covered by the
@types/node
dev dependency.
- These are included with Node.js, and their types are covered by the
-
eventemitter3
:- Agreed. I've added
eventemitter3
as a dev dependency.
- Agreed. I've added
@@ -403,137 +356,15 @@ export const constants: { | |||
TAGGED_BIT: number; | |||
ZONE_INDEX_MAXIMUM_VALUE: number; | |||
ZONE_INDEX_MINIMUM_VALUE: number; | |||
}; | |||
|
|||
export namespace packet { |
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 did not ask to remove this. I know some people use these to overcome the lack of some features on this library. Please revert.
} | ||
|
||
export namespace utils { | ||
export interface utils { |
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.
Please revert this to namespace
and as it where. I don't think it's a good idea to remove types we've previously published. I might have made a mention on private/public APIs but since the functions in utils
had JSDoc's, they could be used by some.
Sorry about the amount of comments but there was a lot of unexpected changes. Some good, some not. At least for me autocomplete is quite broken now. Did you test these? Before: So with the changes it would seem it's not possible to create a new client instance (unless I'm doing something wrong with my quick testing). |
No description provided.