Skip to content

Commit

Permalink
feat(core): Allow to type _ctx
Browse files Browse the repository at this point in the history
BREAKING CHANGE: GondelBaseComponent constructor requires a ctx and a componentName argument
  • Loading branch information
jantimon committed Sep 25, 2018
1 parent 0d8485d commit 0ee58fe
Show file tree
Hide file tree
Showing 22 changed files with 53 additions and 36 deletions.
4 changes: 1 addition & 3 deletions examples/typescript/src/components/input.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Component, EventListener, GondelBaseComponent, triggerPublicEvent } from "@gondel/core";

@Component("Input")
export class Input extends GondelBaseComponent {
_ctx: HTMLInputElement;

export class Input extends GondelBaseComponent<HTMLInputElement> {
@EventListener("input")
_handleInput() {
triggerPublicEvent("gInput", this);
Expand Down
9 changes: 5 additions & 4 deletions packages/core/dist/GondelComponent.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
export declare type IGondelComponent = new (context: HTMLElement, componentName: string) => GondelComponent;
export declare type StartMethod = ((resolve: Function, reject?: Function) => void) | (() => Promise<any>) | (() => void);
export interface GondelComponent {
_ctx: HTMLElement;
export interface GondelComponent<TElement = HTMLElement> {
_ctx: TElement;
_namespace: string;
_componentName: string;
_stopped: boolean;
start?: StartMethod;
stop?(): void;
sync?(): void;
}
export declare class GondelBaseComponent implements GondelComponent {
export declare class GondelBaseComponent<TElement = HTMLElement> implements GondelComponent<TElement> {
constructor(domNode: TElement, componentName: string);
/**
* The component context
*/
_ctx: HTMLElement;
_ctx: TElement;
/**
* The namespace e.g. 'g'
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/dist/GondelComponent.js

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

2 changes: 1 addition & 1 deletion packages/core/dist/GondelComponent.js.map

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

2 changes: 1 addition & 1 deletion packages/core/dist/GondelComponentStarter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export declare function attachGondelBootingFlag(domNode: HTMLElement, bootingFla
/**
* Constructs a new component
*/
export declare function constructComponent(domNode: HTMLElement, gondelComponentRegistry: GondelComponentRegistry, namespace: string): GondelComponent;
export declare function constructComponent(domNode: HTMLElement, gondelComponentRegistry: GondelComponentRegistry, namespace: string): GondelComponent<HTMLElement>;
/**
* Start a component after it was constructed
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/dist/GondelDecorators.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export declare function Component(componentName: string, namespace?: string): (c
*/
export declare function EventListener(eventName: string, selector?: string | object): <T extends {
__events?: [string, string, string | object | undefined][] | undefined;
} & GondelComponent>(target: T, handler: string) => void;
} & GondelComponent<HTMLElement>>(target: T, handler: string) => void;
2 changes: 1 addition & 1 deletion packages/core/dist/gondel.es5.js

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

2 changes: 1 addition & 1 deletion packages/core/dist/gondel.es5.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/dist/gondel.es5.min.js

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

2 changes: 1 addition & 1 deletion packages/core/dist/gondel.es5.min.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions packages/core/src/GondelComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export type StartMethod =
// Sync boot
| (() => void);

export interface GondelComponent {
export interface GondelComponent<TElement = HTMLElement> {
// The component context
_ctx: HTMLElement;
_ctx: TElement;
// The namespace e.g. 'g'
_namespace: string;
// The componentname e.g. 'Input'
Expand All @@ -25,11 +25,12 @@ export interface GondelComponent {
sync?(): void;
}

export class GondelBaseComponent implements GondelComponent {
export class GondelBaseComponent<TElement = HTMLElement> implements GondelComponent<TElement> {
constructor(domNode: TElement, componentName: string) {}
/**
* The component context
*/
_ctx: HTMLElement;
_ctx: TElement;
/**
* The namespace e.g. 'g'
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/GondelComponentStarter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe("GondelComponentStarter", () => {
@Component("Button")
class Button extends GondelBaseComponent {
_wasConstructed: boolean;
constructor() {
super();
constructor(ctx: HTMLElement, componentName: string) {
super(ctx, componentName);
this._wasConstructed = true;
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/plugins/jquery/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MyComponent extends GondelJqueryComponent {
}
```
*/
export declare const GondelJqueryComponent: new (context: HTMLElement, componentName: string) => GondelBaseComponent & {
$ctx: JQuery<HTMLElement>;
};
export declare class GondelJqueryComponent<TElement = HTMLElement> extends GondelBaseComponent<TElement> {
$ctx: JQuery<TElement>;
constructor(ctx: TElement, componentName: string);
}
Loading

0 comments on commit 0ee58fe

Please sign in to comment.