-
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: add resolveProp API for modifying props dynamically
- Loading branch information
Showing
11 changed files
with
152 additions
and
40 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,30 @@ | ||
import { Config, MappedItem } from "../types/Config"; | ||
|
||
export const resolveAllProps = async ( | ||
content: MappedItem[], | ||
config: Config | ||
) => { | ||
return await Promise.all( | ||
content.map(async (item) => { | ||
const configForItem = config.components[item.type]; | ||
|
||
if (configForItem.resolveProps) { | ||
const { props: resolvedProps, readOnly = {} } = | ||
await configForItem.resolveProps(item.props); | ||
|
||
const { _meta: { readOnly: existingReadOnly = {} } = {} } = | ||
item.props || {}; | ||
|
||
return { | ||
...item, | ||
props: { | ||
...resolvedProps, | ||
_meta: { readOnly: { ...existingReadOnly, ...readOnly } }, | ||
}, | ||
}; | ||
} | ||
|
||
return item; | ||
}) | ||
); | ||
}; |
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,20 @@ | ||
import { Config, Data, MappedItem } from "../types/Config"; | ||
import { resolveAllProps } from "./resolve-all-props"; | ||
|
||
export const resolveData = async (data: Data, config: Config) => { | ||
const { zones = {} } = data; | ||
|
||
const zoneKeys = Object.keys(zones); | ||
const resolvedZones: Record<string, MappedItem[]> = {}; | ||
|
||
for (let i = 0; i < zoneKeys.length; i++) { | ||
const zoneKey = zoneKeys[i]; | ||
resolvedZones[zoneKey] = await resolveAllProps(zones[zoneKey], config); | ||
} | ||
|
||
return { | ||
...data, | ||
content: await resolveAllProps(data.content, config), | ||
zones: resolvedZones, | ||
}; | ||
}; |
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