@flowgram.ai/variable-core 0.3.1 → 0.3.3

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/index.d.mts CHANGED
@@ -133,9 +133,7 @@ declare class ScopeAvailableData {
133
133
  * Track Variable Change (Includes type update and children update) By KeyPath
134
134
  * @returns
135
135
  */
136
- trackByKeyPath(keyPath: string[] | undefined, cb: (variable?: BaseVariableField | undefined) => void, opts?: {
137
- triggerOnInit?: boolean;
138
- }): Disposable;
136
+ trackByKeyPath<Data = BaseVariableField | undefined>(keyPath: string[] | undefined, cb: (variable?: Data) => void, opts?: SubscribeConfig<BaseVariableField | undefined, Data>): Disposable;
139
137
  }
140
138
 
141
139
  /**
package/dist/index.d.ts CHANGED
@@ -133,9 +133,7 @@ declare class ScopeAvailableData {
133
133
  * Track Variable Change (Includes type update and children update) By KeyPath
134
134
  * @returns
135
135
  */
136
- trackByKeyPath(keyPath: string[] | undefined, cb: (variable?: BaseVariableField | undefined) => void, opts?: {
137
- triggerOnInit?: boolean;
138
- }): Disposable;
136
+ trackByKeyPath<Data = BaseVariableField | undefined>(keyPath: string[] | undefined, cb: (variable?: Data) => void, opts?: SubscribeConfig<BaseVariableField | undefined, Data>): Disposable;
139
137
  }
140
138
 
141
139
  /**
package/dist/index.js CHANGED
@@ -1855,16 +1855,25 @@ var ScopeAvailableData = class {
1855
1855
  * @returns
1856
1856
  */
1857
1857
  trackByKeyPath(keyPath = [], cb, opts) {
1858
- const { triggerOnInit = true } = opts || {};
1858
+ const { triggerOnInit = true, debounceAnimation, selector } = opts || {};
1859
1859
  return subsToDisposable(
1860
1860
  (0, import_rxjs4.merge)(this.anyVariableChange$, this.variables$).pipe(
1861
1861
  triggerOnInit ? (0, import_rxjs4.startWith)() : (0, import_rxjs4.tap)(() => null),
1862
1862
  (0, import_rxjs4.map)(() => {
1863
1863
  const v = this.getByKeyPath(keyPath);
1864
- return { v, hash: v?.hash };
1864
+ return selector ? selector(v) : v;
1865
1865
  }),
1866
- (0, import_rxjs4.distinctUntilKeyChanged)("hash"),
1867
- (0, import_rxjs4.map)(({ v }) => v)
1866
+ (0, import_rxjs4.distinctUntilChanged)(
1867
+ (a, b) => (0, import_fast_equals7.shallowEqual)(a, b),
1868
+ (value) => {
1869
+ if (value instanceof ASTNode) {
1870
+ return value.hash;
1871
+ }
1872
+ return value;
1873
+ }
1874
+ ),
1875
+ // 每个 animationFrame 内所有更新合并成一个
1876
+ debounceAnimation ? (0, import_rxjs4.debounceTime)(0, import_rxjs4.animationFrameScheduler) : (0, import_rxjs4.tap)(() => null)
1868
1877
  ).subscribe(cb)
1869
1878
  );
1870
1879
  }