@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import { parseConfig } from "./fn"
|
||||
|
||||
export const UPDATE_CONFIGS = "configs_update"
|
||||
export const TOGGLE_CONFIGS = "configs_toggle"
|
||||
|
||||
@@ -6,7 +11,7 @@ export function update(configName, configValue) {
|
||||
return {
|
||||
type: UPDATE_CONFIGS,
|
||||
payload: {
|
||||
[configName]: configValue
|
||||
[configName]: configValue,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -19,8 +24,35 @@ export function toggle(configName) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Hook
|
||||
export const loaded = () => () => {
|
||||
// noop
|
||||
}
|
||||
|
||||
export const downloadConfig = (req) => (system) => {
|
||||
const {
|
||||
fn: { fetch },
|
||||
} = system
|
||||
|
||||
return fetch(req)
|
||||
}
|
||||
|
||||
export const getConfigByUrl = (req, cb) => (system) => {
|
||||
const { specActions, configsActions } = system
|
||||
|
||||
if (req) {
|
||||
return configsActions.downloadConfig(req).then(next, next)
|
||||
}
|
||||
|
||||
function next(res) {
|
||||
if (res instanceof Error || res.status >= 400) {
|
||||
specActions.updateLoadingStatus("failedConfig")
|
||||
specActions.updateLoadingStatus("failedConfig")
|
||||
specActions.updateUrl("")
|
||||
console.error(res.statusText + " " + req.url)
|
||||
cb(null)
|
||||
} else {
|
||||
cb(parseConfig(res.text, system))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import YAML from "js-yaml"
|
||||
|
||||
export const parseYamlConfig = (yaml, system) => {
|
||||
export const parseConfig = (yaml, system) => {
|
||||
try {
|
||||
return YAML.load(yaml)
|
||||
} catch(e) {
|
||||
@@ -1,25 +1,11 @@
|
||||
import yamlConfig from "root/swagger-config.yaml"
|
||||
import { parseYamlConfig } from "./helpers"
|
||||
import * as actions from "./actions"
|
||||
import * as specActions from "./spec-actions"
|
||||
import * as selectors from "./selectors"
|
||||
import reducers from "./reducers"
|
||||
|
||||
const specSelectors = {
|
||||
getLocalConfig: () => {
|
||||
return parseYamlConfig(yamlConfig)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default function configsPlugin() {
|
||||
|
||||
return {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
actions: specActions,
|
||||
selectors: specSelectors,
|
||||
},
|
||||
configs: {
|
||||
reducers,
|
||||
actions,
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { parseYamlConfig } from "./helpers"
|
||||
|
||||
export const downloadConfig = (req) => (system) => {
|
||||
const {fn: { fetch }} = system
|
||||
|
||||
return fetch(req)
|
||||
}
|
||||
|
||||
export const getConfigByUrl = (req, cb)=> ({ specActions }) => {
|
||||
if (req) {
|
||||
return specActions.downloadConfig(req).then(next, next)
|
||||
}
|
||||
|
||||
function next(res) {
|
||||
if (res instanceof Error || res.status >= 400) {
|
||||
specActions.updateLoadingStatus("failedConfig")
|
||||
specActions.updateLoadingStatus("failedConfig")
|
||||
specActions.updateUrl("")
|
||||
console.error(res.statusText + " " + req.url)
|
||||
cb(null)
|
||||
} else {
|
||||
cb(parseYamlConfig(res.text))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user