Skip to content

Commit 349f5d6

Browse files
committed
rc3
1 parent 02203f4 commit 349f5d6

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ yarn.lock
2121
examples/drag/package-lock.json
2222
examples/todomvc/package-lock.json
2323
.vscode/launch.json
24+
*.tgz

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": "1.0.0-rc2",
3+
"version": "1.0.0-rc3",
44
"main": "./dist/dop.nodejs.js",
55
"browser": "./dist/dop.js",
66
"unpkg": "./dist/dop.min.js",

src/core/objects/setPatch.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ dop.core.setPatchMutator = function(destiny, prop, value, tof_value) {
2424
instructions_patchs = dop.protocol.instructionsPatchs,
2525
mutation
2626

27-
// Any value
28-
if (tof_value != 'object' && tof_value != 'array') {
29-
dop.set(destiny, prop, value)
30-
}
31-
32-
// Not defined object or array
33-
else if (!destiny.hasOwnProperty(prop)) {
34-
dop.set(destiny, prop, tof_value == 'array' ? [] : {})
35-
}
36-
3727
// Array instruction
3828
if (tof_value == 'array') {
3929
type_instruction = value[0]
@@ -49,7 +39,12 @@ dop.core.setPatchMutator = function(destiny, prop, value, tof_value) {
4939
}
5040

5141
// Array mutations
52-
else if (isArray(destiny[prop])) {
42+
else {
43+
// We must create the array in case the
44+
if (!destiny.hasOwnProperty(prop)) {
45+
dop.set(destiny, prop, [])
46+
}
47+
5348
if (!isArray(type_instruction)) value = [value]
5449

5550
for (var index = 0, total = value.length; index < total; ++index) {
@@ -65,6 +60,16 @@ dop.core.setPatchMutator = function(destiny, prop, value, tof_value) {
6560

6661
return true // Skiping to dont go inside of [instructionPatch, ...]
6762
}
63+
64+
// Any value
65+
if (tof_value != 'object' && tof_value != 'array') {
66+
dop.set(destiny, prop, value)
67+
}
68+
69+
// Not defined object
70+
else if (!destiny.hasOwnProperty(prop)) {
71+
dop.set(destiny, prop, {})
72+
}
6873
}
6974

7075
// // Array mutations

test/setpatchs2.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var test = require('tape')
2+
var dopClient = require('./.proxy').create()
3+
var dopServer = require('./.proxy').create()
4+
5+
function getPatch(collector) {
6+
var patch = dopServer.core.getPatch(collector.mutations)
7+
var patchServer = dopServer.decode(dopServer.encode(patch))
8+
collector.destroy()
9+
for (var id in patchServer) return patchServer[id].chunks
10+
}
11+
function setPatch(destiny, chunks) {
12+
dopClient.core.setPatch(destiny, chunks, dopClient.core.setPatchMutator)
13+
}
14+
15+
test('Creating a new property with a new object must generate only one mutation in client', function(t) {
16+
var objServer = dopServer.register({})
17+
var objClient = dopClient.register({})
18+
var collectorServer = dopServer.collect()
19+
dopServer.set(objServer, 'prop', { new: 'object' })
20+
21+
var collectorClient = dopClient.collect()
22+
setPatch(objClient, getPatch(collectorServer))
23+
24+
t.equal(collectorClient.mutations.length, 1)
25+
t.deepEqual(objServer, objClient)
26+
collectorClient.destroy()
27+
t.end()
28+
})

0 commit comments

Comments
 (0)