angular-scope-types
Advanced tools
Comparing version 1.0.0-beta.4 to 1.0.0-beta.5
@@ -0,1 +1,12 @@ | ||
# 1.0.0-beta.5 | ||
## Breaking Changes | ||
- Now, if a checker is not optional, the api-check for it will be evaluated immediately. | ||
## New Features | ||
- Adding `displayName` for the wrapper controller for error messaging and debugging. | ||
- Adding `scopeTypesFunction` to the `ddo` to allow you to specify `warn` or `throw`. | ||
# 1.0.0-beta.4 | ||
@@ -2,0 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
// angular-scope-types version 1.0.0-beta.4 built with ♥ by Kent C. Dodds <kent@doddsfamily.us> (http://kent.doddsfamily.us) (ó ì_í)=óò=(ì_í ò) | ||
//! angular-scope-types version 1.0.0-beta.5 built with ♥ by Kent C. Dodds <kent@doddsfamily.us> (http://kent.doddsfamily.us) (ó ì_í)=óò=(ì_í ò) | ||
@@ -152,3 +152,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
_angularFix2['default'].forEach(typeDefinitions, function (check, name) { | ||
if (!_angularFix2['default'].isDefined(context[name])) { | ||
if (!_angularFix2['default'].isDefined(context[name]) && check.isOptional) { | ||
(function () { | ||
@@ -169,3 +169,3 @@ var prefix = ddo.controllerAs ? ddo.controllerAs + '.' : ''; | ||
function checkOption(checker, name) { | ||
$scope.$scopeTypesResults[name] = apiCheckInstance.warn(checker, context[name], { prefix: '' + ddo.name + 'Directive for "' + name + '"' }); | ||
$scope.$scopeTypesResults[name] = apiCheckInstance[ddo.scopeTypesFunction || 'warn'](checker, context[name], { prefix: '' + ddo.name + 'Directive for "' + name + '"' }); | ||
updateData(); | ||
@@ -205,4 +205,14 @@ } | ||
wrappedController.$inject = ['$scope', '$controller', '$element', '$attrs', '$transclude', '$injector']; | ||
wrappedController.displayName = getWrappedControllerDisplayName(originalController); | ||
return wrappedController; | ||
} | ||
function getWrappedControllerDisplayName(originalController) { | ||
var originalControllerName = originalController.displayName || originalController.name; | ||
var name = 'angular-scope-types controller wrapper'; | ||
if (originalControllerName) { | ||
name = '' + name + ' for ' + originalControllerName; | ||
} | ||
return name; | ||
} | ||
} | ||
@@ -233,3 +243,3 @@ } | ||
/* 3 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ function(module, exports) { | ||
@@ -240,3 +250,3 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_3__; | ||
/* 4 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ function(module, exports) { | ||
@@ -383,2 +393,3 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_4__; | ||
scopeTypes: check.func, | ||
scopeTypesFunction: check.oneOf(['warn', 'throw']).optional, | ||
data: check.object.optional | ||
@@ -394,3 +405,3 @@ }).strict; | ||
/* 8 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ function(module, exports) { | ||
@@ -397,0 +408,0 @@ "use strict"; |
@@ -1,4 +0,3 @@ | ||
// angular-scope-types version 1.0.0-beta.4 built with ♥ by Kent C. Dodds <kent@doddsfamily.us> (http://kent.doddsfamily.us) (ó ì_í)=óò=(ì_í ò) | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("api-check"),require("angular")):"function"==typeof define&&define.amd?define(["api-check","angular"],t):"object"==typeof exports?exports.angularScopeTypes=t(require("api-check"),require("angular")):e.angularScopeTypes=t(e.apiCheck,e.angular)}(this,function(e,t){return function(e){function t(r){if(o[r])return o[r].exports;var n=o[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=o(7),a=r(n);t["default"]=a["default"],e.exports=t["default"]},function(t,o,r){t.exports=e},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=o(8);r.version||(r=window.angular),t["default"]=r,e.exports=t["default"]},function(e,t,o){"use strict";function r(){}Object.defineProperty(t,"__esModule",{value:!0}),r.nullable=r,r.nullable.optional=r,t["default"]={noopChecker:r},e.exports=t["default"]},function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function n(){var e=void 0===arguments[0]?{strictDi:!1,disabled:!1}:arguments[0],t=e.scopeTypes,o=(e.strictDi,e.disabled),r=void 0===o?!1:o;if(r)return i["default"].noopChecker;var n=t;if(!n)throw new Error("Must provide an instance of scopeTypes");var a=t.oneOfType([n.string,n.func]),u=n.shape({priority:n.number.optional,template:n.shape.ifNot("templateUrl",a).optional,templateUrl:n.shape.ifNot("template",n.string).optional,transclude:n.bool.optional,restrict:n.oneOf(["A","E","C","AE","EA","AEC","AC","EC"]).optional,templateNamespace:n.oneOf(["html","svg","math"]).optional,scope:n.oneOfType([n.bool,n.objectOf(n.string)]).optional,controller:n.injectableFunction.optional,controllerAs:n.string.optional,bindToController:n.oneOfType([n.bool,n.objectOf(n.string)]).optional,require:n.typeOrArrayOf(n.string).optional,compile:n.func.optional,link:n.oneOfType([n.func,n.shape({pre:n.func.optional,post:n.func.optional}).strict]).optional,scopeTypes:n.func,data:n.object.optional}).strict;return n.oneOfType([n.func,u])}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n;var a=o(3),i=r(a);e.exports=t["default"]},function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=o(6),a=r(n),i=o(4),u=r(i);t["default"]={injectableFunction:a["default"],ddo:u["default"]},e.exports=t["default"]},function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function n(){var e=void 0===arguments[0]?{strictDi:!1,disabled:!1}:arguments[0],t=e.strictDi,o=void 0===t?!1:t,r=e.disabled,n=void 0===r?!1:r,a=i["default"].func.withProperties({$inject:i["default"].arrayOf(i["default"].string)}),u=i["default"].utils.checkerHelpers.setupChecker(function(e,t,o){if(!Array.isArray(e))return i["default"].utils.getError(t,o,i["default"].array.type);var r=e.slice(),n=r.pop(),a=i["default"].arrayOf(i["default"].string),u=a(r);return i["default"].utils.isError(u)?i["default"].utils.getError(t,o,a.type):"function"!=typeof n?i["default"].utils.getError(t,o,i["default"].func.type):void 0},{type:"angular injectable function (array syntax)"},n),l=[a,u];return o||l.push(i["default"].func),i["default"].oneOfType(l)}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n;var a=o(1),i=r(a);e.exports=t["default"]},function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function n(){function e(e){function t(t){function o(o,a){t.$scopeTypesResults[a]=u.warn(o,n[a],{prefix:""+e.name+'Directive for "'+a+'"'}),r()}function r(){var e=0,o=0,r=["__passed","__failed"];i["default"].forEach(t.$scopeTypesResults,function(t,n){-1===r.indexOf(n)&&(t.passed?e++:o++)}),t.$scopeTypesResults.__passed=e,t.$scopeTypesResults.__failed=o}var n=t;e.bindToController&&(n=n[e.controllerAs]);var a=e.scopeTypes(u);s.warn(s.objectOf(s.func).optional,a,{prefix:"getting scope types for "+e.name}),t.$scopeTypesResults={__passed:0,__failed:0},i["default"].forEach(a,function(r,a){i["default"].isDefined(n[a])?o(r,a):!function(){var n=e.controllerAs?e.controllerAs+".":"",i=t.$watch(""+n+a,function(e,t){e!==t&&(i(),o(r,a))})}()})}function o(e,t){function o(o,r,n,a,i,u){var l={$scope:o,$element:n,$attrs:a,$transclude:i};u.invoke(t,this,l),u.invoke(e,this,l)}return i["default"].isDefined(e)?(o.$inject=["$scope","$controller","$element","$attrs","$transclude","$injector"],o):t}return s.config.disabled||u.config.disabled?e:(s.warn(s.ddo,e,{prefix:"creating directive with scopeTypes"}),e.controller=o(e.controller,t),t.$inject=["$scope"],e)}var t=void 0===arguments[0]?{disabled:!1,output:f,apiCheckInstance:void 0}:arguments[0],o=t.disabled,r=void 0===o?!1:o,n=t.output,a=void 0===n?f:n,u=t.apiCheckInstance,s=l["default"]({output:a,disabled:r});return i["default"].forEach(c["default"],function(e,t){s[t]=e({scopeTypes:s,disabled:r})}),s.directive=e,u=u||s,s}Object.defineProperty(t,"__esModule",{value:!0});var a=o(2),i=r(a),u=o(1),l=r(u),s=o(5),c=r(s),f={prefix:"angular-scope-types"};t["default"]=n,e.exports=t["default"]},function(e,o,r){e.exports=t}])}); | ||
//! angular-scope-types version 1.0.0-beta.5 built with ♥ by Kent C. Dodds <kent@doddsfamily.us> (http://kent.doddsfamily.us) (ó ì_í)=óò=(ì_í ò) | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("api-check"),require("angular")):"function"==typeof define&&define.amd?define(["api-check","angular"],t):"object"==typeof exports?exports.angularScopeTypes=t(require("api-check"),require("angular")):e.angularScopeTypes=t(e.apiCheck,e.angular)}(this,function(e,t){return function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=o(7),a=n(r);t["default"]=a["default"],e.exports=t["default"]},function(t,o){t.exports=e},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=o(8);n.version||(n=window.angular),t["default"]=n,e.exports=t["default"]},function(e,t){"use strict";function o(){}Object.defineProperty(t,"__esModule",{value:!0}),o.nullable=o,o.nullable.optional=o,t["default"]={noopChecker:o},e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(){var e=void 0===arguments[0]?{strictDi:!1,disabled:!1}:arguments[0],t=e.scopeTypes,o=(e.strictDi,e.disabled),n=void 0===o?!1:o;if(n)return i["default"].noopChecker;var r=t;if(!r)throw new Error("Must provide an instance of scopeTypes");var a=t.oneOfType([r.string,r.func]),u=r.shape({priority:r.number.optional,template:r.shape.ifNot("templateUrl",a).optional,templateUrl:r.shape.ifNot("template",r.string).optional,transclude:r.bool.optional,restrict:r.oneOf(["A","E","C","AE","EA","AEC","AC","EC"]).optional,templateNamespace:r.oneOf(["html","svg","math"]).optional,scope:r.oneOfType([r.bool,r.objectOf(r.string)]).optional,controller:r.injectableFunction.optional,controllerAs:r.string.optional,bindToController:r.oneOfType([r.bool,r.objectOf(r.string)]).optional,require:r.typeOrArrayOf(r.string).optional,compile:r.func.optional,link:r.oneOfType([r.func,r.shape({pre:r.func.optional,post:r.func.optional}).strict]).optional,scopeTypes:r.func,scopeTypesFunction:r.oneOf(["warn","throw"]).optional,data:r.object.optional}).strict;return r.oneOfType([r.func,u])}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r;var a=o(3),i=n(a);e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=o(6),a=n(r),i=o(4),u=n(i);t["default"]={injectableFunction:a["default"],ddo:u["default"]},e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(){var e=void 0===arguments[0]?{strictDi:!1,disabled:!1}:arguments[0],t=e.strictDi,o=void 0===t?!1:t,n=e.disabled,r=void 0===n?!1:n,a=i["default"].func.withProperties({$inject:i["default"].arrayOf(i["default"].string)}),u=i["default"].utils.checkerHelpers.setupChecker(function(e,t,o){if(!Array.isArray(e))return i["default"].utils.getError(t,o,i["default"].array.type);var n=e.slice(),r=n.pop(),a=i["default"].arrayOf(i["default"].string),u=a(n);return i["default"].utils.isError(u)?i["default"].utils.getError(t,o,a.type):"function"!=typeof r?i["default"].utils.getError(t,o,i["default"].func.type):void 0},{type:"angular injectable function (array syntax)"},r),l=[a,u];return o||l.push(i["default"].func),i["default"].oneOfType(l)}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r;var a=o(1),i=n(a);e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(){function e(e){function t(t){function o(o,a){t.$scopeTypesResults[a]=u[e.scopeTypesFunction||"warn"](o,r[a],{prefix:""+e.name+'Directive for "'+a+'"'}),n()}function n(){var e=0,o=0,n=["__passed","__failed"];i["default"].forEach(t.$scopeTypesResults,function(t,r){-1===n.indexOf(r)&&(t.passed?e++:o++)}),t.$scopeTypesResults.__passed=e,t.$scopeTypesResults.__failed=o}var r=t;e.bindToController&&(r=r[e.controllerAs]);var a=e.scopeTypes(u);s.warn(s.objectOf(s.func).optional,a,{prefix:"getting scope types for "+e.name}),t.$scopeTypesResults={__passed:0,__failed:0},i["default"].forEach(a,function(n,a){!i["default"].isDefined(r[a])&&n.isOptional?!function(){var r=e.controllerAs?e.controllerAs+".":"",i=t.$watch(""+r+a,function(e,t){e!==t&&(i(),o(n,a))})}():o(n,a)})}function o(e,t){function o(o,n,r,a,i,u){var l={$scope:o,$element:r,$attrs:a,$transclude:i};u.invoke(t,this,l),u.invoke(e,this,l)}return i["default"].isDefined(e)?(o.$inject=["$scope","$controller","$element","$attrs","$transclude","$injector"],o.displayName=n(e),o):t}function n(e){var t=e.displayName||e.name,o="angular-scope-types controller wrapper";return t&&(o=""+o+" for "+t),o}return s.config.disabled||u.config.disabled?e:(s.warn(s.ddo,e,{prefix:"creating directive with scopeTypes"}),e.controller=o(e.controller,t),t.$inject=["$scope"],e)}var t=void 0===arguments[0]?{disabled:!1,output:f,apiCheckInstance:void 0}:arguments[0],o=t.disabled,n=void 0===o?!1:o,r=t.output,a=void 0===r?f:r,u=t.apiCheckInstance,s=l["default"]({output:a,disabled:n});return i["default"].forEach(c["default"],function(e,t){s[t]=e({scopeTypes:s,disabled:n})}),s.directive=e,u=u||s,s}Object.defineProperty(t,"__esModule",{value:!0});var a=o(2),i=n(a),u=o(1),l=n(u),s=o(5),c=n(s),f={prefix:"angular-scope-types"};t["default"]=r,e.exports=t["default"]},function(e,o){e.exports=t}])}); | ||
//# sourceMappingURL=angular-scope-types.min.js.map |
106
package.json
{ | ||
"name": "angular-scope-types", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0-beta.5", | ||
"description": "checkers and other utilities for using api-check with angular", | ||
"main": "dist/angular-scope-types.js", | ||
"scripts": { | ||
"build:dist": "NODE_ENV=development webpack --progress --colors", | ||
"build:prod": "NODE_ENV=production webpack --progress --colors", | ||
"build:test": "NODE_ENV=test webpack --progress --colors --watch", | ||
"build:test:single": "NODE_ENV=test webpack --progress --colors", | ||
"build:test:ci": "NODE_ENV=test:ci webpack --progress --colors", | ||
"build": "npm run build:dist; npm run build:prod", | ||
"ci": "npm run code-checks && npm run test:ci && npm run check-coverage && npm run build", | ||
"test": "npm run build:test & NODE_ENV=test node node_modules/karma/bin/karma start karma.conf.js", | ||
"test:single": "npm run build:test:single && NODE_ENV=test node node_modules/karma/bin/karma start karma.conf.js --single-run", | ||
"test:ci": "npm run build:test:ci && NODE_ENV=test:ci node node_modules/karma/bin/karma start karma.conf.js", | ||
"watch": "NODE_ENV=development webpack --watch --progress --colors", | ||
"start": "npm run test", | ||
"check-coverage": "COVERAGE=true npm run test:single && ./node_modules/istanbul/lib/cli.js check-coverage --statements 96 --branches 78 --functions 99 --lines 97", | ||
"coveralls": "cat coverage/lcov.info | coveralls", | ||
"only-check": "node scripts/only-check.js", | ||
"console-check": "node scripts/console-check.js", | ||
"code-checks": "npm run only-check && npm run console-check", | ||
"release": "git push && npm publish && git push --tags", | ||
"release:beta": "git push && npm publish --tag beta && git push --tags" | ||
"test": "COVERAGE=true NODE_ENV=test karma start", | ||
"test:single": "COVERAGE=true NODE_ENV=test karma start --single-run", | ||
"test:debug": "echo 'WARNING: This is currently not working quite right...' && NODE_ENV=test karma start --browsers Chrome", | ||
"build:dist": "NODE_ENV=development webpack --config node_modules/kcd-common-tools/shared/webpack.config.js --progress --colors", | ||
"build:prod": "NODE_ENV=production webpack --config node_modules/kcd-common-tools/shared/webpack.config.js --progress --colors", | ||
"build": "npm run build:dist & npm run build:prod", | ||
"ci": "npm run code-checks && npm run test:single && npm run check-coverage && npm run build", | ||
"check-coverage": "./node_modules/istanbul/lib/cli.js check-coverage --statements 97 --branches 89 --functions 100 --lines 95", | ||
"report-coverage": "cat ./coverage/lcov.info | codecov", | ||
"deploy": "npm run deployClean && npm run deployCopy && npm run deploySurge", | ||
"deploySurge": "surge -p deploy.ignored -d angular-scope-types.surge.sh", | ||
"deployCopy": "cp demo/{index.html,script.js} deploy.ignored/ && cp dist/angular-scope-types.js deploy.ignored/ && cp node_modules/angular/angular.js deploy.ignored/ && cp node_modules/api-check/dist/api-check.js deploy.ignored/", | ||
"deployClean": "rm -rf deploy.ignored/ && mkdir deploy.ignored/", | ||
"only-check": "node node_modules/kcd-common-tools/shared/scripts/only-check.js", | ||
"code-checks": "eslint src/ && npm run only-check", | ||
"release": "npm run build && with-package git commit -am pkg.version && with-package git tag pkg.version && git push && npm publish && git push --tags", | ||
"release:beta": "npm run release && npm run tag:beta", | ||
"tag:beta": "with-package npm dist-tag add pkg.name@pkg.version beta" | ||
}, | ||
@@ -59,35 +59,39 @@ "repository": { | ||
"devDependencies": { | ||
"angular": "^1.3.15", | ||
"angular-mocks": "^1.4.0", | ||
"api-check": "^7.2.0", | ||
"async": "^0.9.0", | ||
"babel-core": "^5.1.13", | ||
"babel-eslint": "^3.0.1", | ||
"babel-loader": "^5.0.0", | ||
"chai": "^2.2.0", | ||
"chalk": "^1.0.0", | ||
"coveralls": "^2.11.2", | ||
"deep-extend": "^0.3.3", | ||
"eslint": "^0.19.0", | ||
"eslint-loader": "^0.10.0", | ||
"ghooks": "^0.3.2", | ||
"glob": "^5.0.5", | ||
"istanbul": "^0.3.13", | ||
"karma": "^0.12.31", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^0.1.8", | ||
"karma-coverage": "^0.3.1", | ||
"karma-firefox-launcher": "^0.1.4", | ||
"karma-mocha": "^0.1.10", | ||
"karma-sinon": "^1.0.4", | ||
"karma-sourcemap-loader": "^0.3.4", | ||
"karma-webpack": "^1.5.0", | ||
"lodash": "^3.7.0", | ||
"mocha": "^2.2.4", | ||
"ng-annotate-loader": "0.0.2", | ||
"sinon-chai": "^2.6.0", | ||
"webpack": "^1.8.9", | ||
"webpack-core": "^0.6.5", | ||
"webpack-notifier": "^1.2.1" | ||
"angular": "1.4.1", | ||
"angular-mocks": "1.4.1", | ||
"api-check": "7.5.0", | ||
"babel": "5.5.8", | ||
"babel-core": "5.5.8", | ||
"babel-eslint": "3.1.17", | ||
"babel-loader": "5.1.4", | ||
"chai": "2.1.0", | ||
"codecov.io": "0.1.4", | ||
"eslint": "0.23.0", | ||
"eslint-loader": "0.14.0", | ||
"ghooks": "0.2.4", | ||
"isparta": "3.0.3", | ||
"isparta-loader": "0.2.0", | ||
"istanbul": "0.3.5", | ||
"karma": "0.12.36", | ||
"karma-chai": "0.1.0", | ||
"karma-chrome-launcher": "0.1.12", | ||
"karma-coverage": "0.4.2", | ||
"karma-firefox-launcher": "0.1.6", | ||
"karma-mocha": "0.1.10", | ||
"karma-sinon": "1.0.4", | ||
"karma-webpack": "1.5.1", | ||
"kcd-common-tools": "1.0.0-beta.9", | ||
"lodash": "3.9.3", | ||
"mocha": "2.1.0", | ||
"node-libs-browser": "^0.5.2", | ||
"sinon": "1.15.3", | ||
"surge": "0.14.2", | ||
"uglify-loader": "1.2.0", | ||
"webpack": "1.9.11", | ||
"with-package": "0.2.0" | ||
}, | ||
"kcdCommon": { | ||
"webpack": "scripts/webpack-overrides.js", | ||
"karma": "scripts/karma-overrides.js" | ||
} | ||
} |
# angular-scope-types | ||
[![Build Status](https://img.shields.io/travis/alianza-dev/angular-scope-types.svg?style=flat-square)](https://travis-ci.org/alianza-dev/angular-scope-types) | ||
[![npm version](https://img.shields.io/npm/v/angular-scope-types.svg?style=flat-square)](https://www.npmjs.org/package/angular-formly) | ||
[![npm downloads](https://img.shields.io/npm/dm/angular-scope-types.svg?style=flat-square)](http://npm-stat.com/charts.html?package=angular-scope-types) | ||
[![Build Status](https://snap-ci.com/alianza-dev/angular-scope-types/branch/master/build_image)](https://snap-ci.com/alianza-dev/angular-scope-types/branch/master) | ||
[![Code Coverage](https://img.shields.io/codecov/c/github/alianza-dev/angular-scope-types.svg?style=flat-square)](https://codecov.io/github/alianza-dev/angular-scope-types) | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/alianza-dev/angular-scope-types?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
This is still in the early stages. Wont be pushed to `npm` or `bower` until it's ready to go. Basically this is intended | ||
## [Demo](http://angular-scope-types.surge.sh/) | ||
This is still in the early stages. This is currently available as a beta on `npm`. Basically this is intended | ||
to bring a concept like React `propTypes` to Angular. | ||
@@ -11,5 +16,1 @@ | ||
as possible. | ||
Here's the [prototype](http://jsbin.com/vimude/edit?html,js,console,output). This is going to be great :-) | ||
Let me know in the issues or on gitter if you want to help out! |
@@ -40,2 +40,3 @@ import checkerUtils from './checkerUtils'; | ||
scopeTypes: check.func, | ||
scopeTypesFunction: check.oneOf(['warn', 'throw']).optional, | ||
data: check.object.optional | ||
@@ -42,0 +43,0 @@ }).strict; |
@@ -1,2 +0,2 @@ | ||
import {expectPass, expectFail, link, controllers} from '../test-utils'; | ||
import {expectPass, expectFail, link, controllers} from '../test.utils'; | ||
import scopeTypesFactory from '../scopeTypes'; | ||
@@ -3,0 +3,0 @@ |
import {expect} from 'chai'; | ||
import {expectPass, expectFail, controllers} from '../test-utils'; | ||
import {expectPass, expectFail, controllers} from '../test.utils'; | ||
import injectableFunction from './injectableFunction'; | ||
@@ -4,0 +4,0 @@ |
@@ -59,3 +59,3 @@ import angular from 'angular-fix'; | ||
angular.forEach(typeDefinitions, (check, name) => { | ||
if (!angular.isDefined(context[name])) { | ||
if (!angular.isDefined(context[name]) && check.isOptional) { | ||
let prefix = ddo.controllerAs ? ddo.controllerAs + '.' : ''; | ||
@@ -75,3 +75,3 @@ const stopWatching = $scope.$watch(`${prefix}${name}`, (value, oldValue) => { | ||
function checkOption(checker, name) { | ||
$scope.$scopeTypesResults[name] = apiCheckInstance.warn( | ||
$scope.$scopeTypesResults[name] = apiCheckInstance[ddo.scopeTypesFunction || 'warn']( | ||
checker, context[name], {prefix: `${ddo.name}Directive for "${name}"`} | ||
@@ -115,5 +115,15 @@ ); | ||
wrappedController.$inject = ['$scope', '$controller', '$element', '$attrs', '$transclude', '$injector']; | ||
wrappedController.displayName = getWrappedControllerDisplayName(originalController); | ||
return wrappedController; | ||
} | ||
function getWrappedControllerDisplayName(originalController) { | ||
const originalControllerName = originalController.displayName || originalController.name; | ||
let name = 'angular-scope-types controller wrapper'; | ||
if (originalControllerName) { | ||
name = `${name} for ${originalControllerName}`; | ||
} | ||
return name; | ||
} | ||
} | ||
} |
@@ -5,3 +5,2 @@ /* eslint no-console:0 */ | ||
import angular from 'angular-fix'; | ||
import sinon from 'sinon'; | ||
import apiCheck from 'api-check'; | ||
@@ -31,3 +30,3 @@ | ||
const basicTemplate = '<scope-type-dir foo="foo" bar="barString"></scope-type-dir>'; | ||
const basicTemplate = '<scope-type-dir foo="foo" bar="barString" baz="baz"></scope-type-dir>'; | ||
@@ -37,2 +36,3 @@ it(`should allow me to create a type checked directive`, () => { | ||
compileAndDigest({ | ||
baz: 'hi', | ||
foo: {isFoo: true, isBar: false, someNum: 23} | ||
@@ -46,2 +46,3 @@ }); | ||
compileAndDigest({ | ||
baz: 'hi', | ||
foo: {isFoo: 'not a boolean', isBar: false, someNum: 23} | ||
@@ -52,2 +53,11 @@ }); | ||
it(`should warn if something that is not optional is not passed`, () => { | ||
createDirective(); | ||
compileAndDigest({ | ||
// missing baz | ||
}); | ||
expectWarning(/Required/); | ||
}); | ||
it(`should be able to be disabled`, () => { | ||
@@ -60,3 +70,5 @@ const myDisabledScopeTypes = scopeTypesFactory({disabled: true}); | ||
compileAndDigest({}, '<dir-name></dir-name>'); | ||
compileAndDigest({ | ||
baz: 'hi' | ||
}, '<dir-name></dir-name>'); | ||
@@ -85,3 +97,3 @@ angular.mock.inject(['$injector', $injector => { | ||
} | ||
compileAndDigest(); | ||
compileAndDigest({baz: 'hey'}); | ||
expectNoWarning(); | ||
@@ -103,2 +115,8 @@ }); | ||
it(`should allow you to pass your own scopeTypesFunction function`, () => { | ||
createDirective(undefined, {scopeTypesFunction: 'throw'}); | ||
expect(() => compileAndDigest({})).to.throw(); | ||
expectNoWarning(); | ||
}); | ||
function createDirective(name, definition, scopeTypesInstance = scopeTypes) { | ||
@@ -110,3 +128,3 @@ angular.mock.module(['$provide', '$compileProvider', function($provide, $compileProvider) { | ||
template: 'foo', | ||
scope: {foo: '=', bar: '@'}, | ||
scope: {foo: '=', bar: '@', baz: '='}, | ||
scopeTypes: getScopeTypes, | ||
@@ -139,4 +157,5 @@ controllerAs: 'vm', | ||
someOptional: st.object.optional | ||
}).strict, | ||
bar: st.oneOf(['fooString', 'barString']).optional | ||
}).strict.optional, | ||
bar: st.oneOf(['fooString', 'barString']).optional, | ||
baz: st.string | ||
}; | ||
@@ -156,3 +175,5 @@ } | ||
function expectWarning(warning) { | ||
expect(warnings).to.have.length(1); | ||
if (!warnings.length) { | ||
throw new Error('Expected a warning, but non was logged'); | ||
} | ||
expect(warnings[0]).to.have.length(1); | ||
@@ -163,5 +184,8 @@ expect(warnings[0][0]).to.match(warning); | ||
function expectNoWarning() { | ||
expect(warnings).to.have.length(0); | ||
if (warnings.length) { | ||
console.log(warnings); | ||
throw new Error('Expected no warning to be logged, but one was'); | ||
} | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
79703
23
854
16