0.0.3 • Published 10 years ago
ember-enforcer v0.0.3
Ember Enforcer has been sunsetted
Instead of maintaining two different addons trying to do the same thing, I've collaborated with Yapplabs to create Ember Strong Attrs.
As such, Ember Enforcer has been sunsetted in favor of ember-strong-attrs.
Ember Enforcer
Ember Enforcer is an addon that facilitates the declaration and enforcement
of Ember.Component attributes. It exposes an API that return Ember.Mixin
instances which can be mixed into your components.
Installation
ember install ember-enforcerAPI
Required Attributes
Enforcer.required(attrName, [options])options can have any of the following keys:
typevalues can be any of the following strings:stringnumberobjectboolfunction
message
import Ember from 'ember';
import Enforcer from 'ember-enforcer';
const ButtonComponent = Ember.Component.extend(
Enforcer.required('height'),
Enforcer.required('width', { type: 'number' }),
Enforcer.required('model', { type: 'object' }),
Enforcer.required('enabled', { type: 'bool' }),
Enforcer.required('color', { message: 'Component requires hex string attribute' }),
Enforcer.required('onClick', {
type: 'function',
message: 'Component requires onClick callback attribute'
}),
{
// Component logic goes here...
});
export default ButtonComponent;Future Enhancements
- ES7 decorators once the proposal is formalized
typecan be a function that returns if attr is a valid type