Created
August 18, 2020 19:07
-
-
Save andrewborisov/143bc9d6ed05e14bb4fbf15ae2059d94 to your computer and use it in GitHub Desktop.
Гист для статьи "Еще раз о паттернах проектирования в Javascript es6 (часть 2)"
This file contains 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
class Gestures { | |
constructor(output) { | |
this.name = 'Gestures'; | |
this.output = output; | |
} | |
tap() { | |
return this.output.click(this.name); | |
} | |
swipe() { | |
return this.output.move(this.name); | |
} | |
pan() { | |
return this.output.drag(this.name); | |
} | |
pinch() { | |
return this.output.zoom(this.name); | |
} | |
} | |
class Mouse { | |
constructor(output) { | |
this.name = 'Mouse'; | |
this.output = output; | |
} | |
click() { | |
return this.output.click(this.name); | |
} | |
move() { | |
return this.output.move(this.name); | |
} | |
down() { | |
return this.output.drag(this.name); | |
} | |
wheel() { | |
return this.output.zoom(this.name); | |
} | |
} | |
class Screen { | |
click(name) { | |
console.log(`Screen select triggered by ${name}`); | |
} | |
move(name) { | |
console.log(`Screen move triggered by ${name}`); | |
} | |
drag(name) { | |
console.log(`Screen drag triggered by ${name}`); | |
} | |
zoom(name) { | |
console.log(`Screen zoom in triggered by ${name}`); | |
} | |
} | |
class Audio { | |
click(name) { | |
console.log(`Sound oink triggered by ${name}`); | |
} | |
move(name) { | |
console.log(`Sound waves triggered by ${name}`); | |
} | |
drag(name) { | |
console.log(`Sound screetch triggered by ${name}`); | |
} | |
zoom(name) { | |
console.log(`Sound volume up triggered by ${name}`); | |
} | |
} | |
const testing = () => { | |
const screen = new Screen(); | |
const audio = new Audio(); | |
const handScreenBridge = new Gestures(screen); | |
const handAudioBridge = new Gestures(audio); | |
const mouseScreenBridge = new Mouse(screen); | |
const mouseAudioBridge = new Mouse(audio); | |
handScreenBridge.tap(); | |
handScreenBridge.swipe(); | |
handScreenBridge.pinch(); | |
console.log('==============='); | |
handAudioBridge.tap(); | |
handAudioBridge.swipe(); | |
handAudioBridge.pinch(); | |
console.log('==============='); | |
mouseScreenBridge.click(); | |
mouseScreenBridge.move(); | |
mouseScreenBridge.wheel(); | |
console.log('==============='); | |
mouseAudioBridge.click(); | |
mouseAudioBridge.move(); | |
mouseAudioBridge.wheel(); | |
}; | |
testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment