Skip to content

Commit

Permalink
feat(internal): Base controller - Merge event dispatch options with d…
Browse files Browse the repository at this point in the history
…efaults. Make it easier to dispatch events with detail.target, bubbles, and cancellable while specifying other options
  • Loading branch information
Sub-Xaero committed Mar 2, 2021
1 parent 9e0a55e commit e4a2b89
Show file tree
Hide file tree
Showing 27 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion dist/auto_submit_form_controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseController } from "./base_controller";
export declare class AutoSubmitFormController extends BaseController {
private boundHandler;
initialize(): void;
connect(): void;
disconnect(): void;
private handler;
Expand Down
2 changes: 1 addition & 1 deletion dist/auto_submit_form_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/autosize_controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BaseController } from "./base_controller";
export declare class AutosizeController extends BaseController {
private boundHandler;
initialize(): void;
connect(): void;
windowResize(): void;
private handler;
private _handler;
private autosize;
}
//# sourceMappingURL=autosize_controller.d.ts.map
2 changes: 1 addition & 1 deletion dist/autosize_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/base_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/char_count_controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export declare class CharCountController extends BaseController {
hasMaxValue: boolean;
errorClass: string;
hasErrorClass: boolean;
boundHandler: () => void;
initialize(): void;
connect(): void;
disconnect(): void;
updateCharCount(): void;
isValidCount(count: number): boolean;
private _updateCharCount;
private _isValidCount;
}
//# sourceMappingURL=char_count_controller.d.ts.map
2 changes: 1 addition & 1 deletion dist/char_count_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/detect_dirty_controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BaseController } from "./base_controller";
export declare class DetectDirtyController extends BaseController {
initialValue: string | boolean | null;
boundHandler: (event?: Event | undefined) => void;
initialize(): void;
connect(): void;
disconnect(): void;
restore(): void;
private handler;
private checkDirty;
}
export declare function isDirty(element: HTMLElement): boolean;
//# sourceMappingURL=detect_dirty_controller.d.ts.map
2 changes: 1 addition & 1 deletion dist/detect_dirty_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions dist/limited_selection_checkboxes_controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export declare class LimitedSelectionCheckboxesController extends BaseController
readonly inputTargets: HTMLInputElement[];
readonly maxValue: number;
readonly messageValue: string;
maxSelections: number;
boundHandleInputs: (event: Event) => void;
initialize(): void;
connect(): void;
disconnect(): void;
handleInputs(event: Event): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/limited_selection_checkboxes_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/password_confirm_controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export declare class PasswordConfirmController extends BaseController {
readonly passwordTargets: HTMLInputElement[];
readonly errorClass: string;
readonly hasErrorClass: boolean;
private boundCheckPasswordsMatch;
initialize(): void;
connect(): void;
disconnect(): void;
private allPasswordsMatch;
Expand Down
2 changes: 1 addition & 1 deletion dist/password_confirm_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/responsive_iframe_controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ResponsiveIframeMessage {
height: number;
}
export declare class ResponsiveIframeWrapperController extends BaseController {
boundMessageReceived: (message: MessageEvent<ResponsiveIframeMessage>) => void;
initialize(): void;
connect(): void;
disconnect(): void;
messageReceived(message: MessageEvent<ResponsiveIframeMessage>): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/responsive_iframe_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stimulus-library.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.modern.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.modern.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.umd.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/utilities/elements.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export declare function isHTMLLinkElement(element: Element): element is HTMLLinkElement;
export declare function isHTMLFormElement(element: Element): element is HTMLFormElement;
export declare function isHTMLInputElement(element: Element): element is HTMLInputElement;
export declare function isHTMLImageElement(element: Element): element is HTMLImageElement;
export declare function isElementCheckable(element: Element): element is HTMLInputElement & {
checked: boolean;
};
export declare function isHTMLLinkElement(element: Element): element is HTMLLinkElement;
export declare function isHTMLFormElement(element: Element): element is HTMLFormElement;
export declare function isHTMLInputElement(element: Element): element is HTMLInputElement;
export declare function isHTMLImageElement(element: Element): element is HTMLImageElement;
export declare function isElementCheckable(element: Element): element is HTMLInputElement & {
checked: boolean;
};
//# sourceMappingURL=elements.d.ts.map
2 changes: 1 addition & 1 deletion dist/word_count_controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export declare class WordCountController extends BaseController {
hasMaxValue: boolean;
errorClass: string;
hasErrorClass: boolean;
boundHandler: () => void;
initialize(): void;
connect(): void;
disconnect(): void;
updateWordCount(): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/word_count_controller.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/base_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ export class BaseController extends Controller {
});
}

dispatch(element: HTMLElement, eventName: string, options: CustomEventInit = {bubbles: true, cancelable: true, detail: {target: element}}) {
let event = new CustomEvent(eventName, options);
dispatch(element: HTMLElement, eventName: string, options: CustomEventInit = {}) {
let mergedOptions = Object.assign({}, {bubbles: true, cancelable: true, detail: {target: element}}, options);
if (!!mergedOptions.detail.target) {
mergedOptions.detail.target = element;
}
let event = new CustomEvent(eventName, mergedOptions);
element.dispatchEvent(event);
}

Expand Down

0 comments on commit e4a2b89

Please sign in to comment.