Skip to content

Commit fa90530

Browse files
committed
v2.0
1 parent e16d251 commit fa90530

3 files changed

Lines changed: 14 additions & 42 deletions

File tree

index.js

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
exportModule("data-context", function factory() {
88

9-
//var isDebug = true;
10-
var ignoreMetadata = false;
9+
var isDebug = this.document && Array.from(document.scripts).find(function (s) { return s.src.includes('data-context-binding'); })?.attributes.debug || false,
10+
ignoreMetadata = false;
1111

1212
/**
1313
* Create a new proxy object with the same structure as the original object.
@@ -953,20 +953,6 @@
953953
else {
954954

955955
obj[k] = v;
956-
957-
if (!v?._isDataContext && obj !== val && obj[k] === val?.[k]
958-
|| v?._isDataContext && !v.isChanged) {
959-
960-
if (obj?._isDataContext) {
961-
962-
obj._modified.splice(obj._modified.indexOf(k), 1);
963-
}
964-
965-
if (v?._isDataContext) {
966-
967-
v._isModified = false;
968-
}
969-
}
970956
}
971957

972958
if (typeof obj[k] === 'object') {
@@ -1072,11 +1058,7 @@
10721058

10731059
if (isOverwriting && index === undefined) {
10741060

1075-
if (typeof isDebug === 'boolean' && isDebug) {
1076-
1077-
throw "Overwriting data -> array index must be.";
1078-
}
1079-
console.warn("Overwriting data -> array index must be.");
1061+
pWarn("Overwriting data -> array index must be.");
10801062
index = i;
10811063
}
10821064

@@ -1117,21 +1099,6 @@
11171099
arr.push(v);
11181100
}
11191101

1120-
if (!v?._isDataContext && arr !== val
1121-
&& arr[typeof index === "number" && index || i] === val?.[typeof index === "number" && index || i]
1122-
|| v?._isDataContext && !v._modified.length) {
1123-
1124-
if (arr?._isDataContext) {
1125-
1126-
arr._modified.splice(arr._modified.indexOf(typeof index === "number" && index || i), 1);
1127-
}
1128-
1129-
if (v?._isDataContext) {
1130-
1131-
v._isModified = false;
1132-
}
1133-
}
1134-
11351102
if (typeof arr[typeof index === "number" && index || i] === 'object') {
11361103

11371104
_setMetadata(arr[typeof index === "number" && index || i], meta);
@@ -1359,7 +1326,7 @@
13591326
}
13601327

13611328
else { _getValue(); }
1362-
1329+
13631330
return;
13641331

13651332

@@ -1689,7 +1656,7 @@
16891656
fs.watchFile(filePath, (curr, prev) => {
16901657

16911658
if (lastModifiedTime > curr.mtimeMs) { return; }
1692-
1659+
16931660
readFileSync();
16941661
});
16951662

@@ -1754,7 +1721,7 @@
17541721

17551722
if (typeof isDebug === 'boolean' && isDebug) {
17561723

1757-
console.error(err);
1724+
pError(err);
17581725
}
17591726
}
17601727
}
@@ -1830,6 +1797,11 @@
18301797
}
18311798
});
18321799

1800+
// Debugging
1801+
function pDebug(...args) { if (isDebug) { console.log(`[ DEBUG ] `, ...args); } }
1802+
function pWarn(...args) { if (isDebug) { console.warn(`[ WARN ] `, ...args); } }
1803+
function pError(...args) { if (isDebug) { console.error(`[ ERROR ] `, ...args); } }
1804+
18331805
return createDataContext;
18341806
});
18351807

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.22",
4+
"version": "2.0.0-beta.23",
55
"license": "MIT",
66
"keywords": [
77
"on",

0 commit comments

Comments
 (0)