Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 4f9d247

Browse files
author
Kent C. Dodds
committed
fix(validateOptions): Remove deprecated API
We now have api-check to validate options for types. This dual api was not helpful. BREAKING CHANGE: If you were using validateOptions, you'll need to switch to apiCheck
1 parent 9f2edcc commit 4f9d247

File tree

6 files changed

+1
-141
lines changed

6 files changed

+1
-141
lines changed

other/ERRORS_AND_WARNINGS.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ of the expression, the scope you're passed wont have all the properties you may
127127
See documentation [here](http://docs.angular-formly.com/docs/field-configuration-object#hideexpression-string--function)
128128
and an example [here](http://angular-formly.com/#/example/field-options/hide-fields)
129129

130-
# validateOptions deprecated
131-
132-
Because angular-formly already has a dependency on `api-check` and this is just a better way to validate your options,
133-
you should use this method instead. In an effort to simplify things. This has been deprecated in favor of the `apiCheck`
134-
property.
135-
136130
# skipNgModelAttrsManipulator moved
137131

138132
This property has been moved from the `data` property to the `extras` property.

src/directives/formly-field.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
564564

565565
wrapper.forEach((aWrapper) => {
566566
formlyUsability.checkWrapper(aWrapper, options);
567-
aWrapper.validateOptions && aWrapper.validateOptions(options);
568567
runApiCheck(aWrapper, options);
569568
});
570569
const promises = wrapper.map(w => getTemplate(w.template || w.templateUrl, !w.template));
@@ -639,9 +638,6 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
639638
// validate with the type
640639
const type = options.type && formlyConfig.getType(options.type);
641640
if (type) {
642-
if (type.validateOptions) {
643-
type.validateOptions(options);
644-
}
645641
runApiCheck(type, options, true);
646642
}
647643
if (options.expressionProperties && options.expressionProperties.hide) {

src/directives/formly-field.test.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,12 @@ describe('formly-field', function() {
102102

103103

104104
describe('api check', () => {
105-
let validateOptions;
106105
beforeEach(() => {
107106
/* eslint no-console:0 */
108107
const originalWarn = console.warn;
109108
console.warn = () => {};
110-
validateOptions = sinon.spy();
111109
formlyConfig.setType({
112-
name: 'text', template: `<input name="{{id}}" ng-model="model[options.key]" />`,
113-
validateOptions
110+
name: 'text', template: `<input name="{{id}}" ng-model="model[options.key]" />`
114111
});
115112
scope.model = {};
116113
console.warn = originalWarn;
@@ -127,13 +124,6 @@ describe('formly-field', function() {
127124

128125
expect(() => compileAndDigest()).to.throw(/extra.*properties.*extraProp/);
129126
});
130-
131-
it(`should invoke the validateOptions property of the type`, () => {
132-
const field = {type: 'text'};
133-
scope.fields = [field];
134-
compileAndDigest();
135-
expect(validateOptions).to.have.been.calledWith(field);
136-
});
137127
});
138128

139129
describe('default type options', () => {

src/providers/formlyApiCheck.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const formlyWrapperType = apiCheck.shape({
4949
templateUrl: apiCheck.shape.ifNot('template', apiCheck.string).optional,
5050
types: apiCheck.typeOrArrayOf(apiCheck.string).optional,
5151
overwriteOk: apiCheck.bool.optional,
52-
validateOptions: apiCheck.func.optional,
5352
apiCheck: apiCheckProperty.optional,
5453
apiCheckInstance: apiCheckInstanceProperty.optional,
5554
apiCheckFunction: apiCheckFunctionProperty.optional,
@@ -204,7 +203,6 @@ const formlyTypeOptions = apiCheck.shape({
204203
extends: apiCheck.string.optional,
205204
wrapper: specifyWrapperType.optional,
206205
data: apiCheck.object.optional,
207-
validateOptions: apiCheck.func.optional,
208206
apiCheck: apiCheckProperty.optional,
209207
apiCheckInstance: apiCheckInstanceProperty.optional,
210208
apiCheckFunction: apiCheckFunctionProperty.optional,

src/providers/formlyConfig.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
6161
prefix: 'formlyConfig.setType',
6262
url: 'settype-validation-failed'
6363
});
64-
checkDeprecatedOptions(options);
6564
if (!options.overwriteOk) {
6665
checkOverwrite(options.name, typeMap, options, 'types');
6766
} else {
@@ -73,7 +72,6 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
7372
const extendsType = getType(options.extends, true, options);
7473
extendTypeControllerFunction(options, extendsType);
7574
extendTypeLinkFunction(options, extendsType);
76-
extendTypeValidateOptionsFunction(options, extendsType);
7775
extendTypeDefaultOptions(options, extendsType);
7876
utils.reverseDeepMerge(options, extendsType);
7977
extendTemplate(options, extendsType);
@@ -120,31 +118,6 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
120118
}
121119
}
122120

123-
function extendTypeValidateOptionsFunction(options, extendsType) {
124-
const extendsFn = extendsType.validateOptions;
125-
if (!angular.isDefined(extendsFn)) {
126-
return;
127-
}
128-
const optionsFn = options.validateOptions;
129-
const originalDefaultOptions = options.defaultOptions;
130-
if (angular.isDefined(optionsFn)) {
131-
options.validateOptions = function(opts) {
132-
optionsFn(opts);
133-
const mergedOptions = angular.copy(opts);
134-
let defaultOptions = originalDefaultOptions;
135-
if (defaultOptions) {
136-
if (angular.isFunction(defaultOptions)) {
137-
defaultOptions = defaultOptions(mergedOptions);
138-
}
139-
utils.reverseDeepMerge(mergedOptions, defaultOptions);
140-
}
141-
extendsFn(mergedOptions);
142-
};
143-
} else {
144-
options.validateOptions = extendsFn;
145-
}
146-
}
147-
148121
function extendTypeDefaultOptions(options, extendsType) {
149122
const extendsDO = extendsType.defaultOptions;
150123
if (!angular.isDefined(extendsDO)) {
@@ -241,7 +214,6 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
241214
if (options.template) {
242215
formlyUsabilityProvider.checkWrapperTemplate(options.template, options);
243216
}
244-
checkDeprecatedOptions(options);
245217
if (!options.overwriteOk) {
246218
checkOverwrite(options.name, templateWrappersMap, options, 'templateWrappers');
247219
} else {
@@ -267,17 +239,6 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
267239
}
268240
}
269241

270-
function checkDeprecatedOptions(options) {
271-
if (options.validateOptions) {
272-
warn(
273-
'validateoptions-deprecated',
274-
'the `validateOptions` property has been deprecated.',
275-
`Attempted for type: ${options.name}`,
276-
options
277-
);
278-
}
279-
}
280-
281242
function getWrapper(name) {
282243
return templateWrappersMap[name || defaultWrapperName];
283244
}

src/providers/formlyConfig.test.js

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -424,85 +424,6 @@ describe('formlyConfig', () => {
424424

425425
});
426426

427-
describe(`validateOptions functions`, () => {
428-
let options, parentFn, childFn;
429-
beforeEach(() => {
430-
options = {
431-
data: {
432-
a: 'b',
433-
c: {d: 'e'}
434-
}
435-
};
436-
parentFn = sinon.spy();
437-
childFn = sinon.spy();
438-
});
439-
440-
it(`should give a deprecation warning when specified as part of a type`, () => {
441-
shouldWarn(
442-
/Formly Warning: the `validateOptions` property has been deprecated. Attempted for type: foobar/,
443-
function() {
444-
setterFn({
445-
name: 'foobar',
446-
validateOptions() {}
447-
});
448-
}
449-
);
450-
});
451-
452-
describe(`old functionality`, () => {
453-
let originalWarn;
454-
beforeEach(() => {
455-
originalWarn = console.warn;
456-
console.warn = () => {};
457-
});
458-
459-
it(`should call the parent validateOptions function when there is no child function`, () => {
460-
setterFn([
461-
{name, template, validateOptions: parentFn},
462-
{name: 'type2', extends: name}
463-
]);
464-
getterFn('type2').validateOptions(options);
465-
expect(parentFn).to.have.been.calledWith(options);
466-
});
467-
468-
it(`should call the child validateOptions function when there is no parent function`, () => {
469-
setterFn([
470-
{name, template},
471-
{name: 'type2', extends: name, validateOptions: childFn}
472-
]);
473-
getterFn('type2').validateOptions(options);
474-
expect(childFn).to.have.been.calledWith(options);
475-
});
476-
477-
it(`should call the child validateOptions function and the parent validateOptions function when they are both present`, () => {
478-
setterFn([
479-
{name, template, validateOptions: parentFn},
480-
{name: 'type2', extends: name, validateOptions: childFn}
481-
]);
482-
getterFn('type2').validateOptions(options);
483-
expect(childFn).to.have.been.calledWith(options);
484-
expect(parentFn).to.have.been.calledWith(options);
485-
});
486-
487-
it(`should pass the result of the child's defaultOptions with the given options to the parent's validateOptions function`, () => {
488-
const defaultOptions = {data: {f: 'g'}};
489-
const combinedOptions = {data: {a: 'b', c: {d: 'e'}, f: 'g'}};
490-
setterFn([
491-
{name, template, validateOptions: parentFn},
492-
{name: 'type2', extends: name, validateOptions: childFn, defaultOptions}
493-
]);
494-
getterFn('type2').validateOptions(options);
495-
expect(childFn).to.have.been.calledWith(options);
496-
expect(parentFn).to.have.been.calledWith(combinedOptions);
497-
});
498-
499-
afterEach(() => {
500-
console.warn = originalWarn;
501-
});
502-
});
503-
504-
});
505-
506427
describe(`controller functions`, () => {
507428
let parentFn, childFn, $controller, $scope;
508429
beforeEach(inject(($rootScope, _$controller_) => {

0 commit comments

Comments
 (0)