rename rest of contextKeys to contextAlias

This commit is contained in:
Mads Rasmussen
2022-06-01 09:43:22 +02:00
parent f995539f0c
commit 52ec2fc896
3 changed files with 15 additions and 15 deletions

View File

@@ -3,7 +3,7 @@ import { UmbContextProvider } from './context-provider';
import { UmbContextConsumer } from './context-consumer';
import { UmbContextRequestEventImplementation, umbContextRequestEventType } from './context-request.event';
const testContextKey = 'my-test-context';
const testContextAlias = 'my-test-context';
class MyClass {
prop = 'value from provider';
@@ -14,7 +14,7 @@ describe('UmbContextConsumer', () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
consumer = new UmbContextConsumer(document.body, testContextKey, () => {});
consumer = new UmbContextConsumer(document.body, testContextAlias, () => {});
});
describe('Public API', () => {
@@ -33,19 +33,19 @@ describe('UmbContextConsumer', () => {
const event = await listener as unknown as UmbContextRequestEventImplementation;
expect(event).to.exist;
expect(event.type).to.eq(umbContextRequestEventType);
expect(event.contextAlias).to.eq(testContextKey);
expect(event.contextAlias).to.eq(testContextAlias);
});
});
});
it('works with UmbContextProvider', (done: any) => {
const provider = new UmbContextProvider(document.body, testContextKey, new MyClass());
const provider = new UmbContextProvider(document.body, testContextAlias, new MyClass());
provider.attach();
const element = document.createElement('div');
document.body.appendChild(element);
const localConsumer = new UmbContextConsumer(element, testContextKey, (_instance) => {
const localConsumer = new UmbContextConsumer(element, testContextAlias, (_instance) => {
expect(_instance.prop).to.eq('value from provider');
done();
})

View File

@@ -10,13 +10,13 @@ export class UmbContextConsumer {
/**
* Creates an instance of UmbContextConsumer.
* @param {EventTarget} target
* @param {string} _contextKey
* @param {string} _contextAlias
* @param {UmbContextCallback} _callback
* @memberof UmbContextConsumer
*/
constructor (
protected target: EventTarget,
private _contextKey: string,
private _contextAlias: string,
private _callback: UmbContextCallback
) {
@@ -26,7 +26,7 @@ export class UmbContextConsumer {
* @memberof UmbContextConsumer
*/
public request() {
const event = new UmbContextRequestEventImplementation(this._contextKey, this._callback);
const event = new UmbContextRequestEventImplementation(this._contextAlias, this._callback);
this.target.dispatchEvent(event);
}
@@ -42,7 +42,7 @@ export class UmbContextConsumer {
private _handleNewProvider = (event: Event) => {
if (!isUmbContextProvideEvent(event)) return;
if (this._contextKey === event.contextAlias) {
if (this._contextAlias === event.contextAlias) {
this.request();
}
}

View File

@@ -7,19 +7,19 @@ import { UmbContextProvideEventImplementation } from './context-provide.event';
*/
export class UmbContextProvider {
protected host: EventTarget;
private _contextKey: string;
private _contextAlias: string;
private _instance: unknown;
/**
* Creates an instance of UmbContextProvider.
* @param {EventTarget} host
* @param {string} contextKey
* @param {string} contextAlias
* @param {*} instance
* @memberof UmbContextProvider
*/
constructor (host: EventTarget, contextKey: string, instance: unknown) {
constructor (host: EventTarget, contextAlias: string, instance: unknown) {
this.host = host;
this._contextKey = contextKey;
this._contextAlias = contextAlias;
this._instance = instance;
}
@@ -28,7 +28,7 @@ export class UmbContextProvider {
*/
public attach () {
this.host.addEventListener(umbContextRequestEventType, this._handleContextRequest);
this.host.dispatchEvent(new UmbContextProvideEventImplementation(this._contextKey));
this.host.dispatchEvent(new UmbContextProvideEventImplementation(this._contextAlias));
}
/**
@@ -47,7 +47,7 @@ export class UmbContextProvider {
private _handleContextRequest = (event: Event) => {
if (!isUmbContextRequestEvent(event)) return;
if (event.contextAlias !== this._contextKey) return;
if (event.contextAlias !== this._contextAlias) return;
event.stopPropagation();
event.callback(this._instance);