deko

1.0.0 • Public • Published

deko build status

Decorators for ES6 classes without transpilation.

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

Decorators

The following decorators are compatible with deko.

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

none

Package Sidebar

Install

npm i deko

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

5.08 kB

Total Files

4

Last publish

Collaborators

  • thlorenz