class Invoker { constructor(commander) { this.commander = commander } publish() { console.log('Invoker publishing'); this.commander.execute() } } class Commander { constructor(receiver) { this.receiver = receiver } execute() { console.log('Commander notifying'); this.receiver.execute() } } class Receiver { execute() { console.log('Receiver excuting'); } } let receiver = new Receiver() let commander = new Commander(receiver) let invoker = new Invoker(commander) invoker.publish()
class Macro { constructor() { this.lists = [] } add(commander) { this.lists.push(commander) } publish() { console.log('Invoker publishing'); this.lists.forEach(item => { item.execute() }) } } class Tabs { execute() { console.log('Tabs executing'); } } class Swiper { execute() { console.log('Swiper executing'); } } let tabs = new Tabs() let swiper = new Swiper() let macro = new Macro() macro.add(tabs) macro.add(swiper) macro.publish()