deko-bind

1.0.0 • Public • Published

deko-bind build status

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

Readme

Keywords

Package Sidebar

Install

npm i deko-bind

Weekly Downloads

5

Version

1.0.0

License

MIT

Unpacked Size

3.22 kB

Total Files

4

Last publish

Collaborators

  • thlorenz