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

Bugfix/unregister callbacks #29

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

beorosz
Copy link
Contributor

@beorosz beorosz commented Feb 14, 2020

Please review the bugfix PR. I've created a dummy Angular app for testing the register/unregister functions, I can push it into this fix if you think it could be useful.

* unregisterCallbacks method added to template

* Replacing tabs with spaces

* README updated to reflect changes in generated code
@@ -1,4 +1,8 @@
export class {{ Name }}Hub {
{% for operation in Callbacks -%}
callbackFor{{ operation.Name }}: ({% for parameter in operation.Parameters %}{{ parameter.Name }}: {{ parameter.Type }}{% if forloop.last == false %}, {% endif %}{% endfor %}) => void;
Copy link
Owner

Choose a reason for hiding this comment

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

Add private?

Copy link
Owner

Choose a reason for hiding this comment

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

To be safe this should be an array of registrations so if multiple impls are registered all callbacks are unregistered, not only the last one. But we can also leave it as is as this is an edge case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modifications were made following your comments. Please check.

@RicoSuter
Copy link
Owner

@TomSmith27 is this still relevant? Can you have a look?

@beorosz
Copy link
Contributor Author

beorosz commented May 12, 2020

@RicoSuter, @TomSmith27 this is still relevant. Let me resolve the conflict and update the PR.

@TomSmith27
Copy link
Contributor

@beorosz I think the problem with this implementation is it only allows a single callback to be registered for each event.

If two places in the app set callbackForWelcome wont one of them be overidden?

I have also created a pull request that addresses a similar issue

Could you take a look at that and let me know what you think?

#32

@beorosz
Copy link
Contributor Author

beorosz commented May 12, 2020

@TomSmith27 yes, your solutions looks more flexible. @RicoSuter what do you think?

@RicoSuter
Copy link
Owner

RicoSuter commented May 12, 2020

@TomSmith27 I think if you only register the function and do not create a new lambda, then "this" is not correctly scoped within the call...
I think there is a reason I didnt register the function directly...

@TomSmith27
Copy link
Contributor

@RicoSuter

I am currently testing this is in a project and the below examples seem to be working, i am getting the correct context for this.

Is there another situation i can test to make sure it works in all situations

const receiveMessage = (name: string, age: number) => {
            this.person.name = name;
            this.person.age = age;
        };
        
chatHub.onReceiveMessage(receiveMessage);

chatHub.onReceiveMessage((name: string, age: number) => {
            this.person.name = name;
            this.person.age = age;
});

@beorosz
Copy link
Contributor Author

beorosz commented May 20, 2020

@RicoSuter @TomSmith27 should I close this PR then?

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.

3 participants