Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed May 17, 2024
1 parent 527d351 commit 07e4f3c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ customName: {
}
```

Read more about the full object property descriptor in the [Structure](/component-model/structure.md#value) section.

### Attributes

Writable properties are no longer automatically synchronized back to the attribute. You must set the `reflect` option to enable the synchronization:
Expand All @@ -45,6 +47,8 @@ Writable properties are no longer automatically synchronized back to the attribu
}
```

Read more about the attribute synchronization in the [Structure](/component-model/structure.md#reflect) section.

### Render and Content

#### Names
Expand Down Expand Up @@ -93,7 +97,7 @@ The options are now part of the `render` descriptor instead of a need to extend
}
```

### Store
### Store Errors

For better developer experience, the `store.get()` and `store.set()` methods throw type errors immediately, instead of returning a model in error state. This is not a breaking change, but the information can help you to find the issue faster.

Expand Down Expand Up @@ -190,7 +194,7 @@ The `render` factory is no longer supported - you must set `render` or `content`

If you update the DOM using another property name, you must create a custom factory for the property. You can follow the old implementation of the `render` factory available here:

https://github.com/hybridsjs/hybrids/blob/v6.1.0/src/render.js
<https://github.com/hybridsjs/hybrids/blob/v6.1.0/src/render.js>

#### Templates

Expand Down Expand Up @@ -252,7 +256,7 @@ import { Component } from "hybrids";
const MyElement: Component<MyElement> = { ... };
```

### Store
### Store Factory

#### Identifier

Expand Down
41 changes: 41 additions & 0 deletions test/spec/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ describe("store:", () => {
expect(() => store.get({ value: null })).toThrow();
});

it("throws an error when get method returns string", () => {
Model = {
value: "test",
[store.connect]: {
get: () => "test",
},
};

expect(() => store.get(Model)).toThrow();
});

it("throws when nested object is used as a primary model", () => {
store.get(Model, "1");
expect(() => {
Expand Down Expand Up @@ -386,6 +397,20 @@ describe("store:", () => {
).toThrow();
});

it("throws an error when set method returns undefined", () => {
Model = {
value: "test",
[store.connect]: {
get: () => ({}),
set: () => {
return "test";
},
},
};

expect(() => store.set(Model)).toThrow();
});

it("rejects an error when array with external objects is set with wrong type", async () => {
const model = await promise;
expect(() =>
Expand Down Expand Up @@ -420,6 +445,22 @@ describe("store:", () => {
});
});

it("rejects an error when set method returns promise resolving to string", () => {
Model = {
value: "test",
[store.connect]: {
get: () => ({}),
set: async () => {
return "test";
},
},
};

return store.set(Model).catch((e) => {
expect(e).toBeInstanceOf(Error);
});
});

it("returns a placeholder in error state for not found singleton model", () => {
Model = {
value: "test",
Expand Down

0 comments on commit 07e4f3c

Please sign in to comment.