开发者社区> 镜像站> NPM> deko-bind
deko-bind
Function bind decorator for deko.
Last updated 3 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install deko-bind 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

2 Versions

  • 1.0.0                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None