Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions code/lib/manager-api/src/modules/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export const init: ModuleFn<SubAPI, SubState> = (
return refs;
},

setRef: (id, { storyIndex, setStoriesData, ...rest }, ready = false) => {
setRef: async (id, { storyIndex, setStoriesData, ...rest }, ready = false) => {
if (singleStory) {
return;
}
Expand Down Expand Up @@ -307,10 +307,10 @@ export const init: ModuleFn<SubAPI, SubState> = (
index = addRefIds(index, ref);
}

api.updateRef(id, { ...ref, ...rest, index, internal_index });
await api.updateRef(id, { ...ref, ...rest, index, internal_index });
},

updateRef: (id, data) => {
updateRef: async (id, data) => {
const { [id]: ref, ...updated } = api.getRefs();

updated[id] = { ...ref, ...data };
Expand All @@ -320,7 +320,7 @@ export const init: ModuleFn<SubAPI, SubState> = (
return obj;
}, {});

store.setState({
await store.setState({
refs: ordered,
});
},
Expand All @@ -331,9 +331,10 @@ export const init: ModuleFn<SubAPI, SubState> = (
const initialState: SubState['refs'] = refs;

if (runCheck) {
Object.entries(refs).forEach(([id, ref]) => {
api.checkRef({ ...ref!, stories: {} } as API_SetRefData);
});
Object.entries(refs).reduce(async (acc, [id, ref]) => {
await acc;
await api.checkRef({ ...ref!, stories: {} } as API_SetRefData);
}, Promise.resolve());
Comment thread
ndelangen marked this conversation as resolved.
Outdated
}

return {
Expand Down
6 changes: 6 additions & 0 deletions code/lib/manager-api/src/tests/refs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ describe('Refs API', () => {
// given
initRefs({ provider, store } as any);

// the `runCheck` is async, so we need to wait for it to finish
await Promise.resolve();
Comment thread
ndelangen marked this conversation as resolved.
Outdated

expect(fetchMock.mock.calls).toMatchInlineSnapshot(`
[
[
Expand Down Expand Up @@ -207,6 +210,9 @@ describe('Refs API', () => {
};
initRefs({ provider, store } as any);

// the `runCheck` is async, so we need to wait for it to finish
await Promise.resolve();

expect(fetchMock.mock.calls).toMatchInlineSnapshot(`
[
[
Expand Down