Skip to content

Commit

Permalink
fix(store): add id to listing type placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Oct 16, 2023
1 parent c06c178 commit cc0c9d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,19 @@ function setupListModel(Model, nested) {
contexts,
enumerable: modelConfig.enumerable,
external: modelConfig.external,
placeholder: () => {
placeholder: (id) => {
const model = Object.create(listPlaceholderPrototype);
definitions.set(model, config);

Object.defineProperties(model, {
id: { value: id },
toString: {
value: function () {
return this.id;
},
},
});

return Object.freeze(model);
},
isInstance: (model) =>
Expand Down
11 changes: 10 additions & 1 deletion test/spec/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2086,8 +2086,13 @@ describe("store:", () => {
},
};

const pendingModel = store.get([Model], "test");

expect(pendingModel.id).toBe("test");
expect(String(pendingModel)).toBe("test");

return store
.pending(store.get([Model]))
.pending(pendingModel)
.then((models) => store.pending(models[0]).then(() => models))
.then((models) => {
const model = models[0];
Expand Down Expand Up @@ -2150,6 +2155,10 @@ describe("store:", () => {
};

const pendingModel = store.get(Model, 1);

expect(pendingModel.id).toBe("1");
expect(String(pendingModel)).toBe("1");

expect(store.pending(pendingModel)).toBeInstanceOf(Promise);
expect(() => pendingModel.value).toThrow();

Expand Down

0 comments on commit cc0c9d9

Please sign in to comment.