mirror of
https://github.com/archtechx/alpine-typescript.git
synced 2025-12-12 06:44:03 +00:00
Improve IDE support, addTitles()
This commit is contained in:
parent
19e75e76ce
commit
644fd0524f
2 changed files with 21 additions and 1 deletions
14
src/index.ts
14
src/index.ts
|
|
@ -16,10 +16,12 @@ export abstract class AlpineComponent {
|
|||
$dispatch?: (event: string, data: object) => void;
|
||||
|
||||
/** Execute a given expression AFTER Alpine has made its reactive DOM updates. */
|
||||
$nextTick?: (callback: () => void) => void;
|
||||
$nextTick?: (callback: (_: any) => void) => void;
|
||||
|
||||
/** Will fire a provided callback when a component property you "watched" gets changed. */
|
||||
$watch?: (property: string, callback: (value: any) => void) => void;
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export function registerComponents(components: { [name: string]: Function }): { [name: string]: ComponentConstructor } {
|
||||
|
|
@ -63,6 +65,16 @@ export function convertClassToAlpineConstructor(component: any): ComponentConstr
|
|||
}
|
||||
}
|
||||
|
||||
export function addTitles(): void {
|
||||
window.Alpine.onBeforeComponentInitialized((component: AlpineComponent) => {
|
||||
if (! component.$el.hasAttribute('x-title')) {
|
||||
if (component.$data.constructor.prototype instanceof AlpineComponent) {
|
||||
component.$el.setAttribute('x-title', component.$data.constructor.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function bootstrap(): void {
|
||||
window.AlpineComponents = {};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue