Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
1.0 KiB

// import isObject from "lodash/fp/isObject"
import set from "lodash/fp/set";
import { parseBinding } from "./parseBinding"
export const setState = (store, path, value) => {
if (!path || path.length === 0) return
// const pathParts = path.split(".")
// const safeSetPath = (state, currentPartIndex = 0) => {
// const currentKey = pathParts[currentPartIndex]
// if (pathParts.length - 1 == currentPartIndex) {
// state[currentKey] = value
// return
// }
// if (
// state[currentKey] === null ||
// state[currentKey] === undefined ||
// !isObject(state[currentKey])
// ) {
// state[currentKey] = {}
// }
// safeSetPath(state[currentKey], currentPartIndex + 1)
// }
store.update(state => {
// safeSetPath(state)
state = set(path, value, state);
return state
})
}
export const setStateFromBinding = (store, binding, value) => {
const parsedBinding = parseBinding(binding)
if (!parsedBinding) return
return setState(store, parsedBinding.path, value)
}