-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move root props under
props
key
This is a backwards-compatible change, with deprecated warnings. It is necessary to support resolveData on the root.
- Loading branch information
Showing
12 changed files
with
178 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Config, Data, RootDataWithProps } from "../types/Config"; | ||
|
||
export const cache: { | ||
lastChange?: { original: RootDataWithProps; resolved: RootDataWithProps }; | ||
} = {}; | ||
|
||
export const resolveRootData = async (data: Data, config: Config) => { | ||
if (config.root?.resolveData && data.root.props) { | ||
let changed = Object.keys(data.root.props).reduce( | ||
(acc, item) => ({ ...acc, [item]: true }), | ||
{} | ||
); | ||
|
||
if (cache.lastChange) { | ||
const { original, resolved } = cache.lastChange; | ||
|
||
if (original === data.root) { | ||
return resolved; | ||
} | ||
|
||
Object.keys(data.root.props).forEach((propName) => { | ||
if (original.props[propName] === data.root.props![propName]) { | ||
changed[propName] = false; | ||
} | ||
}); | ||
} | ||
|
||
const rootWithProps = data.root as RootDataWithProps; | ||
|
||
const resolvedRoot = await config.root?.resolveData(rootWithProps, { | ||
changed, | ||
}); | ||
|
||
cache.lastChange = { | ||
original: data.root as RootDataWithProps, | ||
resolved: resolvedRoot as RootDataWithProps, | ||
}; | ||
|
||
return { | ||
...data.root, | ||
...resolvedRoot, | ||
props: { | ||
...data.root.props, | ||
...resolvedRoot.props, | ||
}, | ||
}; | ||
} | ||
|
||
return data.root; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.