This addon enables the following pattern:
// some-component
export default Component.extend(RequiredProperties, {
requiredProperties: ['thing', 'another', 'on-select-thing']
});
ERROR: You must provide thing, another, and on-select-thing to some-component.
Like ember-prop-types
, this addon helps ensure required properties are passed to components. This addon is intended to be a much smaller building block. It only verifies required properties are present, not that they are of the correct type.
ember install ember-required-properties
Import the mixin anywhere you want to require properties:
import RequiredProperties from 'ember-required-properties/mixins/required-properties';
export Component.extend(RequiredProperties, {
requiredProperties: ['one', 'two']
});
Now if you fail to pass all of the required properties you will get an error.
NOTE: since we use Ember.assert
to throw errors, production will silently fail.
Ember Required Properties is maintained and funded by Echobind.
@echobind
We love open source! See our other projects or hire us to help bring your idea to life.
Echobind LLC (c) 2016
@echobind
Licensed under the MIT license