Created
September 14, 2021 11:59
-
-
Save zapkub/30def5f2a6eff81d3ba70f2fd5dac525 to your computer and use it in GitHub Desktop.
decoupling everlong things
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Message = Uint8Array; | |
class BluetoothControl { | |
collectScanResult() { | |
} | |
private _onDiscoverCallback: (device: BLEDevice) => void | |
onDiscoverDevice(callback: (device: BLEDevice) => void) { | |
this._onDiscoverCallback = callback; | |
} | |
} | |
class BLEDevice { | |
constructor() {} | |
private _onMessage: (data: Message) => void | |
public setOnMessage(callback: (data: Message) => void) { | |
this._onMessage = callback; | |
} | |
private _listenTo() { | |
// listen to bluetooth | |
this._onMessage?.(new Uint8Array()); | |
} | |
public toogleHost() {} | |
} | |
class Classroom { | |
devices: BLEDevice[] | |
constructor() { } | |
addDevice(device: BLEDevice) { | |
device.setOnMessage(this.sendLocal); | |
this.devices.push(device); | |
} | |
sendLocal(uint8: Uint8Array) { | |
// forward | |
} | |
} | |
class Online { | |
devices: BLEDevice[] | |
addDevice(device: BLEDevice) { | |
device.setOnMessage(this.sendLocal); | |
this.devices.push(device); | |
} | |
sendLocal(uint8: Uint8Array) { | |
// forward | |
} | |
} | |
class ModeController { | |
constructor( | |
private classroom: Classroom, | |
private online: Online, | |
private bluetoothControl: BluetoothControl, | |
) { | |
} | |
onModeChange(mode: 'Online' | 'Classroom') { | |
if (mode === 'Online') { | |
this.bluetoothControl.onDiscoverDevice(this.online.addDevice); | |
} else { | |
this.bluetoothControl.onDiscoverDevice(this.classroom.addDevice); | |
} | |
} | |
} | |
function init() { | |
const bluetoothControl = new BluetoothControl(); | |
const classroom = new Classroom(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment