move context-provider element to element package to avoid circular dependencies
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import type { UmbControllerHostInterface, UmbControllerInterface } from '@umbraco-cms/controller';
|
||||
import { UmbContextToken } from '../context-token';
|
||||
import { UmbContextConsumer } from './context-consumer';
|
||||
import { UmbContextCallback } from './context-request.event';
|
||||
|
||||
import type { UmbControllerHostInterface, UmbControllerInterface } from '@umbraco-cms/controller';
|
||||
|
||||
export class UmbContextConsumerController<T = unknown>
|
||||
extends UmbContextConsumer<UmbControllerHostInterface, T>
|
||||
implements UmbControllerInterface
|
||||
|
||||
@@ -4,5 +4,4 @@ export * from './consume/context-request.event';
|
||||
export * from './provide/context-provider.controller';
|
||||
export * from './provide/context-provider';
|
||||
export * from './provide/context-provide.event';
|
||||
export * from './provide/context-provider.element';
|
||||
export * from './context-token';
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { expect, fixture, html } from '@open-wc/testing';
|
||||
import { customElement } from 'lit/decorators.js';
|
||||
import { UmbContextProviderElement } from './context-provider.element';
|
||||
import { UmbLitElement } from '@umbraco-cms/element';
|
||||
|
||||
@customElement('umb-context-test')
|
||||
export class ContextTestElement extends UmbLitElement {
|
||||
public value: string | null = null;
|
||||
constructor() {
|
||||
super();
|
||||
this.consumeContext<string>('test-context', (value) => {
|
||||
this.value = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
describe('UmbContextProvider', () => {
|
||||
let element: UmbContextProviderElement;
|
||||
let consumer: ContextTestElement;
|
||||
const contextValue = 'test-value';
|
||||
|
||||
beforeEach(async () => {
|
||||
element = await fixture(
|
||||
html` <umb-context-provider key="test-context" .value=${contextValue}>
|
||||
<umb-context-test></umb-context-test>
|
||||
</umb-context-provider>`
|
||||
);
|
||||
consumer = element.getElementsByTagName('umb-context-test')[0] as ContextTestElement;
|
||||
});
|
||||
|
||||
it('is defined with its own instance', () => {
|
||||
expect(element).to.be.instanceOf(UmbContextProviderElement);
|
||||
});
|
||||
|
||||
it('provides the context', () => {
|
||||
expect(consumer.value).to.equal(contextValue);
|
||||
});
|
||||
});
|
||||
@@ -1,35 +0,0 @@
|
||||
import { html } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { UmbLitElement } from '@umbraco-cms/element';
|
||||
|
||||
@customElement('umb-context-provider')
|
||||
export class UmbContextProviderElement extends UmbLitElement {
|
||||
/**
|
||||
* The value to provide to the context.
|
||||
* @required
|
||||
*/
|
||||
@property({ type: Object })
|
||||
value: unknown;
|
||||
|
||||
/**
|
||||
* The key to provide to the context.
|
||||
* @required
|
||||
*/
|
||||
@property({ type: String })
|
||||
key!: string;
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
if (!this.key) {
|
||||
throw new Error('The key property is required.');
|
||||
}
|
||||
if (!this.value) {
|
||||
throw new Error('The value property is required.');
|
||||
}
|
||||
this.provideContext(this.key, this.value);
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`<slot></slot>`;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { expect } from '@open-wc/testing';
|
||||
import { UmbContextConsumer } from '../consume/context-consumer';
|
||||
import { UmbContextRequestEventImplementation } from '../consume/context-request.event';
|
||||
import { UmbContextToken } from '../context-token';
|
||||
import { UmbContextProvider } from './context-provider';
|
||||
|
||||
class MyClass {
|
||||
|
||||
Reference in New Issue
Block a user