{"id":21492878,"url":"https://github.com/crystal-ball/ember-cli-prop-types","last_synced_at":"2025-07-15T18:32:51.361Z","repository":{"id":57223437,"uuid":"91598797","full_name":"crystal-ball/ember-cli-prop-types","owner":"crystal-ball","description":"React PropTypes for Ember CLI","archived":false,"fork":false,"pushed_at":"2020-01-26T15:25:07.000Z","size":410,"stargazers_count":34,"open_issues_count":4,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-16T17:13:25.467Z","etag":null,"topics":["ember","ember-cli","proptype-validators","proptypes"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crystal-ball.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-17T16:40:50.000Z","updated_at":"2024-05-30T02:37:51.000Z","dependencies_parsed_at":"2022-08-30T02:40:16.438Z","dependency_job_id":null,"html_url":"https://github.com/crystal-ball/ember-cli-prop-types","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-ball%2Fember-cli-prop-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-ball%2Fember-cli-prop-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-ball%2Fember-cli-prop-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-ball%2Fember-cli-prop-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crystal-ball","download_url":"https://codeload.github.com/crystal-ball/ember-cli-prop-types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226063959,"owners_count":17568025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ember","ember-cli","proptype-validators","proptypes"],"created_at":"2024-11-23T15:33:58.676Z","updated_at":"2024-11-23T15:33:59.327Z","avatar_url":"https://github.com/crystal-ball.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![PropTypes Icon](https://github.com/crystal-ball/ember-cli-prop-types/raw/master/icon.png)\n\n[![Latest NPM release](https://img.shields.io/npm/v/ember-cli-prop-types.svg)](https://www.npmjs.com/package/ember-cli-prop-types)\n[![Ember Observer Score](https://emberobserver.com/badges/ember-cli-prop-types.svg)](https://emberobserver.com/addons/ember-cli-prop-types)\n[![Dependencies](https://david-dm.org/crystal-ball/ember-cli-prop-types.svg)](https://david-dm.org/crystal-ball/ember-cli-prop-types)\n[![Dev Dependencies](https://david-dm.org/crystal-ball/ember-cli-prop-types/dev-status.svg)](https://david-dm.org/crystal-ball/ember-cli-prop-types?type=dev)\n\n# Ember CLI PropTypes\n\nThis addon makes the [prop-types](https://www.npmjs.com/package/prop-types)\nlibrary available for React style props validation in your Ember application. The\naddon itself is very simple, it includes:\n1. AMD compatible import of `prop-types` library _(prod optimized import weight of\n  only 0.12KB gzipped)_.\n2. Ember `Component` reopen in dev builds to call `checkPropTypes`, see the\n  [component-prop-types](https://github.com/crystal-ball/ember-cli-prop-types/blob/master/addon/initializers/component-prop-types.js)\n  initializer _(Component reopen stripped for production builds)_.\n\nProps validations and the validators themselves are all provided by the\n[prop-types](https://www.npmjs.com/package/prop-types) library.\n\n## Install\n\n```\nember install ember-cli-prop-types\n```\n\n## Props Validation\nImport `PropTypes` into your component JS files and define a `propTypes` property to\nperform validation on passed props:\n\n```javascript\n// your-component.js\nimport Component from 'ember-component';\nimport PropTypes from 'prop-types';\n\nexport default Component.extend({\n  // Define prop types for your passed properties here\n  propTypes: {\n    title: PropTypes.string.isRequired,\n    pages: PropTypes.number,\n    isLatest: PropTypes.bool\n  }\n});\n```\n\nThe `prop-types` library will validate that any props passed into your component\nmatch the type specified in `propTypes`. See the\n[prop-types Documentation](https://www.npmjs.com/package/prop-types) for details on\ndefining `propTypes` for your components.\n\n### Validating Ember-Specific Classes/Concepts\n\nYou can validate the majority of Ember classes or other Ember-specific concepts\nvia the `instanceOf` type checker. We have added specific support for `Ember.Array`\nand will continue to add support for Ember classes that cannot be validated using\nthe library as-is.\n\n```javascript\nimport Component from 'ember-component';\nimport EmberObject from 'ember-object';\nimport DS from 'ember-data';\nimport PropTypes from 'prop-types';\nconst { PromiseArray } = DS;\n\nexport default Component.extend({\n  propTypes: {\n    post: PropTypes.instanceOf(EmberObject),\n    relatedPosts: PropTypes.instanceOf(PromiseArray),\n    authors: PropTypes.emberArray.isRequired,\n    comments: PropTypes.emberArray,\n    leaveCommentClosureAction: PropTypes.func\n  }\n});\n```\n\n#### Ember-Specific Checkers:\n\n- `PropTypes.emberArray`\n\n### Destructured Imports\n\nDestructuring imports is also supported:\n\n```javascript\nimport Component from 'ember-component';\nimport { string, number, bool, func } from 'prop-types';\n\nexport default Component.extend({\n  propTypes: {\n    title: string.isRequired,\n    pages: number,\n    isLatest: bool,\n    someAction: func\n  }\n});\n```\n\n## Props Default Values\nThis addon adds the ability to set a default value for passed props through a `getDefaultProps`\nmethod. This method should return an object with the default props values:\n\n```javascript\nimport Component from 'ember-component';\nimport { string, number, bool } from 'prop-types';\n\nexport default Component.extend({\n  propTypes: {\n    title: string.isRequired,\n    pages: number,\n    isLatest: bool\n  },\n  getDefaultProps() {\n    return {\n      title: 'Ambitious Props',\n      pages: 1,\n      isLatest: false\n    };\n  }\n});\n```\n\nDuring component initialization, if a prop with a configured default is `undefined`,\nit will be set to the returned default value. This can be especially helpful when\nworking with dynamic values or the component helper.\n\nThe `getDefaultProps` method is run during production builds.\n\n## Lifecycle Hook Super Calls\nThis addon calls props validation and default value assignments in the `didReceiveAttrs`\nand `init` lifecycle hooks. Per the Ember.js docs, if you need to define additional behavior in\nthese hooks you must call `this._super(...arguments)`:\n\n```javascript\nexport default Component.extend({\n  propTypes: {\n    someString: PropTypes.string\n  },\n  getDefaultProps() {\n    return {\n      someString: 'Default Value'\n    }\n  },\n\n  init() {\n    this._super(...arguments);\n    // your component code\n  },\n  didReceiveAttrs() {\n    this._super(...arguments);\n    // your component code\n  }\n})\n```\n\n## In Production\nAlthough props validation is only run in development builds, this addon must be\nincluded for production builds as well. During production builds the `prop-types`\nlibrary is not imported. Instead a set of shims is imported for the props validators\nso that the `import` statements do not throw errors. Prod weight for the addon is\n0.29 KB (0.12 KB gzipped).\n\nThe call to `PropTypes.checkPropTypes` is automatically stripped in production builds\nas well using UglifyJS's `compress` configurations. If you would like to disable this\nadditional stripping you can configure the addon to skip it in your\n`ember-cli-build.js` configs _(Note that even if you disable the code stripping props\nvalidations will still only be run in dev builds)_.\n\nThe `getDefaultProps` method is run during component `init` in production builds. If\nyou would prefer not to enable this method, you can configure the addon to strip it\nout:\n\n```javascript\n// ember-cli-build.js\nmodule.exports = function(defaults) {\n  let app = new EmberApp(defaults, {\n    emberCliPropTypes: {\n      compress: false, // Setting to false will disable code stripping\n      getDefaultProps: false // Setting to false will strip `getDefaultProps` feature\n    }\n  });\n\n  return app.toTree();\n};\n\n```\n\n## Contributing\n\nIf you'd like to contribute, please read our [contribution\nguidelines](./.github/CONTRIBUTING.md) and then get cracking!\n\n[Please report bugs using the issues tab.](https://github.com/crystal-ball/ember-cli-prop-types/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrystal-ball%2Fember-cli-prop-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrystal-ball%2Fember-cli-prop-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrystal-ball%2Fember-cli-prop-types/lists"}