Closed jamesadevine closed 6 years ago
P.S. this is built off of the dal-integration branch.
The messagebus-patch branch can be used for testing from https://github.com/lancaster-university/microbit/compare/dal-integration...messagebus-patch
Thanks @jamesadevine
Looks good. Nice rationale. All those white space changes put me off doing a quick review. ;)
@finneyj My editor has an aversion for tabs... I wonder how they got there in the first place? :wink:
cheeky. ;)
In the runtime, we currently observe a "one handler per event and function" rule when adding and ignoring listeners; the message bus does not observe
cb_arg
(callback argument) as a differentiator between listeners. This has lead to MessageBus functionality duplication at the MakeCode layer (the MakeCode layer receives all events and invokes the correct handler). Effectively, in the MakeCode layer the source and value of an event is the key, and the cb_arg is the value. What this means is that only one function can be added per event in TypeScript, limiting the ability to write additional drivers for things like the radio entirely in TypeScript.The same effect can be seen in C++. To observe, simply compile the code snippet bellow:
The snippet above scrolls "ABC" on either button press, however, given that the callback argument is different, the above snippet should scroll "ABC" "123" on button a or b .
This PR introduces the ability to differentiate listeners on their
cb_arg
in addition to the source and id they are assigned. Implicitly, this means that multiple listeners can now have the same source and id. Therefore, in addition I also introduce a callback function that is invoked whenever a listener is deleted so that in the case multiple listeners are deleted, the application can take note.Here's a simple test program after checking out this PR:
This test program will:
1) Scroll "abc" "123" when either button a or b is pressed. 2) After pressing button AB, only "123" will scroll.
You can also remove all listeners by replacing:
with a less specific variant:
@tballmsft @jaustin @mmoskal @finneyj