@brightspace-ui/labs 2.11.5 → 2.11.6
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/package.json +1 -1
- package/src/utilities/reactive-store/constants.js +1 -0
- package/src/utilities/reactive-store/context-controllers.js +3 -2
- package/src/utilities/reactive-store/reactive-store.js +16 -7
- package/src/utilities/reactive-store/store-consumer.js +2 -1
- package/src/utilities/reactive-store/store-reactor.js +3 -1
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const combinedPropertiesSymbol = Symbol('combinedProperties');
|
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
ContextConsumer as LitContextConsumer,
|
|
4
4
|
ContextProvider as LitContextProvider
|
|
5
5
|
} from '@lit/context';
|
|
6
|
+
import { combinedPropertiesSymbol } from './constants.js';
|
|
6
7
|
import StoreReactor from './store-reactor.js';
|
|
7
8
|
|
|
8
9
|
export class ContextProvider {
|
|
9
10
|
constructor(host, StoreClass, store = new StoreClass()) {
|
|
10
|
-
const
|
|
11
|
+
const properties = StoreClass[combinedPropertiesSymbol];
|
|
11
12
|
const storeReactor = new StoreReactor(host, store, properties);
|
|
12
13
|
new LitContextProvider(host, {
|
|
13
14
|
context: createContext(StoreClass),
|
|
@@ -31,7 +32,7 @@ export class ContextProvider {
|
|
|
31
32
|
}
|
|
32
33
|
export class ContextConsumer {
|
|
33
34
|
constructor(host, StoreClass) {
|
|
34
|
-
const
|
|
35
|
+
const properties = StoreClass[combinedPropertiesSymbol];
|
|
35
36
|
const target = {
|
|
36
37
|
store: {},
|
|
37
38
|
storeReactor: {},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { combinedPropertiesSymbol } from './constants.js';
|
|
1
2
|
import { createContextControllers } from './context-controllers.js';
|
|
2
3
|
import PubSub from '../pub-sub/pub-sub.js';
|
|
3
4
|
import StoreConsumer from './store-consumer.js';
|
|
@@ -13,7 +14,11 @@ export default class ReactiveStore {
|
|
|
13
14
|
this._pubSub = new PubSub();
|
|
14
15
|
this._state = {};
|
|
15
16
|
|
|
16
|
-
this.#defineProperties(
|
|
17
|
+
this.#defineProperties();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static get [combinedPropertiesSymbol]() {
|
|
21
|
+
return getCombinedProperties(this.prototype);
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
createConsumer() {
|
|
@@ -37,12 +42,8 @@ export default class ReactiveStore {
|
|
|
37
42
|
this._pubSub.unsubscribe(callback);
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
#defineProperties(
|
|
41
|
-
|
|
42
|
-
this.#defineProperties(Object.getPrototypeOf(proto));
|
|
43
|
-
|
|
44
|
-
const { properties } = proto.constructor;
|
|
45
|
-
if (!properties) return;
|
|
45
|
+
#defineProperties() {
|
|
46
|
+
const properties = this.constructor[combinedPropertiesSymbol];
|
|
46
47
|
|
|
47
48
|
Object.keys(properties).forEach((property) => {
|
|
48
49
|
Object.defineProperty(this, property, {
|
|
@@ -62,3 +63,11 @@ export default class ReactiveStore {
|
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
|
|
67
|
+
function getCombinedProperties(proto) {
|
|
68
|
+
if (!(proto instanceof ReactiveStore)) return {};
|
|
69
|
+
return {
|
|
70
|
+
...getCombinedProperties(Object.getPrototypeOf(proto)),
|
|
71
|
+
...(proto.constructor.properties ?? {})
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { combinedPropertiesSymbol } from './constants.js';
|
|
1
2
|
import StoreReactor from './store-reactor.js';
|
|
2
3
|
|
|
3
4
|
export default class StoreConsumer {
|
|
4
|
-
constructor(host, store, properties = store.constructor
|
|
5
|
+
constructor(host, store, properties = store.constructor[combinedPropertiesSymbol]) {
|
|
5
6
|
const storeReactor = new StoreReactor(host, store, properties);
|
|
6
7
|
|
|
7
8
|
return new Proxy(store, {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { combinedPropertiesSymbol } from './constants.js';
|
|
2
|
+
|
|
1
3
|
export default class StoreReactor {
|
|
2
4
|
changedProperties;
|
|
3
5
|
|
|
4
|
-
constructor(host, store, properties = store.constructor
|
|
6
|
+
constructor(host, store, properties = store.constructor[combinedPropertiesSymbol]) {
|
|
5
7
|
this.#host = host;
|
|
6
8
|
this.#host.addController(this);
|
|
7
9
|
this.#store = store;
|