ember-strong-attrs
ember-strong-attrs
is an addon that facilitates the declaration of
Ember.Component
required and optional attributes. It extends
Ember.Component
and provides ES7 Decorators to declare
required and optional attributes.
Caveats
- Experimental. This is alpha software, and we think it's a cool idea but not sure if it's a good idea yet.
- You need to enable ES7 Decorators in Babel.
- JSHint does not support ES7 Decorators at the moment so you
will get JSHint errors like this:
Unexpected '@'.
. To avoid this, you can tell jshint to ignore your decorators for now, as shown in the examples below. - Your
Ember.Component
s need to be ES6 classes so that the ES7 Decorators can decorate them.
Setup
- Install the addon
ember install ember-strong-attrs
- Update your
ember-cli-build.js
to enable Babel's ES7 Decorators
/* global require, module */var EmberApp = ; module { defaultsbabel = optional: 'es7.decorators' ; var app = defaults {}; return app;};
- Update the components you want to declare required/option attributes on to use ES6 Classes syntax.
Given the following Ember.Component
definition:
; Component;
You will get the following using ES6 Classes syntax
; Component // Don't forget the trailing { } and the removal of the semicolon
- Import the decorators into your component file.
;
API
Supported Attribute types
The attrType
argument can be the following classes:
String
Number
Date
Function
YouCustomClass
Decorators
ember-strong-attrs
exposes two decorators:
@requiredAttr(attrName, attrType)
@optionalAttr(attrName, attrType)
Example:
;;; // Note the lack of semicolons behind the decorators/* jshint ignore: start */@@@/* jshint ignore: end */Component
ES6 Compatible
ember-strong-attr
exposes one function to declare strong attributes on
Ember.Component
declareStrongAttrs(attrsFunc, component)
, which returns the modifiedcomponent
that was passed in.
Example:
;;; { this; this; this;} EmberComponent;