ciena-blueplanet / ember-prop-types

Improved property management for Ember apps and addons.
http://ciena-blueplanet.github.io/ember-prop-types/
MIT License
80 stars 36 forks source link

Add support for iface type #180

Open synaptiko opened 5 years ago

synaptiko commented 5 years ago

Overview

Summary

Loosely based on https://github.com/ciena-blueplanet/ember-prop-types/issues/116 We use iface in our project, it's really similar to shape, the difference is that only specified props are checked.

Here's an example:

propTypes: {
  dog: PropTypes.iface({
    bark: PropTypes.function.isRequired,
    color: PropTypes.string
  }).isRequired
},

Then you can pass:

dog: Ember.Object.extend({
  bark() {
    console.log('woof woof')
  }
}).create()

or

dog: Ember.Object.extend({
  bark() {
    console.log('ruff ruff')
  },
  color: 'black',
  breed: 'affenpinscher'
}).create()

Both are accepted.

Checklist

If there will be interest in this PR, I can go over the list below and update documentation and provide some tests.

Semver

This project uses semver, please check the scope of this PR:

CHANGELOG

Support for iface type which is checking provided props similar to shape type but the missing props are tolerated.