Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.
MIT License
3.15k stars 117 forks source link

Changing parent causes 'update' event for child, even if child value unchanged #455

Open thomsbg opened 8 years ago

thomsbg commented 8 years ago

When setting a parent path, cursors of child paths are notified of 'update' events, even if the values at the child paths didn't change.

Repro steps:

var assert = require('assert')
var Baobab = require('baobab')
var tree = new Baobab({ outer: { inner: 'value' } })
tree.select('outer', 'inner').on('update', e => {
  // will fail
  assert.notEqual(e.data.previousData, e.data.currentData)
})
tree.set('outer', { inner: tree.get('outer', 'inner') })

Expected: the 'update' handler does not fire, since the value at path (outer, inner) did not change. Actual: an AssertionError is thrown