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

Commit 9fddbcd

Browse files
committed
refactor(types): apiCheck as a function. Fix #40
1 parent f40f6b2 commit 9fddbcd

File tree

6 files changed

+45
-57
lines changed

6 files changed

+45
-57
lines changed

src/types/checkbox.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
export default ngModule => {
22
ngModule.config(addCheckboxType);
33

4-
function addCheckboxType(formlyConfigProvider, formlyBootstrapApiCheck) {
5-
const c = formlyBootstrapApiCheck;
4+
function addCheckboxType(formlyConfigProvider) {
65
formlyConfigProvider.setType({
76
name: 'checkbox',
87
template: require('./checkbox.html'),
98
wrapper: ['bootstrapHasError'],
10-
apiCheck: {
11-
templateOptions: c.shape({
12-
label: c.string
13-
})
14-
},
15-
apiCheckInstance: c
9+
apiCheck: check => ({
10+
templateOptions: {
11+
label: check.string
12+
}
13+
})
1614
});
1715
}
1816
};

src/types/multiCheckbox.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
export default ngModule => {
22
ngModule.config(addCheckboxType);
33

4-
function addCheckboxType(formlyConfigProvider, formlyBootstrapApiCheck) {
5-
const c = formlyBootstrapApiCheck;
4+
function addCheckboxType(formlyConfigProvider) {
65
formlyConfigProvider.setType({
76
name: 'multiCheckbox',
87
template: require('./multiCheckbox.html'),
98
wrapper: ['bootstrapLabel', 'bootstrapHasError'],
10-
apiCheck: {
11-
templateOptions: c.shape({
12-
options: c.arrayOf(c.object),
13-
labelProp: c.string.optional,
14-
valueProp: c.string.optional
15-
})
16-
},
9+
apiCheck: check => ({
10+
templateOptions: {
11+
options: check.arrayOf(check.object),
12+
labelProp: check.string.optional,
13+
valueProp: check.string.optional
14+
}
15+
}),
1716
defaultOptions: {
1817
noFormControl: false,
1918
ngModelAttrs: {
@@ -23,7 +22,6 @@ export default ngModule => {
2322
}
2423
}
2524
},
26-
apiCheckInstance: c,
2725
controller: /* @ngInject */ function($scope) {
2826
const to = $scope.to;
2927
const opts = $scope.options;

src/types/radio.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
export default ngModule => {
22
ngModule.config(addRadioType);
33

4-
function addRadioType(formlyConfigProvider, formlyBootstrapApiCheck) {
5-
const c = formlyBootstrapApiCheck;
4+
function addRadioType(formlyConfigProvider) {
65
formlyConfigProvider.setType({
76
name: 'radio',
87
template: require('./radio.html'),
98
wrapper: ['bootstrapLabel', 'bootstrapHasError'],
109
defaultOptions: {
1110
noFormControl: false
1211
},
13-
apiCheck: {
14-
templateOptions: c.shape({
15-
options: c.arrayOf(c.object),
16-
labelProp: c.string.optional,
17-
valueProp: c.string.optional
18-
})
19-
},
20-
apiCheckInstance: c
12+
apiCheck: check => ({
13+
templateOptions: {
14+
options: check.arrayOf(check.object),
15+
labelProp: check.string.optional,
16+
valueProp: check.string.optional
17+
}
18+
})
2119
});
2220
}
2321
};

src/types/select.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ export default ngModule => {
33

44
const template = `<select class="form-control" ng-model="model[options.key]"></select>`;
55

6-
function addSelectType(formlyConfigProvider, formlyBootstrapApiCheck) {
7-
const c = formlyBootstrapApiCheck;
6+
function addSelectType(formlyConfigProvider) {
87
formlyConfigProvider.setType({
98
name: 'select',
109
template,
@@ -20,15 +19,14 @@ export default ngModule => {
2019
}
2120
};
2221
},
23-
apiCheck: {
24-
templateOptions: c.shape({
25-
options: c.arrayOf(c.object),
26-
labelProp: c.string.optional,
27-
valueProp: c.string.optional,
28-
groupProp: c.string.optional
29-
})
30-
},
31-
apiCheckInstance: c
22+
apiCheck: check => ({
23+
templateOptions: {
24+
options: check.arrayOf(check.object),
25+
labelProp: check.string.optional,
26+
valueProp: check.string.optional,
27+
groupProp: check.string.optional
28+
}
29+
})
3230
});
3331
}
3432
};

src/types/textarea.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
export default ngModule => {
22
ngModule.config(addTextareaType);
33

4-
function addTextareaType(formlyConfigProvider, formlyBootstrapApiCheck) {
5-
const c = formlyBootstrapApiCheck;
4+
function addTextareaType(formlyConfigProvider) {
65
formlyConfigProvider.setType({
76
name: 'textarea',
87
template: '<textarea class="form-control" ng-model="model[options.key]"></textarea>',
@@ -13,13 +12,12 @@ export default ngModule => {
1312
cols: {attribute: 'cols'}
1413
}
1514
},
16-
apiCheck: {
17-
templateOptions: c.shape({
18-
rows: c.number.optional,
19-
cols: c.number.optional
20-
})
21-
},
22-
apiCheckInstance: c
15+
apiCheck: check => ({
16+
templateOptions: {
17+
rows: check.number.optional,
18+
cols: check.number.optional
19+
}
20+
})
2321
});
2422
}
2523
};

src/wrappers/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
export default ngModule => {
22
ngModule.config(addWrappers);
33

4-
function addWrappers(formlyConfigProvider, formlyBootstrapApiCheck) {
5-
const c = formlyBootstrapApiCheck;
4+
function addWrappers(formlyConfigProvider) {
65
formlyConfigProvider.setWrapper([
76
{
87
name: 'bootstrapLabel',
98
template: require('./label.html'),
10-
apiCheck: {
11-
templateOptions: c.shape({
12-
label: c.string,
13-
required: c.bool.optional
14-
})
15-
},
16-
apiCheckInstance: c
9+
apiCheck: check => ({
10+
templateOptions: {
11+
label: check.string,
12+
required: check.bool.optional
13+
}
14+
})
1715
},
1816
{name: 'bootstrapHasError', template: require('./has-error.html')}
1917
]);

0 commit comments

Comments
 (0)