Skip to content

Commit 9a691a6

Browse files
committed
v2.0
1 parent 22ae50b commit 9a691a6

3 files changed

Lines changed: 44 additions & 31 deletions

File tree

index.js

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,11 @@
576576
}
577577
catch (e) {
578578

579-
throw "[ ERROR ] " + e
580-
+ " In parsing position: " + it.position + " '" + it.current + "' => "
579+
throw ": In parsing position: " + it.position + " '" + it.current + "' => "
581580
+ it.text.substring(it.position < 10 ? 0 : it.position - 10, it.position + 10)
582581
.replace(/\r/g, "\\r")
583-
.replace(/\n/g, "\\n");
582+
.replace(/\n/g, "\\n")
583+
+ "\n" + e.message + e.stack;
584584
}
585585

586586
_setMetadata(value, meta);
@@ -671,31 +671,7 @@
671671

672672
function _get(val, def) {
673673

674-
if (it.current === '\r' && it.following === '\r') {
675-
676-
if (!def._isDataContext) {
677-
678-
def = createDataContext(def);
679-
def._isModified = true;
680-
}
681-
if (_typeof(val) === 'array') {
682-
683-
val.length = 0;
684-
}
685-
if (val?._events) { def._events = val._events; }
686-
if (val?._propertyName && val._parent) {
687-
688-
def._parent = val._parent;
689-
def._propertyName = val._propertyName;
690-
val._parent[val._propertyName] = def;
691-
}
692-
693-
it.next();
694-
it.next();
695-
696-
return def;
697-
}
698-
else if (_typeof(val) !== _typeof(def)) {
674+
if (_typeof(val) !== _typeof(def)) {
699675

700676
if (val?._isDataContext) {
701677

@@ -914,6 +890,15 @@
914890

915891
it.next();
916892

893+
var isNewObject = it.current === '\r' && it.following === '\r',
894+
keys = [];
895+
896+
if (isNewObject) {
897+
898+
it.next();
899+
it.next();
900+
}
901+
917902
var obj = _get(val, {});
918903

919904
_setMetadata(obj, meta);
@@ -937,6 +922,8 @@
937922

938923
var k = _key();
939924

925+
keys.push(k);
926+
940927
_whitespace();
941928

942929
var v = _value(obj[k] || val?.[k]);
@@ -1003,6 +990,18 @@
1003990
it.next();
1004991
}
1005992

993+
if (isNewObject) {
994+
995+
for (var k of Object.keys(obj)) {
996+
997+
if (!keys.includes(k)) {
998+
999+
delete obj[k];
1000+
obj._isModified = true;
1001+
}
1002+
}
1003+
}
1004+
10061005
return obj;
10071006
}
10081007
}
@@ -1040,6 +1039,14 @@
10401039

10411040
it.next();
10421041

1042+
var isNewArray = it.current === '\r' && it.following === '\r';
1043+
1044+
if (isNewArray) {
1045+
1046+
it.next();
1047+
it.next();
1048+
}
1049+
10431050
var arr = _get(val, []);
10441051

10451052
_setMetadata(arr, meta);
@@ -1142,6 +1149,12 @@
11421149
it.next();
11431150
}
11441151

1152+
if (isNewArray && val?.length > i) {
1153+
1154+
val.length = i;
1155+
arr._isModified = true;
1156+
}
1157+
11451158
return arr;
11461159
}
11471160
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "data-context",
33
"description": "Watch data changes in the browser and node.js",
4-
"version": "2.0.0-beta.21",
4+
"version": "2.0.0-beta.22",
55
"license": "MIT",
66
"keywords": [
77
"on",

0 commit comments

Comments
 (0)