mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-25 04:20:33 +03:00
fix: recompute all props when assigning an object to a proxy key
This commit is contained in:
@@ -40,6 +40,7 @@ export const createHandler = <T>(context: MergeContext<T>, resolveContext: Resol
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also return a merge proxy for nested objects
|
||||||
if (!(value as MergeSource<T>)[IS_PROXY]) {
|
if (!(value as MergeSource<T>)[IS_PROXY]) {
|
||||||
const keyPath: PathSegments = [...pathSegments, (key as string)]
|
const keyPath: PathSegments = [...pathSegments, (key as string)]
|
||||||
|
|
||||||
@@ -85,6 +86,11 @@ export const createHandler = <T>(context: MergeContext<T>, resolveContext: Resol
|
|||||||
// update from)
|
// update from)
|
||||||
recompute(context)
|
recompute(context)
|
||||||
return success
|
return success
|
||||||
|
} else if (isPlainObject(value)) {
|
||||||
|
// if an object was assigned to this key make sure to recompute all
|
||||||
|
// of its individual properies
|
||||||
|
recompute(context, pathSegments)
|
||||||
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
let keyContexts: ResolveContext[] = []
|
let keyContexts: ResolveContext[] = []
|
||||||
@@ -106,7 +112,7 @@ export const createHandler = <T>(context: MergeContext<T>, resolveContext: Resol
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Ensure to clone if value is an object, cause sources is an array of
|
// Ensure to clone if value is an object, cause sources is an array of
|
||||||
// the sourceProxies not the sources so we could trigger an endless loop when
|
// the sourceProxies and not the sources so we could trigger an endless loop when
|
||||||
// updating a prop on an obj as the prop on the active object refers to
|
// updating a prop on an obj as the prop on the active object refers to
|
||||||
// a prop on a proxy
|
// a prop on a proxy
|
||||||
if (isPlainObject(resolved)) {
|
if (isPlainObject(resolved)) {
|
||||||
@@ -139,7 +145,7 @@ export const createHandler = <T>(context: MergeContext<T>, resolveContext: Resol
|
|||||||
let index = 0
|
let index = 0
|
||||||
for (const segment of pathSegments) {
|
for (const segment of pathSegments) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
proxies = proxies.map(proxy => proxy[segment])
|
proxies = proxies.map(proxy => proxy && proxy[segment])
|
||||||
|
|
||||||
if (isArrayItem && index === pathSegments.length - 1) {
|
if (isArrayItem && index === pathSegments.length - 1) {
|
||||||
activeSegmentKey = segment
|
activeSegmentKey = segment
|
||||||
@@ -152,7 +158,7 @@ export const createHandler = <T>(context: MergeContext<T>, resolveContext: Resol
|
|||||||
|
|
||||||
// Check if the key still exists in one of the sourceProxies,
|
// Check if the key still exists in one of the sourceProxies,
|
||||||
// if so resolve the new value, if not remove the key
|
// if so resolve the new value, if not remove the key
|
||||||
if (proxies.some(proxy => (key in proxy))) {
|
if (proxies.some(proxy => proxy && (key in proxy))) {
|
||||||
let keyContexts: ResolveContext[] = []
|
let keyContexts: ResolveContext[] = []
|
||||||
let keySources
|
let keySources
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user