Skip to content

Bugfix/unregister callbacks#29

Open
beorosz wants to merge 7 commits intoRicoSuter:masterfrom
beorosz:bugfix/unregisterCallbacks
Open

Bugfix/unregister callbacks#29
beorosz wants to merge 7 commits intoRicoSuter:masterfrom
beorosz:bugfix/unregisterCallbacks

Conversation

@beorosz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner

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

@beorosz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

beorosz commented May 12, 2020

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

@RicoSuter
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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