JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 64
  • Score
    100M100P100Q82711F
  • License MIT

A TypeScript/ES7 decorator for automatically binding methods to the class instance

Package Exports

  • @aloreljs/bound-decorator
  • @aloreljs/bound-decorator/_bundle/fesm5.js
  • @aloreljs/bound-decorator/_bundle/umd.js
  • @aloreljs/bound-decorator/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@aloreljs/bound-decorator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Bound decorator

Build Status Coverage Status


Table of Contents

Installation

npm install @aloreljs/bound-decorator

Both Babel and Typescript currently struggle when mixing transpiled ES5 and non-transpiled ES6 classes together. You need to make sure to configure your build environment to import the correct version of the decorator. Below is a table of the decorator's main fields and their compatibility:

| Field | ES5 | ES6 | |-----------------------: |:---: |:---: | | main (node.js default) | | x | | module | x | | | browser | x | | | esm5 | x | | | esm2015 | | x | | fesm5 | x | | | fesm2015 | | x |

Frontend bundlers typically use the browser or module field by default.

Compatibility

  • Typescript - full
  • Spec-compliant decorator proposal - full
  • Babel (current proposal) - full
  • Babel (legacy) - full

Usage

import {BoundMethod} from '@aloreljs/bound-decorator';

class MyClass {
  
  @BoundMethod()
  method1() {
    // equivalent to
    // this.method1 = this.method1.bind(this);
  }
  
  @BoundMethod('a', 'b')
  method2(a, b, c) {
    // equivalent to
    // this.method2 = this.method2.bind(this, 'a', 'b');
  }

  @BoundMethod()
  static foo() {
    // Equivalent to
    // MyClass.foo = MyClass.foo.bind(MyClass);
  }
}