Skip to content

Commit 8fd85e7

Browse files
committed
Merge branch 'rawRegister' of https://github.com/microbit-apps/display-shield into restore_poll_buttons
2 parents f4afc82 + 57ce8b4 commit 8fd85e7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

eventcontext.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@ namespace context {
2121
public flags: number
2222
) { }
2323

24+
private myHandler: () => void = undefined
25+
2426
register() {
25-
control.onEvent(this.src, this.value, () => {
27+
this.myHandler = () => {
2628
if (this.handler) this.handler();
27-
}, this.flags)
29+
}
30+
control.rawOnEvent(this.src, this.value, this.myHandler, this.flags)
2831
}
2932

3033
unregister() {
31-
control.onEvent(this.src, this.value, doNothing, this.flags);
34+
control.rawUnregisterEvent(this.src, this.value);
3235
}
3336
}
3437

3538
function doNothing() { }
3639

37-
38-
3940
export class EventContext {
4041
private handlers: EventHandler[];
4142
private frameCallbacks: FrameCallback[];
@@ -100,7 +101,7 @@ namespace context {
100101
}
101102

102103
private runningCallbacks: boolean;
103-
private registerFrameCallbacks() {
104+
private startFrameWorker() {
104105
if (!this.frameCallbacks) return;
105106

106107
const worker = this.frameWorker;
@@ -129,7 +130,7 @@ namespace context {
129130
register() {
130131
for (const h of this.handlers)
131132
h.register();
132-
this.registerFrameCallbacks();
133+
this.startFrameWorker();
133134
}
134135

135136
unregister() {
@@ -141,7 +142,7 @@ namespace context {
141142
registerFrameHandler(order: number, handler: () => void): FrameCallback {
142143
if (!this.frameCallbacks) {
143144
this.frameCallbacks = [];
144-
this.registerFrameCallbacks();
145+
this.startFrameWorker();
145146
}
146147

147148
const fn = new FrameCallback()

0 commit comments

Comments
 (0)