@flowgram.ai/variable-core 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -55,6 +55,9 @@ var VariableTable = class {
55
55
  this.parentTable = parentTable;
56
56
  this.table = /* @__PURE__ */ new Map();
57
57
  this.toDispose = new DisposableCollection();
58
+ /**
59
+ * @deprecated
60
+ */
58
61
  this.onDataChangeEmitter = new Emitter();
59
62
  this.variables$ = new Subject();
60
63
  // 监听变量列表中的单个变量变化
@@ -79,7 +82,9 @@ var VariableTable = class {
79
82
  this.toDispose.pushAll([
80
83
  this.onDataChangeEmitter,
81
84
  // active share()
82
- this.onAnyVariableChange(() => null)
85
+ this.onAnyVariableChange(() => {
86
+ this.bumpVersion();
87
+ })
83
88
  ]);
84
89
  }
85
90
  /**
@@ -108,7 +113,7 @@ var VariableTable = class {
108
113
  return disposables;
109
114
  }
110
115
  fireChange() {
111
- this._version++;
116
+ this.bumpVersion();
112
117
  this.onDataChangeEmitter.fire();
113
118
  this.variables$.next(this.variables);
114
119
  this.parentTable?.fireChange();
@@ -116,6 +121,12 @@ var VariableTable = class {
116
121
  get version() {
117
122
  return this._version;
118
123
  }
124
+ bumpVersion() {
125
+ this._version = this._version + 1;
126
+ if (this._version === Number.MAX_SAFE_INTEGER) {
127
+ this._version = 0;
128
+ }
129
+ }
119
130
  get variables() {
120
131
  return Array.from(this.table.values());
121
132
  }
@@ -1620,6 +1631,9 @@ var ScopeOutputData = class {
1620
1631
  get globalVariableTable() {
1621
1632
  return this.scope.variableEngine.globalVariableTable;
1622
1633
  }
1634
+ get version() {
1635
+ return this.variableTable.version;
1636
+ }
1623
1637
  /**
1624
1638
  * @deprecated use onListOrAnyVarChange instead
1625
1639
  */
@@ -1684,8 +1698,9 @@ var ScopeOutputData = class {
1684
1698
  // src/scope/datas/scope-available-data.ts
1685
1699
  import {
1686
1700
  Subject as Subject3,
1701
+ animationFrameScheduler as animationFrameScheduler2,
1702
+ debounceTime as debounceTime2,
1687
1703
  distinctUntilChanged as distinctUntilChanged3,
1688
- distinctUntilKeyChanged,
1689
1704
  map as map3,
1690
1705
  merge as merge2,
1691
1706
  share as share3,
@@ -1702,6 +1717,7 @@ var ScopeAvailableData = class {
1702
1717
  constructor(scope) {
1703
1718
  this.scope = scope;
1704
1719
  this.memo = createMemo();
1720
+ this._version = 0;
1705
1721
  this.refresh$ = new Subject3();
1706
1722
  this._variables = [];
1707
1723
  /**
@@ -1746,10 +1762,12 @@ var ScopeAvailableData = class {
1746
1762
  this._variables = _variables;
1747
1763
  this.memo.clear();
1748
1764
  this.onDataChangeEmitter.fire(this._variables);
1765
+ this.bumpVersion();
1749
1766
  this.onListOrAnyVarChangeEmitter.fire(this._variables);
1750
1767
  }),
1751
1768
  this.onAnyVariableChange(() => {
1752
1769
  this.onDataChangeEmitter.fire(this._variables);
1770
+ this.bumpVersion();
1753
1771
  this.onListOrAnyVarChangeEmitter.fire(this._variables);
1754
1772
  }),
1755
1773
  Disposable3.create(() => {
@@ -1761,6 +1779,15 @@ var ScopeAvailableData = class {
1761
1779
  get globalVariableTable() {
1762
1780
  return this.scope.variableEngine.globalVariableTable;
1763
1781
  }
1782
+ get version() {
1783
+ return this._version;
1784
+ }
1785
+ bumpVersion() {
1786
+ this._version = this._version + 1;
1787
+ if (this._version === Number.MAX_SAFE_INTEGER) {
1788
+ this._version = 0;
1789
+ }
1790
+ }
1764
1791
  // 刷新可访问变量列表
1765
1792
  refresh() {
1766
1793
  if (this.scope.disposed) {
@@ -1818,16 +1845,25 @@ var ScopeAvailableData = class {
1818
1845
  * @returns
1819
1846
  */
1820
1847
  trackByKeyPath(keyPath = [], cb, opts) {
1821
- const { triggerOnInit = true } = opts || {};
1848
+ const { triggerOnInit = true, debounceAnimation, selector } = opts || {};
1822
1849
  return subsToDisposable(
1823
1850
  merge2(this.anyVariableChange$, this.variables$).pipe(
1824
1851
  triggerOnInit ? startWith() : tap2(() => null),
1825
1852
  map3(() => {
1826
1853
  const v = this.getByKeyPath(keyPath);
1827
- return { v, hash: v?.hash };
1854
+ return selector ? selector(v) : v;
1828
1855
  }),
1829
- distinctUntilKeyChanged("hash"),
1830
- map3(({ v }) => v)
1856
+ distinctUntilChanged3(
1857
+ (a, b) => shallowEqual7(a, b),
1858
+ (value) => {
1859
+ if (value instanceof ASTNode) {
1860
+ return value.hash;
1861
+ }
1862
+ return value;
1863
+ }
1864
+ ),
1865
+ // 每个 animationFrame 内所有更新合并成一个
1866
+ debounceAnimation ? debounceTime2(0, animationFrameScheduler2) : tap2(() => null)
1831
1867
  ).subscribe(cb)
1832
1868
  );
1833
1869
  }