Skip to content

Commit

Permalink
fix(element): fix FormLayout provide props not update (#2448)
Browse files Browse the repository at this point in the history
* fix(element): fix FormLayout provide props not update

* chore(reactive-vue): ignore vue3 test branch
  • Loading branch information
muuyao authored Nov 17, 2021
1 parent f3f2989 commit cd50ad7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/element/src/form-layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,29 @@ export const FormLayoutShallowContext: InjectionKey<Ref<FormLayoutProps>> =
Symbol('FormLayoutShallowContext')

export const useFormDeepLayout = (): Ref<FormLayoutProps> =>
inject(FormLayoutDeepContext, ref(null))
inject(FormLayoutDeepContext, ref({}))

export const useFormShallowLayout = (): Ref<FormLayoutProps> =>
inject(FormLayoutShallowContext, ref(null))
inject(FormLayoutShallowContext, ref({}))

export const useFormLayout = (): Ref<FormLayoutProps> => {
const shallowLayout = useFormShallowLayout()
const deepLayout = useFormDeepLayout()
const formLayout = ref({})
const formLayout = ref({
...deepLayout.value,
...shallowLayout.value,
})

watch(
[shallowLayout],
[shallowLayout, deepLayout],
() => {
formLayout.value = {
...deepLayout.value,
...shallowLayout.value,
}
},
{
immediate: true,
deep: true,
}
)
return formLayout
Expand Down Expand Up @@ -115,7 +118,7 @@ export const FormLayout = defineComponent<FormLayoutProps>({
() => {
shallowProps.value = props.value.shallow ? props.value : undefined
if (!props.value.shallow) {
Object.assign(newDeepLayout.value, props)
Object.assign(newDeepLayout.value, props.value)
} else {
if (props.value.size) {
newDeepLayout.value.size = props.value.size
Expand Down
1 change: 1 addition & 0 deletions packages/reactive-vue/src/hooks/useObserver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { autorun } from '@formily/reactive'
import { getCurrentInstance, onBeforeUnmount, isVue3 } from 'vue-demi'

/* istanbul ignore next */
export const useObserver = () => {
if (isVue3) {
const vm = getCurrentInstance()
Expand Down
1 change: 1 addition & 0 deletions packages/reactive-vue/src/observer/observerInVue3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IObserverOptions } from '../types'
import { useObserver } from '../hooks/useObserver'

/* istanbul ignore next */
export const observer = function (opts: any, options?: IObserverOptions): any {
const name = options?.name || opts.name || 'ObservableComponent'

Expand Down

0 comments on commit cd50ad7

Please sign in to comment.