Define client and presenter for follow

This commit is contained in:
Shin'ya Ueoka 2019-05-18 13:06:37 +09:00
parent 17dc2bb5ec
commit a88324acd9
9 changed files with 358 additions and 179 deletions

View file

@ -0,0 +1,47 @@
import * as messages from '../../shared/messages';
import { Key } from '../../shared/utils/keys';
export default interface FollowMasterClient {
startFollow(newTab: boolean, background: boolean): void;
responseHintCount(count: number): void;
sendKey(key: Key): void;
// eslint-disable-next-line semi
}
export class FollowMasterClientImpl implements FollowMasterClient {
private window: Window;
constructor(window: Window) {
this.window = window;
}
startFollow(newTab: boolean, background: boolean): void {
this.postMessage({
type: messages.FOLLOW_START,
newTab,
background,
});
}
responseHintCount(count: number): void {
this.postMessage({
type: messages.FOLLOW_RESPONSE_COUNT_TARGETS,
count,
});
}
sendKey(key: Key): void {
this.postMessage({
type: messages.FOLLOW_KEY_PRESS,
key: key.key,
ctrlKey: key.ctrlKey || false,
});
}
private postMessage(msg: messages.Message): void {
this.window.postMessage(JSON.stringify(msg), '*');
}
}