-
Notifications
You must be signed in to change notification settings - Fork 25
/
skeleton-group-mixin.js
49 lines (39 loc) · 1.59 KB
/
skeleton-group-mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { dedupeMixin } from '@open-wc/dedupe-mixin';
import { SkeletonMixin } from './skeleton-mixin.js';
import { SubscriberRegistryController } from '../../controllers/subscriber/subscriberControllers.js';
export const SkeletonGroupMixin = dedupeMixin(superclass => class extends SkeletonMixin(superclass) {
static get properties() {
return {
_anySubscribersWithSkeletonActive : { state: true },
};
}
constructor() {
super();
this._anySubscribersWithSkeletonActive = false;
this._skeletonSubscribers = new SubscriberRegistryController(this, 'skeleton', {
onSubscribe: this.onSubscriberChange.bind(this),
onUnsubscribe: this.onSubscriberChange.bind(this),
updateSubscribers: this._checkSubscribersSkeletonState.bind(this),
});
}
updated(changedProperties) {
super.updated(changedProperties);
if (changedProperties.has('skeleton')) {
this._skeletonSubscribers.updateSubscribers();
}
}
onSubscriberChange() {
this._skeletonSubscribers.updateSubscribers();
}
_checkSubscribersSkeletonState(subscribers) {
this._anySubscribersWithSkeletonActive = [...subscribers.values()].some(subscriber => (
subscriber._skeletonSetExplicitly || subscriber._anySubscribersWithSkeletonActive
));
this.setSkeletonActive(this._skeletonSetExplicitly || this._anySubscribersWithSkeletonActive || this._skeletonSetByParent);
subscribers.forEach(subscriber => {
subscriber.setSkeletonActive(this._skeletonActive);
subscriber.setSkeletonSetByParent(this._skeletonActive && !subscriber._skeletonSetExplicitly);
});
this._parentSkeleton?.registry?.onSubscriberChange();
}
});