|
6 | 6 |
|
7 | 7 | exportModule("data-context", function factory() { |
8 | 8 |
|
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; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * Create a new proxy object with the same structure as the original object. |
|
953 | 953 | else { |
954 | 954 |
|
955 | 955 | 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 | | - } |
970 | 956 | } |
971 | 957 |
|
972 | 958 | if (typeof obj[k] === 'object') { |
|
1072 | 1058 |
|
1073 | 1059 | if (isOverwriting && index === undefined) { |
1074 | 1060 |
|
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."); |
1080 | 1062 | index = i; |
1081 | 1063 | } |
1082 | 1064 |
|
|
1117 | 1099 | arr.push(v); |
1118 | 1100 | } |
1119 | 1101 |
|
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 | | - |
1135 | 1102 | if (typeof arr[typeof index === "number" && index || i] === 'object') { |
1136 | 1103 |
|
1137 | 1104 | _setMetadata(arr[typeof index === "number" && index || i], meta); |
|
1359 | 1326 | } |
1360 | 1327 |
|
1361 | 1328 | else { _getValue(); } |
1362 | | - |
| 1329 | + |
1363 | 1330 | return; |
1364 | 1331 |
|
1365 | 1332 |
|
|
1689 | 1656 | fs.watchFile(filePath, (curr, prev) => { |
1690 | 1657 |
|
1691 | 1658 | if (lastModifiedTime > curr.mtimeMs) { return; } |
1692 | | - |
| 1659 | + |
1693 | 1660 | readFileSync(); |
1694 | 1661 | }); |
1695 | 1662 |
|
|
1754 | 1721 |
|
1755 | 1722 | if (typeof isDebug === 'boolean' && isDebug) { |
1756 | 1723 |
|
1757 | | - console.error(err); |
| 1724 | + pError(err); |
1758 | 1725 | } |
1759 | 1726 | } |
1760 | 1727 | } |
|
1830 | 1797 | } |
1831 | 1798 | }); |
1832 | 1799 |
|
| 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 | + |
1833 | 1805 | return createDataContext; |
1834 | 1806 | }); |
1835 | 1807 |
|
|
0 commit comments