// each item in bridges has the states of a certain component
const Bridges = {};
// this gets called from the child component to change the state of the parent
const setState = (componentID, stateName, newState) => newState ?? Bridges[componentID][stateName].render(newState);
// this gets called from the child to read the state of the parent
const getState = (componentID, stateName) => Bridges[componentID][stateName].state;
// this gets called from the parent, the component you wanna share it's state with the child or re-render if the child received a delete event for example.
const initBridge = (componentID, states) => {
if (!bridgesObj?.render) {
bridgesObj.render = () => {
console.error('render function is not set');
};
}
// adds the parent states to the collection/store
Bridges[componentID] = {...states};
};
export const Bridge = {initBridge, getState, setState};
// each item in bridges has the states of a certain component
const Bridges = {};
// this gets called from the child component to change the state of the parent
const setState = (componentID, stateName, newState) => newState ?? Bridges[componentID][stateName].render(newState);
// this gets called from the child to read the state of the parent
const getState = (componentID, stateName) => Bridges[componentID][stateName].state;
// this gets called from the parent, the component you wanna share it's state with the child or re-render if the child received a delete event for example.
const initBridge = (componentID, states) => {
if (!bridgesObj?.render) {
bridgesObj.render = () => {
console.error('render function is not set');
};
}
// adds the parent states to the collection/store
Bridges[componentID] = {...states};
};
export const Bridge = {initBridge, getState, setState};