deko-bind
v1.0.0
Published
Function bind decorator for deko.
Downloads
7
Readme
deko-bind
bind decorator for deko.
const deko = require('deko')
const bind = require('deko-bind')
class WorldClass {
constructor() {
deko(this)
}
hello() {
return 'hello world'
}
static $$onclicked() {
return [ bind ]
} onclicked(e) {
console.log(this.hello())
}
}
const worldClass = new WorldClass()
const onclicked = worldClass.onclicked
// Yay it's bound!!!
onclicked()
Installation
npm install deko-bind
Benchmarks
Comparing manually binding vs. binding with deko vs. binding with auto-bind.
# manual binding (this.foo = this.foo.bind(this) 1000000 times
ok ~24 ms (0 s + 23595643 ns)
# deko binding 1000000 times
ok ~145 ms (0 s + 145026498 ns)
# auto-bind all 1000000 times
ok ~719 ms (0 s + 718651445 ns)
# auto-bind with [ 'onclickedBound' ] opts 1000000 times
ok ~1.68 s (1 s + 684526786 ns)
all benchmarks completed
ok ~2.57 s (2 s + 571800372 ns)
License
MIT