This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
methodの間接利用の方式を見直す #5
Comments
やっぱりモジュールベースが直感的 class Module {
emit () { throw new Error('Not connect to sugo actor!. You need setup .... ') }
}
class Bomb extends Module {
boom() {
console.log('boom!')
this.emit('fire!!')
}
}
class TimeBomb extends Bomb {
constructor () {
}
countDown () {
super.boom()
}
boom () {
thrown new Error('Not call me!')
}
}
const sugoActor('example.com', {
moudles: {
mybomb01: new TimeBomb()
}
})
let caller = sugoCaller('example.com')
let mybomb01 = caller.get('mybomb01')
mybomb01.on('fire', () => { /* ... */ })
yield mybomb01.countDown() |
外向けに使わせるメソッドを制限したい場合はプラグインで頑張る function limitPlugin(instance, methodsToAllow ) {
for( let method of methodsToAllow ) {
instance[method] = someWrap(instance[method])
}
return instance
}
modules: {
b: limitPlugin(new TimeBomb(), ['countDown']
}
|
多重継承的な? class Module {
}
const HiPeople = (superclass = Module) => class extends superclass {
sayHi () { console.log('Hi!') }
}
const YoPeople = (superclass = Module) => class extends superclass {
sayYo () { console.log('Yo!') }
}
class MyPerson extends HiPeople(YoPeople(Module)) {
sayHiAndYo () {
const s = this
s.sayHi()
s.sayYo()
}
} |
継承以外にも他のモジュールを間接呼び出しできるようにしたい。emiterを渡せば良いか? class A extends Module {
foo() { this.emit('foo') }
}
class B extends Module {
constructor () {
this.a = new A({ $emitter: this }) // Pipe emitter
}
foo () { this.a.foo() }
}
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
例えば
という風にb.z() -> a.y() -> a.x() と間接的に呼び出すときにどうすればよいか。方式を考える必要がある
The text was updated successfully, but these errors were encountered: