Skip to content

Commit

Permalink
fix(store): dont rewrite id for list type in async storage
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Oct 26, 2020
1 parent 63e2549 commit 2196fe9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function setupStorage(storage) {
);
}

if (!result.get && result.list) {
result.get = () => {};
}

return Object.freeze(result);
}

Expand Down Expand Up @@ -713,7 +717,9 @@ function get(Model, id) {
return sync(
config,
stringId,
config.create(stringId ? { ...data, id: stringId } : data),
config.create(
!config.list && stringId ? { ...data, id: stringId } : data,
),
);
})
.catch(e => {
Expand Down
15 changes: 15 additions & 0 deletions test/spec/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,21 @@ describe("store:", () => {
});
});

it("returns a list with parameters", done => {
Model = {
id: true,
value: "",
[store.connect]: {
list: () => Promise.resolve([{ id: "1", value: "test" }]),
},
};

store.pending(store.get([Model], { page: 1 })).then(resolvedModel => {
expect(resolvedModel).toEqual([{ id: "1", value: "test" }]);
done();
});
});

it("returns placeholder in async calls for long fetching model", done => {
let resolvePromise;
Model = {
Expand Down

0 comments on commit 2196fe9

Please sign in to comment.