Skip to content

Commit

Permalink
fix: Reactive cycle improvements
Browse files Browse the repository at this point in the history
Introduces improvements to the reactive cycles of signals and resources.

    Previously, signals holding objects were not correct evaluated for changes, causing unnecessary notifications to observers. Now, even if the signal holds an object, the object is checked for deep equality of its properties and values (as opposed to checking for object identity).
    Resource reactive cycles have also been improved to avoid unnecessary notifications.
        A resource's source function is never evaluated unless fetchWhen is true
        The deepCheck evaluation done for signals is also now done for resource source functions, avoiding unnecessary re-evaluation when these return an object
  • Loading branch information
cesarParra authored Nov 26, 2024
1 parent 4fcc5a7 commit 2fa354a
Show file tree
Hide file tree
Showing 12 changed files with 854 additions and 515 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ Data from a resource signal comes in the following format:

```typescript
type AsyncData<T> = {
data: T | null; // The data fetched from the server. It is null until the data is fetched
data: ReadOnlySignal<T> | null; // The data fetched from the server. It is null until the data is fetched
loading: boolean; // A boolean that indicates if the data is being fetched
error: unknown | null; // An error object that is populated if the fetch fails
};
Expand Down Expand Up @@ -607,6 +607,9 @@ export default class ContactList extends LightningElement {

### Mutating `$resource` data

Notice that the data returned by a resource is a ReadOnlySignal.
This means that you cannot mutate the data directly, so how can you update the data?

Besides `refetch`, the `$resource` function also returns a `mutate` function that allows you to mutate the data.

`mutate` is useful when you want to update the data without refetching it (and avoid a trip to the server).
Expand Down
Loading

0 comments on commit 2fa354a

Please # to comment.