Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(template): remove non-existing properties correctly in vue 3 template #226

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/helper-vue3/src/FieldPluginProvider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ import { convertToRaw } from '../utils'
const plugin = reactive<FieldPluginResponse>({
type: 'loading',
})

const updateObjectWithoutChangingReference = (
originalObject: Record<string, unknown>,
newObject: Record<string, unknown>,
) => {
// Delete keys that do not exist anymore
Object.keys(originalObject).forEach((key) => {
if (newObject[key] === undefined) {
delete originalObject[key]
}
})
// Update the original object with the new one
// @ts-ignore not sure how to solve this
Object.assign(originalObject, newObject)
}

createFieldPlugin((newState) => {
// Instead of replacing `plugin.data` which loses the reactive reference,
// we're assigning each property into `plugin.data`.
Expand All @@ -25,8 +41,10 @@ createFieldPlugin((newState) => {
const keys = Object.keys(newState.data) as Array<keyof FieldPluginData>
keys.forEach((key) => {
if (typeof plugin.data[key] === 'object') {
// @ts-ignore not sure how to solve this
Object.assign(plugin.data[key], newState.data[key])
updateObjectWithoutChangingReference(
plugin.data[key] as Record<string, unknown>,
newState.data[key] as Record<string, unknown>,
)
} else {
// @ts-ignore not sure how to solve this
plugin.data[key] = newState.data[key]
Expand Down