本文整理汇总了TypeScript中src/onboarding/utils/pluginConfigs.createNewPlugin函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createNewPlugin函数的具体用法?TypeScript createNewPlugin怎么用?TypeScript createNewPlugin使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createNewPlugin函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getConfigFields
telegrafPlugins: state.telegrafPlugins.map(tp => {
const name = _.get(tp, 'name')
if (name === action.payload.telegrafPlugin) {
const configFields = getConfigFields(name)
if (!configFields) {
return {...tp, configured: ConfigurationState.Configured}
}
const {config} = getDeep<Plugin>(
tp,
'plugin',
createNewPlugin(name)
)
let isValidConfig = true
Object.entries(configFields).forEach(
([fieldName, {type: fieldType, isRequired}]) => {
if (isRequired) {
const fieldValue = config[fieldName]
switch (fieldType) {
case ConfigFieldType.Uri:
isValidConfig = validateURI(fieldValue as string)
break
case ConfigFieldType.String:
isValidConfig = (fieldValue as string) !== ''
break
case ConfigFieldType.StringArray:
isValidConfig = !!(fieldValue as string[]).length
break
case ConfigFieldType.UriArray:
isValidConfig =
!!(fieldValue as string[]).length &&
!fieldValue.find(uri => !validateURI(uri))
break
}
}
}
)
if (!isValidConfig || _.isEmpty(config)) {
return {
...tp,
configured: ConfigurationState.InvalidConfiguration,
}
} else {
return {...tp, configured: ConfigurationState.Configured}
}
}
return {...tp}
}),
示例2: createNewPlugin
telegrafPlugins: state.telegrafPlugins.map(tp => {
if (tp.name === action.payload.name) {
const plugin = _.get(tp, 'plugin', createNewPlugin(tp.name))
return {
...tp,
plugin: updateConfigFields(
plugin,
action.payload.field,
action.payload.value
),
}
}
return tp
}),