Skip to content

Commit 31b4b52

Browse files
committed
Fix bug where text, props diffs were not exposed
1 parent 3524456 commit 31b4b52

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function walk(left, right, patch, index) {
4646

4747
function diffText(apply, left, right) {
4848
return left.value === right.value ?
49-
undefined :
49+
apply :
5050
append(apply, {type: 'text', left: left, right: right});
5151
}
5252

@@ -84,7 +84,7 @@ function diffChildren(apply, left, right, patch, offset) {
8484

8585
function diffProperties(apply, left, right) {
8686
var diff = diffObjects(left, right);
87-
return diff ? append(apply, {type: 'props', left: left, right: diff}) : undefined;
87+
return diff ? append(apply, {type: 'props', left: left, right: diff}) : apply;
8888
}
8989

9090
function diffObjects(left, right) {

test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test('unist-diff', function (t) {
5454
});
5555

5656
t.test('`props`', function (st) {
57-
st.plan(11);
57+
st.plan(12);
5858

5959
(function () {
6060
var alpha = {type: 'alpha'};
@@ -68,6 +68,24 @@ test('unist-diff', function (t) {
6868
);
6969
})();
7070

71+
(function () {
72+
var left = {type: 'alpha', bravo: true, value: 'charlie'};
73+
var right = {type: 'alpha', bravo: false, value: 'charlie'};
74+
75+
st.deepEqual(
76+
diff(left, right),
77+
{
78+
0: {
79+
type: 'props',
80+
left: left,
81+
right: {bravo: false}
82+
},
83+
left: left
84+
},
85+
'should not return a patch for changed primitives'
86+
);
87+
})();
88+
7189
(function () {
7290
var alpha = {type: 'alpha'};
7391
var left = {type: 'bravo', charlie: [1, 2, 3], children: [alpha]};

0 commit comments

Comments
 (0)