Skip to content

Commit

Permalink
feat: expose previous data to resolveData via lastData param
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Apr 24, 2024
1 parent 0a18bdb commit dd7051e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ const resolveData = async ({ props }, { changed }) => {
};
```

##### `params.lastData`

The data object from the previous run of this function.

#### Returns

| Prop | Example | Type |
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/resolve-component-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const resolveComponentData = async (
}

const { props: resolvedProps, readOnly = {} } =
await configForItem.resolveData(item, { changed });
await configForItem.resolveData(item, { changed, lastData: oldItem });

const { readOnly: existingReadOnly = {} } = item || {};

Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/resolve-root-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const resolveRootData = async (data: Data, config: Config) => {

const resolvedRoot = await config.root?.resolveData(rootWithProps, {
changed,
lastData: cache.lastChange?.original || {},
});

cache.lastChange = {
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export type ComponentConfig<
data: DataShape,
params: {
changed: Partial<Record<keyof ComponentProps, boolean>>;
lastData: DataShape;
}
) =>
| Promise<{
Expand Down

0 comments on commit dd7051e

Please sign in to comment.