Skip to content

DX improvments by adding typehints #356

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

Closed
wants to merge 3 commits into from
Closed

Conversation

nandi95
Copy link

@nandi95 nandi95 commented Sep 15, 2022

This is a non-breaking change.
This will help users set up quicker by typehinting options.
There is no type testing set up nor there is much to test given no features have been added.
Please see comments below.

I would version this as a minor given the error added and the method on the null channel.

auth?: {
headers: Record<string, string>
},
userAuthentication?: {
Copy link
Author

Choose a reason for hiding this comment

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

Haven't set up fields that are isn't actually referenced in this package. For service specific options the user can import typing from the service's package and use an intersection of types.

Copy link
Author

Choose a reason for hiding this comment

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

In fact authEndpoint for example is deprecated in pusher.

/**
* Listen for an event on a channel instance.
*/
abstract listen(name: string, event: string, callback: CallableFunction): Channel;
Copy link
Author

Choose a reason for hiding this comment

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

This seems to have been present in all supplied connectors and this would be a basic requirement/naming for any different provider's connector.

/**
* Get a private encrypted channel instance by name.
*/
encryptedPrivateChannel(name: string): NullPrivateChannel {
Copy link
Author

Choose a reason for hiding this comment

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

Added so it's has better feature parity with the pusher connector.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what the socket.io equivalent...

@@ -50,7 +50,7 @@ export class SocketIoConnector extends Connector {
/**
* Listen for an event on a channel instance.
*/
listen(name: string, event: string, callback: Function): SocketIoChannel {
listen(name: string, event: string, callback: CallableFunction): SocketIoChannel {
Copy link
Author

Choose a reason for hiding this comment

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

has better typing when it comes to call, bind, apply

Copy link
Author

Choose a reason for hiding this comment

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

I can update the rest of the package to CallableFunction if desired.


/**
* This class is the primary API for interacting with broadcasting.
*/
export default class Echo {
export default class Echo<O extends Record<PropertyKey, unknown>> {
Copy link
Author

Choose a reason for hiding this comment

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

user can pass in the typings from providers such as pusher

@@ -46,6 +51,8 @@ export default class Echo {
this.connector = new NullConnector(this.options);
} else if (typeof this.options.broadcaster == 'function') {
this.connector = new this.options.broadcaster(this.options);
} else {
throw new Error('Broadcaster option not set when initialising Echo.');
Copy link
Author

Choose a reason for hiding this comment

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

This is a bit nicer than the user calling a method on undefined as the connector has not been set.

@@ -95,7 +102,7 @@ export default class Echo {
* Get a private encrypted channel instance by name.
*/
encryptedPrivate(channel: string): Channel {
return this.connector.encryptedPrivateChannel(channel);
return (this.connector as NullConnector | PusherConnector).encryptedPrivateChannel(channel);
Copy link
Author

Choose a reason for hiding this comment

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

Not sure why this is here socket.io connector is not implementing it. (The user can always just access echo.connector)

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

@nandi95
Copy link
Author

nandi95 commented Mar 2, 2023

@taylorotwell
To respond, this kind of code if anything, it helps maintaining the codebase. In this case, I could release a @types/laravel-echo but it would be odd, given that files are already are typescript files and it would mean it's not updated along with echo itself.

@nandi95
Copy link
Author

nandi95 commented Jun 2, 2023

@jessarcher Any chance this could be looked at again?

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