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

Commit 2f81ba5

Browse files
committedMar 20, 2016
feat(formlyConfigProvider): Expose field types map from formlyConfigProvider
For a plugin I am writing that renders an inspector showing the current configuration for formly, I need access to the types that have been registered with formly. This change exposes the map of type name to type configuration object via a new method on formlyConfigProvider called getTypes(). This is in support of issue #663
1 parent 4fda1ed commit 2f81ba5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
 

Diff for: ‎src/providers/formlyConfig.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
1515
angular.extend(this, {
1616
setType,
1717
getType,
18+
getTypes,
1819
getTypeHeritage,
1920
setWrapper,
2021
getWrapper,
@@ -161,6 +162,10 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
161162
}
162163
}
163164

165+
function getTypes() {
166+
return typeMap
167+
}
168+
164169
function getTypeHeritage(parent) {
165170
const heritage = []
166171
let type = parent

Diff for: ‎src/providers/formlyConfig.test.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ describe('formlyConfig', () => {
185185
})
186186

187187

188-
describe('setType/getType', () => {
189-
let getterFn, setterFn
188+
describe('setType/getType/getTypes', () => {
189+
let getterFn, setterFn, getTypesFn
190190
const name = 'input'
191191
const template = '<input type="{{options.inputType}}" />'
192192
const templateUrl = '/input.html'
@@ -195,6 +195,7 @@ describe('formlyConfig', () => {
195195
beforeEach(inject(function(formlyConfig) {
196196
getterFn = formlyConfig.getType
197197
setterFn = formlyConfig.setType
198+
getTypesFn = formlyConfig.getTypes
198199
}))
199200

200201
describe('\(^O^)/ path', () => {
@@ -217,6 +218,14 @@ describe('formlyConfig', () => {
217218
expect(getterFn('type2').templateUrl).to.equal(templateUrl)
218219
})
219220

221+
it('should expose the mapping from type name to config', () => {
222+
setterFn([
223+
{name, template},
224+
{name: 'type2', templateUrl},
225+
])
226+
expect(getTypesFn()).to.eql({[name]: getterFn(name), type2: getterFn('type2')})
227+
})
228+
220229
it('should allow you to set a wrapper as a string', () => {
221230
setterFn({name, template, wrapper})
222231
expect(getterFn(name).wrapper).to.equal(wrapper)

0 commit comments

Comments
 (0)