9.0.2 • Published 6 years ago

ember-prop-types v9.0.2

Weekly downloads
4,467
License
MIT
Repository
github
Last release
6 years ago

ember-prop-types

This addon provides React-like property management for components.

Dependencies

Ember NPM

Health

Travis Coveralls

Security

bitHound

Installation

ember install ember-prop-types

Usage

Full Docs

Examples

Better Components

Below is an example of a component that uses the property mixin provided by this addon:

import Ember from 'ember'
import {PropTypes} from 'ember-prop-types'

export default Ember.Component.extend({
  propTypes: {
    foo: PropTypes.string,
    bar: PropTypes.number.isRequired,
    baz: PropTypes.oneOfType([
      PropTypes.bool,
      PropTypes.string
    ])
  },

  getDefaultProps () {
    return {
      foo: 'This is going to be highly profitable'
    }
  }
})

If this mixin is being used in a class other than Component, it will need to be mixed into the class:

import Ember from 'ember'
import PropTypeMixin, {PropTypes} from 'ember-prop-types'

export default Ember.ClassName.extend(PropTypeMixin, {
  propTypes: {
    foo: PropTypes.string,
    bar: PropTypes.number.isRequired,
    baz: PropTypes.oneOfType([
      PropTypes.bool,
      PropTypes.string
    ])
  },

  getDefaultProps () {
    return {
      foo: 'This is going to be highly profitable'
    }
  }
})

Property Validation

The idea of propTypes comes from the world of React and is implemented to have an almost identical API in the Ember world. Below is a list of possible propTypes to validate against.

  • any
  • array
  • arrayOf
  • bool
  • date
  • element
  • EmberObject
  • func
  • instanceOf
  • null
  • number
  • object
  • oneOf
  • oneOfType
  • regexp
  • shape
  • string
  • symbol

Default Property Values

In Ember you can set default property values on a component class itself but sometimes this bites you when you end up with a property containing an array of selected items or a state object, where all instances of the component end up sharing that same array or object. Uncovering this issue is not always an easy task and so getDefaultProps was also implemented (thanks to the React team for this concept as well).

9.0.2

6 years ago

9.0.0

6 years ago

8.0.0

6 years ago

7.0.4

6 years ago

7.0.3

6 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.1.0

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.14.2

7 years ago

3.14.1

7 years ago

3.14.0

7 years ago

3.13.4

7 years ago

3.13.3

7 years ago

3.13.2

7 years ago

3.13.1

7 years ago

3.13.0

7 years ago

3.12.3

7 years ago

3.12.2

7 years ago

3.12.1

7 years ago

3.12.0

7 years ago

3.11.0

7 years ago

3.10.4

7 years ago

3.10.3

7 years ago

3.10.2

7 years ago

3.10.1

7 years ago

3.10.0

7 years ago

3.9.0

7 years ago

3.8.0

7 years ago

3.7.1

7 years ago

3.7.0

7 years ago

3.6.0

7 years ago

3.5.0

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.5.11

8 years ago

2.5.10

8 years ago

2.5.9

8 years ago

2.5.8

8 years ago

2.5.7

8 years ago

2.5.6

8 years ago

2.5.5

8 years ago

2.5.4

8 years ago

2.5.3

8 years ago

2.5.2

8 years ago

2.5.1

8 years ago

2.5.0

8 years ago

2.4.2

8 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.2.8

8 years ago

2.2.7

8 years ago

2.2.6

8 years ago

2.2.5

8 years ago

2.2.4

8 years ago

2.2.3

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.2

8 years ago