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.
 
 
 
 
 
 

34 lines
897 B

import { writable } from "svelte/store"
import { cloneDeep } from "lodash/fp"
export const createContextStore = existingContext => {
const store = writable({ ...existingContext })
// Adds a data context layer to the tree
const provideData = (componentId, data) => {
store.update(state => {
if (componentId) {
state[componentId] = data
state[`${componentId}_draft`] = cloneDeep(data)
state.closestComponentId = componentId
}
return state
})
}
// Adds an action context layer to the tree
const provideAction = (componentId, actionType, callback) => {
store.update(state => {
if (actionType && componentId) {
state[`${componentId}_${actionType}`] = callback
}
return state
})
}
return {
subscribe: store.subscribe,
update: store.update,
actions: { provideData, provideAction },
}
}