Skip to content

use absolute exclude path in build/webpack.test.config.js and fix error when recursively traverse an object #2680

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion build/webpack.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ module.exports = {
{
test: /\.js$/,
loader: 'babel',
exclude: /test\/unit|node_modules/
// NOTE: use absolute path to make sure
// running tests is OK even if it is in node_modules of other project
exclude: [
path.resolve(__dirname, '../test/unit'),
path.resolve(__dirname, '../node_modules')
]
}
]
},
Expand Down
17 changes: 14 additions & 3 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,25 @@ Watcher.prototype.teardown = function () {
* @param {*} val
*/

function traverse (val) {
function traverse (val, walkedObjs) {
var i, keys

walkedObjs = walkedObjs || {}
if (isArray(val)) {
i = val.length
while (i--) traverse(val[i])
while (i--) traverse(val[i], walkedObjs)
} else if (isObject(val)) {
if (val.__ob__) {
var depId = val.__ob__.dep.id
if (walkedObjs[depId]) {
return
} else {
walkedObjs[depId] = true
}
}

keys = Object.keys(val)
i = keys.length
while (i--) traverse(val[keys[i]])
while (i--) traverse(val[keys[i]], walkedObjs)
}
}
17 changes: 17 additions & 0 deletions test/unit/specs/watcher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,23 @@ describe('Watcher', function () {
})
})

it('deep watch with circular references', function (done) {
new Watcher(vm, 'b', spy, {
deep: true
})
Vue.set(vm.b, '_', vm.b)
nextTick(function () {
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
expect(spy.calls.count()).toBe(1)
vm.b._.c = 1
nextTick(function () {
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
expect(spy.calls.count()).toBe(2)
done()
})
})
})

it('fire change for prop addition/deletion in non-deep mode', function (done) {
new Watcher(vm, 'b', spy)
Vue.set(vm.b, 'e', 123)
Expand Down