|
1 | | - |
2 | 1 | /** Copyright (c) Manuel Lõhmus (MIT License). */ |
3 | 2 |
|
4 | 3 | "use strict"; |
|
211 | 210 | delete emitToParent.timeout; |
212 | 211 |
|
213 | 212 | _this.emit("-change", { eventName: "-change", target: _this }); |
214 | | - }, 0, this); |
| 213 | + }, 10, this); |
215 | 214 | } |
216 | 215 |
|
217 | 216 | if ((eventName === '-' || eventName === '-change') && |
|
469 | 468 | } |
470 | 469 |
|
471 | 470 | target.emitToParent("-", { eventName, target, propertyPath: [property], oldValue, newValue }); |
| 471 | + target.emit(property, { eventName, target, propertyPath: [property], oldValue, newValue }); |
472 | 472 |
|
473 | 473 | setModified(target, property); |
474 | 474 |
|
475 | | - target.emit(property, { eventName, target, propertyPath: [property], oldValue, newValue }); |
476 | 475 | target.emitToParent("-change", { eventName: "-change", target }); |
477 | 476 |
|
478 | 477 | return ret; |
|
674 | 673 |
|
675 | 674 | if (it.current === '\r' && it.following === '\r') { |
676 | 675 |
|
677 | | - if (!def._isDataContext) { def = createDataContext(def); } |
| 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 | + } |
678 | 685 | if (val?._events) { def._events = val._events; } |
679 | 686 | if (val?._propertyName && val._parent) { |
680 | 687 |
|
681 | 688 | def._parent = val._parent; |
682 | 689 | def._propertyName = val._propertyName; |
| 690 | + val._parent[val._propertyName] = def; |
683 | 691 | } |
684 | 692 |
|
685 | 693 | it.next(); |
|
960 | 968 | obj[k] = v; |
961 | 969 |
|
962 | 970 | if (!v?._isDataContext && obj !== val && obj[k] === val?.[k] |
963 | | - || v?._isDataContext && !v._modified.length) { |
| 971 | + || v?._isDataContext && !v.isChanged) { |
964 | 972 |
|
965 | 973 | if (obj?._isDataContext) { |
966 | 974 |
|
|
1402 | 1410 | ? Object.values(value._modified).sort() |
1403 | 1411 | : Object.keys(value); |
1404 | 1412 |
|
| 1413 | + if (type === "array") { keys = keys.filter(function (k) { return Number.isInteger(Number(k)) }); } |
| 1414 | + |
1405 | 1415 | // write emty object |
1406 | 1416 | if (!keys.length) { |
1407 | 1417 |
|
|
1657 | 1667 |
|
1658 | 1668 | var isInitData = !fs.existsSync(filePath), |
1659 | 1669 | isFileProcessing = false, |
1660 | | - writeTimeout; |
| 1670 | + writeTimeout, |
| 1671 | + lastModifiedTime = Date.now(); |
1661 | 1672 |
|
1662 | 1673 | if (!data) { data = createDataContext({}); } |
1663 | 1674 | if (!data._isDataContext) { data = createDataContext(data); } |
1664 | 1675 |
|
1665 | | - fs.watchFile(filePath, (curr, prev) => { readFileSync(); }); |
| 1676 | + fs.watchFile(filePath, (curr, prev) => { |
| 1677 | + |
| 1678 | + if (lastModifiedTime > curr.mtimeMs) { return; } |
| 1679 | + |
| 1680 | + readFileSync(); |
| 1681 | + }); |
1666 | 1682 |
|
1667 | 1683 | data.on('-change', (event) => { |
1668 | 1684 |
|
|
1738 | 1754 | writeTimeout = setTimeout(function () { |
1739 | 1755 |
|
1740 | 1756 | wait(write); |
1741 | | - }, 500); |
| 1757 | + }, 5000); |
1742 | 1758 |
|
1743 | 1759 |
|
1744 | 1760 | function write() { |
|
1755 | 1771 | fs.writeFileSync(filePath, strJson, { encoding: 'utf8', flag: 'w', flush: true }); |
1756 | 1772 |
|
1757 | 1773 | //data.resetChanges(); |
| 1774 | + lastModifiedTime = Date.now(); |
1758 | 1775 | isFileProcessing = false; |
1759 | 1776 |
|
1760 | 1777 | if (onDataChange) { |
|
0 commit comments