Skip to content

Commit ca66dab

Browse files
committed
oldValue to old_value
1 parent e5e56a7 commit ca66dab

File tree

9 files changed

+44
-44
lines changed

9 files changed

+44
-44
lines changed

src/api/applyPatchFactory.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ export default function applyPatchFactory(patchers) {
3030
: origin_value
3131

3232
// Applying patches
33-
const oldValue = patchers.reduce(
34-
(oldValue, p) =>
33+
const old_value = patchers.reduce(
34+
(old_value, p) =>
3535
p({
3636
origin,
3737
destiny,
3838
prop,
3939
path,
40-
oldValue,
40+
old_value,
4141
had_prop,
4242
applyPatch
4343
}),
4444
destiny_value
4545
)
4646

47-
// We register the mutation if oldValue is different to the new value
48-
if (destiny[prop] !== oldValue) {
49-
setDeep(unpatch_root, path.slice(0), oldValue)
47+
// We register the mutation if old_value is different to the new value
48+
if (destiny[prop] !== old_value) {
49+
setDeep(unpatch_root, path.slice(0), old_value)
5050
mutations.push({
51-
oldValue,
51+
old_value,
5252
object: destiny,
5353
prop,
5454
path: path.slice(1)

src/types/Array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import merge from '../util/merge'
33

44
export default function Array() {}
55

6-
Array.patch = function({ origin, destiny, prop, oldValue }) {
6+
Array.patch = function({ origin, destiny, prop, old_value }) {
77
const origin_value = origin[prop]
88
if (isArray(origin_value)) {
99
destiny[prop] = merge([], origin_value)
1010
}
11-
return oldValue
11+
return old_value
1212
}

src/types/Delete.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export default function Delete() {
88
}
99
}
1010

11-
Delete.patch = function({ origin, destiny, prop, oldValue, had_prop }) {
11+
Delete.patch = function({ origin, destiny, prop, old_value, had_prop }) {
1212
if (origin[prop] instanceof Delete || origin[prop] === Delete) {
1313
delete destiny[prop]
1414
}
1515
if (!had_prop) {
16-
oldValue = new Delete()
16+
old_value = new Delete()
1717
}
18-
return oldValue
18+
return old_value
1919
}
2020

2121
Delete.encode = function({ value }) {

src/types/Inner.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@ export default function Inner(patch) {
1313
this.patch = patch
1414
}
1515

16-
Inner.patch = function({ origin, destiny, prop, oldValue, applyPatch }) {
16+
Inner.patch = function({ origin, destiny, prop, old_value, applyPatch }) {
1717
const origin_value = origin[prop]
1818
if (origin_value instanceof Inner) {
19-
destiny[prop] = oldValue
20-
if (isArray(oldValue)) {
19+
destiny[prop] = old_value
20+
if (isArray(old_value)) {
2121
const patches = origin_value.patch
2222
const unpatches = {}
23-
const length = oldValue.length
23+
const length = old_value.length
2424
for (const key in patches) {
25-
const had_prop = oldValue.hasOwnProperty(key)
26-
const patched = applyPatch(oldValue[key], patches[key])
25+
const had_prop = old_value.hasOwnProperty(key)
26+
const patched = applyPatch(old_value[key], patches[key])
2727
if (
28-
oldValue[key] !== patched.result ||
28+
old_value[key] !== patched.result ||
2929
isPlainObject(patches[key])
3030
) {
31-
oldValue[key] = patched.result
31+
old_value[key] = patched.result
3232
unpatches[key] = had_prop ? patched.unpatch : Delete()
3333
}
3434
}
35-
if (oldValue.length !== length) {
35+
if (old_value.length !== length) {
3636
unpatches.length = length
3737
}
38-
// console.log({ result: oldValue, unpatches })
38+
// console.log({ result: old_value, unpatches })
3939
return new Inner(unpatches)
4040
}
4141
}
42-
return oldValue
42+
return old_value
4343
}
4444

4545
Inner.encode = function({ value, encode }) {

src/types/Replace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export default function Replace(value) {
88
this.value = value
99
}
1010

11-
Replace.patch = function({ origin, destiny, prop, oldValue }) {
11+
Replace.patch = function({ origin, destiny, prop, old_value }) {
1212
if (origin[prop] instanceof Replace) {
1313
destiny[prop] = origin[prop].value
14-
return new Replace(oldValue)
14+
return new Replace(old_value)
1515
}
16-
return oldValue
16+
return old_value
1717
}
1818

1919
Replace.encode = function({ value }) {

src/types/Splice.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ export default function Splice(...args) {
1010
this.args = args
1111
}
1212

13-
Splice.patch = function({ origin, destiny, prop, oldValue }) {
13+
Splice.patch = function({ origin, destiny, prop, old_value }) {
1414
const origin_value = origin[prop]
1515
if (origin_value instanceof Splice) {
16-
destiny[prop] = oldValue
17-
if (isArray(oldValue)) {
16+
destiny[prop] = old_value
17+
if (isArray(old_value)) {
1818
const { args } = origin_value
1919
if (args[0] < 0) {
20-
args[0] = oldValue.length + args[0]
20+
args[0] = old_value.length + args[0]
2121
}
22-
const spliced = oldValue.splice.apply(oldValue, args)
22+
const spliced = old_value.splice.apply(old_value, args)
2323
const inverted = [args[0], args.length - 2].concat(spliced)
2424
return Splice.apply(null, inverted)
2525
}
2626
}
27-
return oldValue
27+
return old_value
2828
}
2929

3030
Splice.encode = function({ value }) {

src/util/set.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export function setDeep(unpatch, path, value) {
1313
export function createPatchFromMutations(mutations) {
1414
const patch = {}
1515
const unpatch = {}
16-
mutations.forEach(({ object, prop, path, oldValue }) => {
16+
mutations.forEach(({ object, prop, path, old_value }) => {
1717
setDeep(patch, path.slice(0), object[prop])
18-
setDeep(unpatch, path.slice(0), oldValue)
18+
setDeep(unpatch, path.slice(0), old_value)
1919
})
2020
return { patch, unpatch }
2121
}

test/.addType.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ function Push(...elements) {
1111
}
1212
this.elements = elements
1313
}
14-
Push.patch = function({ origin, destiny, prop, oldValue }) {
14+
Push.patch = function({ origin, destiny, prop, old_value }) {
1515
const originValue = origin[prop]
16-
if (isArray(oldValue) && originValue instanceof Push) {
17-
destiny[prop] = oldValue
16+
if (isArray(old_value) && originValue instanceof Push) {
17+
destiny[prop] = old_value
1818
return Push.apply(null, originValue.elements)
1919
}
20-
return oldValue
20+
return old_value
2121
}
2222
Push.encode = function({ value }) {
2323
if (value instanceof Push) {

test/applyPatch.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,25 @@ test('syntax mutations', function(t) {
168168
t.is(mutations.length, 4)
169169
t.deepEqual(mutations[0], {
170170
prop: 'value',
171-
oldValue: false,
171+
old_value: false,
172172
path: ['value'],
173173
object: target
174174
})
175175
t.deepEqual(mutations[1], {
176176
prop: 'prop',
177-
oldValue: false,
177+
old_value: false,
178178
path: ['prop'],
179179
object: target
180180
})
181181
t.deepEqual(mutations[2], {
182182
prop: 'value',
183-
oldValue: false,
183+
old_value: false,
184184
path: ['last', 'value'],
185185
object: target.last
186186
})
187187
t.deepEqual(mutations[3], {
188188
prop: 'lastlast',
189-
oldValue: { value: false },
189+
old_value: { value: false },
190190
path: ['lastlast'],
191191
object: target
192192
})
@@ -200,7 +200,7 @@ test('syntax mutations on top level', function(t) {
200200
t.is(mutations.length, 1)
201201
t.deepEqual(mutations[0], {
202202
prop: '',
203-
oldValue: target,
203+
old_value: target,
204204
path: [],
205205
object: { '': patch }
206206
})
@@ -214,7 +214,7 @@ test('syntax mutations when using delete', function(t) {
214214
t.is(mutations.length, 1)
215215
t.deepEqual(mutations[0], {
216216
prop: '',
217-
oldValue: target,
217+
old_value: target,
218218
path: [],
219219
object: {}
220220
})

0 commit comments

Comments
 (0)