-
Notifications
You must be signed in to change notification settings - Fork 14
Updated JS event handlers and implemented onCustomMessageAction #5
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
Conversation
ad9d617 to
dd421d1
Compare
dd421d1 to
de483aa
Compare
vickz84259
left a comment
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.
How is someone meant to unsubscribe from an event?
lib/src/chatbox.dart
Outdated
| if (widget.onCustomMessageAction != null) { | ||
| _oldCustomActions = Set<String>.of(widget.onCustomMessageAction!.keys); | ||
| for (var action in _oldCustomActions) { | ||
| execute('chatBox.onCustomMessageAction("$action", (event) => JSCCustomMessageAction.postMessage(JSON.stringify(["$action", event])));'); |
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.
Why send an array with the action string and event object? The event object by itself already contains a property called action. So the message sent to Dart could just be: JSON.stringify(event)
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 that basically to be independent from the event data structure.
But, as I already need to know the event data structure, in order to convert it to Dart, I agree that using event.action works as well.
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.
anyway, now I'm using only one handler for all the custom message actions, and using event.action to know the triggered action
This actually is a known memory leak, but I don't think it will be that serious. The way I envisioned it is this: You put the actions that you want to subscribe to as keys of the mapping. If you want to subscribe to a new custom action, you add the key to the mapping, and internally, I handle the JS to handle the subscription. If you don't want to be subscribed anymore, you remove the key from the mapping, and it will work. Internally the JS will still be subscribed, but no handler will be called from the Dart side. I know it's not optimal, but I don't think it's a problem. @eteeselink what do you think? |
|
My Flutter-fu fails me, but I'd like to understand this. With this code, how would someone subscribe to a custom action? |
a56a9b3 to
271efb8
Compare
With a mapping, as per the (already approved) docs: onCustomMessageAction: {
'favourite': (event) {
print('Favourited message with id: ${event.message.id}');
},
'report': (event) {
print('Reported message with id: ${event.message.id}');
},
}, |
|
ok clear. that's delightful btw :) not sure if i already said that. |
cc @eteeselink