Skip to content

Commit

Permalink
rename context consume event const
Browse files Browse the repository at this point in the history
  • Loading branch information
nielslyngsoe committed Nov 7, 2024
1 parent fffd044 commit fb30dde
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/libs/context-api/consume/context-consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UmbContextProvider } from '../provide/context-provider.js';
import { UmbContextToken } from '../token/context-token.js';
import { UmbContextConsumer } from './context-consumer.js';
import type { UmbContextRequestEventImplementation } from './context-request.event.js';
import { UMB_CONTENT_REQUEST_EVENT_TYPE } from './context-request.event.js';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE } from './context-request.event.js';
import { expect, oneEvent } from '@open-wc/testing';

const testContextAlias = 'my-test-context';
Expand Down Expand Up @@ -38,13 +38,13 @@ describe('UmbContextConsumer', () => {

describe('events', () => {
it('dispatches context request event when constructed', async () => {
const listener = oneEvent(window, UMB_CONTENT_REQUEST_EVENT_TYPE);
const listener = oneEvent(window, UMB_CONTEXT_REQUEST_EVENT_TYPE);

consumer.hostConnected();

const event = (await listener) as unknown as UmbContextRequestEventImplementation;
expect(event).to.exist;
expect(event.type).to.eq(UMB_CONTENT_REQUEST_EVENT_TYPE);
expect(event.type).to.eq(UMB_CONTEXT_REQUEST_EVENT_TYPE);
expect(event.contextAlias).to.eq(testContextAlias);
consumer.hostDisconnected();
});
Expand Down
9 changes: 7 additions & 2 deletions src/libs/context-api/consume/context-request.event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const UMB_CONTENT_REQUEST_EVENT_TYPE = 'umb:context-request';
export const UMB_CONTEXT_REQUEST_EVENT_TYPE = 'umb:context-request';
/**
* @deprecated use UMB_CONTEXT_REQUEST_EVENT_TYPE
* This will be removed in Umbraco 17
*/
export const UMB_CONTENT_REQUEST_EVENT_TYPE = UMB_CONTEXT_REQUEST_EVENT_TYPE;
export const UMB_DEBUG_CONTEXT_EVENT_TYPE = 'umb:debug-contexts';

export type UmbContextCallback<T> = (instance: T) => void;
Expand Down Expand Up @@ -29,7 +34,7 @@ export class UmbContextRequestEventImplementation<ResultType = unknown>
public readonly callback: (context: ResultType) => boolean,
public readonly stopAtContextMatch: boolean = true,
) {
super(UMB_CONTENT_REQUEST_EVENT_TYPE, { bubbles: true, composed: true, cancelable: true });
super(UMB_CONTEXT_REQUEST_EVENT_TYPE, { bubbles: true, composed: true, cancelable: true });
}

clone() {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/context-api/provide/context-boundary.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UmbContextRequestEvent } from '../consume/context-request.event.js';
import type { UmbContextToken } from '../token/index.js';
import { UMB_CONTENT_REQUEST_EVENT_TYPE } from '../consume/context-request.event.js';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE } from '../consume/context-request.event.js';
import { UmbContextProvideEventImplementation } from './context-provide.event.js';

/**
Expand All @@ -24,7 +24,7 @@ export class UmbContextBoundary {
const idSplit = contextIdentifier.toString().split('#');
this.#contextAlias = idSplit[0];

this.#eventTarget.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
this.#eventTarget.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/libs/context-api/provide/context-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UmbContextRequestEvent } from '../consume/context-request.event.js';
import type { UmbContextToken } from '../token/index.js';
import { UMB_CONTENT_REQUEST_EVENT_TYPE, UMB_DEBUG_CONTEXT_EVENT_TYPE } from '../consume/context-request.event.js';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE, UMB_DEBUG_CONTEXT_EVENT_TYPE } from '../consume/context-request.event.js';
import { UmbContextProvideEventImplementation } from './context-provide.event.js';

/**
Expand Down Expand Up @@ -41,7 +41,7 @@ export class UmbContextProvider<BaseType = unknown, ResultType extends BaseType
this.#apiAlias = idSplit[1] ?? 'default';
this.#instance = instance;

this.#eventTarget.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
this.#eventTarget.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/packages/core/modal/component/modal.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { UMB_ROUTE_CONTEXT, type UmbRouterSlotElement } from '@umbraco-cms/backo
import { createExtensionElement } from '@umbraco-cms/backoffice/extension-api';
import type { UmbContextRequestEvent } from '@umbraco-cms/backoffice/context-api';
import {
UMB_CONTENT_REQUEST_EVENT_TYPE,
UMB_CONTEXT_REQUEST_EVENT_TYPE,
UmbContextBoundary,
UmbContextProvider,
} from '@umbraco-cms/backoffice/context-api';
Expand Down Expand Up @@ -63,7 +63,7 @@ export class UmbModalElement extends UmbLitElement {

// The following code is the context api proxy.
// It re-dispatches the context api request event to the origin target of this modal, in other words the element that initiated the modal. [NL]
this.element.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
this.element.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
if (!this.#modalContext) return;
// Note for this hack (The if-sentence): [NL]
// We do not currently have a good enough control to ensure that the proxy is last, meaning if another context is provided at this element, it might respond after the proxy event has been dispatched.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UMB_CONTENT_REQUEST_EVENT_TYPE, type UmbContextRequestEvent } from '@umbraco-cms/backoffice/context-api';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE, type UmbContextRequestEvent } from '@umbraco-cms/backoffice/context-api';
import type { RawEditorOptions } from '@umbraco-cms/backoffice/external/tinymce';
import { UUIIconRequestEvent } from '@umbraco-cms/backoffice/external/uui';

Expand Down Expand Up @@ -34,7 +34,7 @@ export const defaultFallbackConfig: RawEditorOptions = {
init_instance_callback: function (editor) {
// The following code is the context api proxy. [NL]
// It re-dispatches the context api request event to the origin target of this modal, in other words the element that initiated the modal. [NL]
editor.dom.doc.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
editor.dom.doc.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
if (!editor.iframeElement) return;

event.stopImmediatePropagation();
Expand Down

0 comments on commit fb30dde

Please sign in to comment.