Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-decorator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-decorator

The default blueprint for ember-cli addons.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
decreased by-96.11%
Maintainers
1
Weekly downloads
 
Created
Source

abstract-decorator

JavaScript doesn't have a built in language feature for defining abstract classes and enforcing their contracts - but with decorators, we can create that functionality ourselves! The @abstract decorator allows you to define simple abstract classes, like so:

@abstract
class CookieService {
  @abstract headers;

  @abstract getValue() {}
  @abstract setValue() {}
}

You can then extend the class and provide the abstract values:

class BrowserCookieService extends CookieService {
  headers = new Map();

  getValue() {
    // get cookie value
  }

  setValue(value) {
    // set cookie value
  }
}

If a subclass fails to provide the correct values, then an error will be thrown the first time the class is instatiated. The two types of abstract values that can be defined are fields and methods, and they are defined by decorating a class field or a method respectively.

Dev Time Only

The errors thrown by @abstract are useful in development, but are pointless overhead in production applications. If you're consuming this package, you can remove the decorators using the filter-imports babel plugin:

{
  "plugins": [
    [
      "babel-plugin-filter-imports",
      {
        "imports": {
          "abstract-decorator": ["default"]
        }
      }
    ]
  ]
}

This setup is provided out-of-the-box in Ember apps and addons, zero configuration necessary!

Compatibility

This package is compatible with Node v10 and above out of the box.

Decorator Transforms

This package supports the stage 1/legacy decorators transform. This is transform that is the current recommendation of the champions of the decorators proposal.

Typescript

This package does not support Typescript. Typescript has first class support for abstract classes, so there's no need to include extra weight via this decorator.

Ember

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

npm install --save abstract-decorator

# or with yarn
yarn add abstract-decorator

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 29 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc