Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

AdamCoulterOz
Copy link

No description provided.

@AdamCoulterOz AdamCoulterOz changed the title add type information for product details add type information for product details and client events Dec 7, 2021
Copy link
Collaborator

@ristomatti ristomatti left a 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.

src/lifx.d.ts Outdated Show resolved Hide resolved
src/lifx.d.ts Show resolved Hide resolved
src/lifx.d.ts Outdated Show resolved Hide resolved
src/lifx.d.ts Show resolved Hide resolved
src/lifx.d.ts Outdated Show resolved Hide resolved
src/lifx.d.ts Outdated Show resolved Hide resolved
src/lifx.d.ts Outdated Show resolved Hide resolved
@ristomatti ristomatti changed the title add type information for product details and client events Add missing types to client events, light properties, product details Dec 7, 2021
@ristomatti
Copy link
Collaborator

I've renamed the PR to better reflect the changes.

import {EventEmitter} from 'eventemitter3';
import {AddressInfo} from 'net';

export class ClientOptions {
Copy link
Collaborator

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.

Copy link
Author

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 */
Copy link
Collaborator

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;
Copy link
Collaborator

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 */
Copy link
Collaborator

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.

Copy link
Author

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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 {
Copy link
Collaborator

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';
Copy link
Collaborator

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.

Copy link
Author

@AdamCoulterOz AdamCoulterOz Oct 13, 2023

Choose a reason for hiding this comment

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

Here's a clarification:

  1. Core Node Modules (dgram and net):

    • These are included with Node.js, and their types are covered by the @types/node dev dependency.
  2. eventemitter3:

    • Agreed. I've added eventemitter3 as a dev dependency.

@@ -403,137 +356,15 @@ export const constants: {
TAGGED_BIT: number;
ZONE_INDEX_MAXIMUM_VALUE: number;
ZONE_INDEX_MINIMUM_VALUE: number;
};

export namespace packet {
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

@ristomatti
Copy link
Collaborator

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:

image
After:

image

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).

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