Skip to content

Commit ffca6a9

Browse files
committed
Bug fixed
1 parent 93d061c commit ffca6a9

File tree

4 files changed

+79
-53
lines changed

4 files changed

+79
-53
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016-2017 Josema Gonzalez
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/core/mutators/splice.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,7 @@
22
dop.core.splice = function() {
33
var objectTarget = dop.getObjectTarget(this),
44
output = Array.prototype.splice.apply(objectTarget, arguments);
5-
if (output.length>0 && objectTarget !== this)
5+
if ((output.length>0 || arguments.length>2) && objectTarget !== this)
66
dop.core.storeSplice(objectTarget, output, Array.prototype.slice.call(arguments, 0));
77
return output;
88
};
9-
10-
11-
dop.core.storeSplice = function(array, spliced, args) {
12-
13-
var start = args[0],
14-
deleteCount = args[1],
15-
index = 0,
16-
total = array.length,
17-
tof,
18-
item,
19-
object_dop;
20-
21-
for (;index<total; ++index) {
22-
item = array[index];
23-
if (dop.util.isObjectStandard(item)) {
24-
25-
object_dop = dop.getObjectDop(item);
26-
27-
if (object_dop!==undefined && object_dop._ === array)
28-
object_dop[object_dop.length-1] = index;
29-
30-
else
31-
array[index] = dop.core.configureObject(
32-
item,
33-
dop.getObjectDop(array).concat(index),
34-
dop.data.object_data[dop.getObjectId(array)].options.proxy,
35-
array
36-
);
37-
}
38-
}
39-
40-
41-
dop.core.storeMutation({
42-
object: dop.getObjectProxy(array),
43-
splice: args,
44-
spliced: spliced
45-
});
46-
};

src/core/objects/proxyArrayHandler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ dop.core.proxyArrayHandler = {
1515
unshift: {value:function() {
1616
return dop.core.unshift.apply(this, arguments);
1717
}},
18-
fill: {value:function() {
19-
return dop.core.fill.apply(this, arguments);
20-
}},
18+
2119
move: {value:function() {
2220
return dop.core.move.apply(this, arguments);
2321
}},
22+
fill: {value:function() {
23+
return dop.core.fill.apply(this, arguments);
24+
}},
2425
reverse: {value:function() {
2526
return dop.core.reverse.apply(this, arguments);
2627
}},

test/arrays.js

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var array = [
1414
'string',
1515
true,
1616
-123,
17-
NaN,
17+
// NaN, // not working with deepEqual, cuz (NaN===NaN) -> false
1818
-Infinity,
1919
1.234153454354341,
2020
12313214234312324353454534534,
@@ -73,14 +73,6 @@ var paramsCases = [
7373
[-2,-2,'string',1,true,{},[]],
7474
];
7575

76-
function apply(t, paramsCase) {
77-
var register = dop.register(array.slice(0));
78-
var original = array.slice(0);
79-
var description = 'Splice case: '+JSON.stringify(paramsCase);
80-
t.equal(gify(register.splice.apply(register, paramsCase)), gify(original.splice.apply(original, paramsCase)), description);
81-
t.equal(gify(original), gify(register), description);
82-
}
83-
8476

8577

8678

@@ -94,9 +86,20 @@ test('for (i in ...) must return only array values', function(t) {
9486

9587

9688

97-
test('splice', function(t) {
89+
test('Array.splice', function(t) {
9890
paramsCases.forEach(function(paramsCase) {
99-
apply(t, paramsCase);
91+
var register = dop.register(array.slice(0));
92+
var original = array.slice(0);
93+
var description = JSON.stringify(paramsCase);
94+
t.equal(gify(register.splice.apply(register, paramsCase)), gify(original.splice.apply(original, paramsCase)), 'output case: '+description);
95+
t.equal(gify(original), gify(register), 'stringify case: '+description);
96+
t.deepEqual(original,register, 'deepEqual case: '+description);
97+
for (var index in register) {
98+
if (dop.util.isObject(register[index]) && dop.isRegistered(register[index])) {
99+
var object_dop = dop.getObjectDop(register[index]);
100+
t.equal(Number(index), Number(object_dop[object_dop.length-1]), 'correct path for subobject: '+index + ', Case:'+description);
101+
}
102+
}
100103
});
101104
t.end();
102105
});
@@ -110,6 +113,45 @@ test('splice', function(t) {
110113

111114

112115

116+
dop.core.storeSplice = function(array, spliced, args) {
117+
118+
var start = args[0],
119+
deleteCount = args[1],
120+
index = 0,
121+
total = array.length,
122+
tof,
123+
item,
124+
object_dop;
125+
126+
// console.log( '' );
127+
// console.log( args[1]>0, 'spliced:'+spliced.length, args.length>2 );
128+
for (;index<total; ++index) {
129+
item = array[index];
130+
if (dop.util.isObjectStandard(item)) {
131+
132+
object_dop = dop.getObjectDop(item);
133+
134+
if (object_dop!==undefined && object_dop._ === array)
135+
object_dop[object_dop.length-1] = index;
136+
137+
else
138+
array[index] = dop.core.configureObject(
139+
item,
140+
dop.getObjectDop(array).concat(index),
141+
dop.data.object_data[dop.getObjectId(array)].options.proxy,
142+
array
143+
);
144+
}
145+
}
146+
147+
148+
dop.core.storeMutation({
149+
object: dop.getObjectProxy(array),
150+
splice: args,
151+
spliced: spliced
152+
});
153+
};
154+
113155

114156

115157

0 commit comments

Comments
 (0)