abstracting generic queryStoreMapping
This commit is contained in:
parent
9bb780cd96
commit
00cea8429c
@ -30,31 +30,16 @@
|
|||||||
id: 'ComposerCharly',
|
id: 'ComposerCharly',
|
||||||
component: 'ComposerCharly',
|
component: 'ComposerCharly',
|
||||||
slot: 'aside',
|
slot: 'aside',
|
||||||
// data: {
|
data: {
|
||||||
// queries: {
|
queries: {
|
||||||
// todos: queryTodos,
|
todos: queryTodos,
|
||||||
// messages: queryMessages
|
messages: queryMessages
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
machine: {
|
machine: {
|
||||||
initial: 'LOADING',
|
initial: 'LOADING',
|
||||||
states: {
|
states: {
|
||||||
LOADING: {
|
LOADING: {
|
||||||
entry: () => {
|
|
||||||
function subscribeAndMapQueries(queryMap) {
|
|
||||||
Object.entries(queryMap).forEach(([name, query]) => {
|
|
||||||
query.subscribe((value) => {
|
|
||||||
if (value) {
|
|
||||||
coreServices.mutateStore('ComposerCharly', { [name]: value });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return subscribeAndMapQueries({
|
|
||||||
todos: queryTodos,
|
|
||||||
messages: queryMessages
|
|
||||||
});
|
|
||||||
},
|
|
||||||
on: {
|
on: {
|
||||||
TOGGLE: {
|
TOGGLE: {
|
||||||
target: 'READY'
|
target: 'READY'
|
||||||
|
@ -90,6 +90,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function subscribeAndMapQueries(id: string, queryMap: Record<string, any>) {
|
||||||
|
Object.entries(queryMap).forEach(([name, query]) => {
|
||||||
|
query.subscribe((value) => {
|
||||||
|
if (value) {
|
||||||
|
coreServices.mutateStore(id, { [name]: value });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function computeLayoutStyle(layout?: IComposerLayout): string {
|
function computeLayoutStyle(layout?: IComposerLayout): string {
|
||||||
if (!layout) return '';
|
if (!layout) return '';
|
||||||
return `
|
return `
|
||||||
@ -101,10 +111,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initializeComposerState(child: IComposer) {
|
function initializeComposerState(child: IComposer) {
|
||||||
if (!child) return; // Add this line
|
if (!child) return;
|
||||||
|
|
||||||
if (child.id) {
|
if (child.id) {
|
||||||
child.store = createComposerStore(child.id, child.store || {});
|
child.store = createComposerStore(child.id, child.store || {});
|
||||||
|
if (child.data?.queries) {
|
||||||
|
subscribeAndMapQueries(child.id, child.data.queries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child.children) {
|
if (child.children) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user