@fluid-topics/ft-wc-utils 1.2.21 → 1.2.22
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/build/globals.min.js +13 -13
- package/build/redux/ReduxWatcher.d.ts +13 -0
- package/build/redux/ReduxWatcher.js +32 -0
- package/build/redux/index.d.ts +1 -0
- package/build/redux/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FtReduxStore } from "./FtReduxStore";
|
|
2
|
+
import { Unsubscribe } from "@reduxjs/toolkit";
|
|
3
|
+
export declare class ReduxWatcher<State, Value> {
|
|
4
|
+
protected readonly store: FtReduxStore<State>;
|
|
5
|
+
protected readonly valueSelector: (s: State) => Value;
|
|
6
|
+
protected readonly callback: (v: Value, s: State) => void;
|
|
7
|
+
constructor(store: FtReduxStore<State>, valueSelector: (s: State) => Value, callback: (v: Value, s: State) => void);
|
|
8
|
+
protected lastValue?: Value;
|
|
9
|
+
protected unsubscribe?: Unsubscribe;
|
|
10
|
+
watch(): this;
|
|
11
|
+
stop(): this;
|
|
12
|
+
}
|
|
13
|
+
export declare function watch<State, Value>(store: FtReduxStore<State>, valueSelector: (s: State) => Value, callback: (v: Value, s: State) => void): ReduxWatcher<State, Value>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { hasChanged } from "../helpers";
|
|
2
|
+
export class ReduxWatcher {
|
|
3
|
+
constructor(store, valueSelector, callback) {
|
|
4
|
+
this.store = store;
|
|
5
|
+
this.valueSelector = valueSelector;
|
|
6
|
+
this.callback = callback;
|
|
7
|
+
}
|
|
8
|
+
watch() {
|
|
9
|
+
this.stop();
|
|
10
|
+
this.lastValue = this.valueSelector(this.store.getState());
|
|
11
|
+
this.unsubscribe = this.store.subscribe(() => {
|
|
12
|
+
const state = this.store.getState();
|
|
13
|
+
const newValue = this.valueSelector(state);
|
|
14
|
+
if (hasChanged(this.lastValue, newValue)) {
|
|
15
|
+
this.callback(newValue, state);
|
|
16
|
+
this.lastValue = newValue;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
stop() {
|
|
22
|
+
if (this.unsubscribe != null) {
|
|
23
|
+
this.unsubscribe();
|
|
24
|
+
this.unsubscribe = undefined;
|
|
25
|
+
}
|
|
26
|
+
this.lastValue = undefined;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function watch(store, valueSelector, callback) {
|
|
31
|
+
return new ReduxWatcher(store, valueSelector, callback).watch();
|
|
32
|
+
}
|
package/build/redux/index.d.ts
CHANGED
package/build/redux/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-wc-utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.22",
|
|
4
4
|
"description": "Internal web components tools",
|
|
5
5
|
"author": "Fluid Topics <devtopics@antidot.net>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"mark.js": "8.11.1",
|
|
25
25
|
"moment": "2.29.4"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "29f6269b3af8af4c82f5ab2228d52b493ac3ddea"
|
|
28
28
|
}
|