expect(serializeInner(root)).toBe('bar')
})
+ test('without parent listener (local mutation)', async () => {
+ let foo: any
+ const update = () => {
+ foo.value = 'bar'
+ }
+
+ const compRender = vi.fn()
+ const Comp = defineComponent({
+ props: ['foo'],
+ emits: ['update:foo'],
+ setup(props) {
+ foo = useModel(props, 'foo')
+ return () => {
+ compRender()
+ return foo.value
+ }
+ },
+ })
+
+ const root = nodeOps.createElement('div')
+ // provide initial value
+ render(h(Comp, { foo: 'initial' }), root)
+ expect(compRender).toBeCalledTimes(1)
+ expect(serializeInner(root)).toBe('initial')
+
+ expect(foo.value).toBe('initial')
+ update()
+ // when parent didn't provide value, local mutation is enabled
+ expect(foo.value).toBe('bar')
+
+ await nextTick()
+ expect(compRender).toBeCalledTimes(2)
+ expect(serializeInner(root)).toBe('bar')
+ })
+
test('default value', async () => {
let count: any
const inc = () => {
type LooseRequired,
type Prettify,
type UnionToIntersection,
+ camelize,
extend,
hasChanged,
isArray,
return ref() as any
}
+ const camelizedName = camelize(name)
+
const res = customRef((track, trigger) => {
let localValue: any
watchSyncEffect(() => {
},
set(value) {
const rawProps = i.vnode!.props
- if (!(rawProps && name in rawProps) && hasChanged(value, localValue)) {
+ if (
+ !(
+ rawProps &&
+ // check if parent has passed v-model
+ (name in rawProps || camelizedName in rawProps) &&
+ (`onUpdate:${name}` in rawProps ||
+ `onUpdate:${camelizedName}` in rawProps)
+ ) &&
+ hasChanged(value, localValue)
+ ) {
localValue = value
trigger()
}