vuejs / composition-api

Composition API plugin for Vue 2
https://composition-api.vuejs.org/
MIT License
4.19k stars 342 forks source link

`watch` no longer works for multiple sources after v1.1 #853

Closed zorji closed 2 years ago

zorji commented 2 years ago

Jest test to reproduce the issue.

The following test passes in v1.0.3 but fails since v1.1 (I tested with v1.1.5, 1.2, 1.3 and 1.4.0)

Vue version: 2.6.14

import VueCompositionApi, { reactive, watch } from '@vue/composition-api'
import Vue from 'vue'

Vue.use(VueCompositionApi)

describe('watch', () => {

  it('should trigger watch when reactive changes', (done) => {

    const pagination = reactive({ page: 0, pageSize: 0 })

    watch(pagination, (newPagination) => {
      expect(newPagination)
        .toEqual({ page: 1, pageSize: 0 })
      done()
    })

    pagination.page = 1

  })

  it('should trigger watch when reactive changes in array', (done) => {

    const pagination = reactive({ page: 0, pageSize: 0 })
    const filter = reactive({ name: '' })

    watch([pagination, filter] as const, ([newPagination, newFilter]) => {
      expect(newPagination)
        .toEqual({ page: 1, pageSize: 0 })
      expect(newFilter)
        .toEqual({ name: '' })
      done()
    })

    pagination.page = 1

  })

})
xiaoxiangmoe commented 2 years ago

temporary try this:

watch([pagination, filter] as const, ([newPagination, newFilter]) => {

}, {deep:true})
github-actions[bot] commented 2 years ago

Stale issue message

github-actions[bot] commented 2 years ago

Stale issue message