@brightspace-ui/core 2.155.2 → 2.156.0
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.
@@ -4,10 +4,10 @@ The `ProviderMixin` and `RequesterMixin` can be used to create a DI-like system
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
Apply the `ProviderMixin` to the component that will be responsible for providing some data to components that request it
|
7
|
+
Apply the `ProviderMixin` to the component that will be responsible for providing some data to components that request it. Optionally, the `ProviderDelegate` class can be used to specify a function that will provide the value when requested.
|
8
8
|
|
9
9
|
```js
|
10
|
-
import { ProviderMixin } from '@brightspace-ui/core/mixins/provider/provider-mixin.js';
|
10
|
+
import { ProviderMixin, ProviderDelegate } from '@brightspace-ui/core/mixins/provider/provider-mixin.js';
|
11
11
|
|
12
12
|
class InterestingFactProvider extends ProviderMixin(LitElement) {
|
13
13
|
constructor() {
|
@@ -15,6 +15,8 @@ class InterestingFactProvider extends ProviderMixin(LitElement) {
|
|
15
15
|
this.provideInstance('d2l-interesting-fact-string', 'Olives are not the same as fish');
|
16
16
|
this.provideInstance('d2l-interesting-fact-object', { fact: 'Olives are not the same as fish' });
|
17
17
|
this.provideInstance('d2l-interesting-fact-function', x => `${x} are not the same as fish`);
|
18
|
+
this.provideInstance('d2l-interesting-fact-delegate', new ProviderDelegate(() => 'Olives are not the same as fish'));
|
19
|
+
this.provideInstance('d2l-interesting-fact-async-delegate', new ProviderDelegate(() => new Promise(...)));
|
18
20
|
}
|
19
21
|
}
|
20
22
|
```
|
@@ -1,9 +1,20 @@
|
|
1
|
+
export class ProviderDelegate {
|
2
|
+
constructor(delegate) {
|
3
|
+
this.delegate = delegate;
|
4
|
+
}
|
5
|
+
}
|
6
|
+
|
1
7
|
export function provideInstance(node, key, obj) {
|
2
8
|
if (!node._providerInstances) {
|
3
9
|
node._providerInstances = new Map();
|
4
10
|
node.addEventListener('d2l-request-instance', e => {
|
5
11
|
if (node._providerInstances.has(e.detail.key)) {
|
6
|
-
|
12
|
+
const instance = node._providerInstances.get(e.detail.key);
|
13
|
+
if (instance instanceof ProviderDelegate) {
|
14
|
+
e.detail.instance = instance.delegate();
|
15
|
+
} else {
|
16
|
+
e.detail.instance = instance;
|
17
|
+
}
|
7
18
|
e.stopPropagation();
|
8
19
|
}
|
9
20
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.156.0",
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
5
5
|
"type": "module",
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|