Skip to content

Commit 5a747b6

Browse files
committed
Fixed bug when mutating array.length. Was storing two mutations instead of one
1 parent 064a238 commit 5a747b6

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dop",
3-
"version": "0.24.0",
3+
"version": "0.24.1",
44
"main": "./dist/dop.nodejs.js",
55
"browser": "./dist/dop.js",
66
"unpkg": "./dist/dop.min.js",

src/core/mutators/set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dop.core.set = function(object, property, value) {
4343
mutation.oldValue = dop.util.clone(oldValue)
4444

4545
// If is array and length is different we must store the length
46-
if (objectTarget.length !== length && objectIsArray)
46+
if (property !== 'length' && objectTarget.length !== length && objectIsArray)
4747
dop.core.storeMutation({
4848
object: objectProxy,
4949
prop: 'length',

test/mutation.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,5 +404,23 @@ test('unobserve = observer.observe(...)', function(t) {
404404
set(object, 'newprop', 'blabla')
405405
t.equal(times, 2)
406406

407+
t.end()
408+
})
409+
410+
411+
412+
test('mutating length of array', function(t) {
413+
var object = dop.register({array:[1,2,3]})
414+
var times = 0
415+
var observer = dop.createObserver(function(mutations) {
416+
times += 1
417+
})
418+
observer.observe(object.array)
419+
observer.observe(object.array, 'length')
420+
set(object.array, 'length', 1)
421+
t.equal(object.array.length, 1)
422+
t.equal(times, 1)
423+
424+
407425
t.end()
408426
})

0 commit comments

Comments
 (0)