Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
585 changes: 362 additions & 223 deletions README.fr.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions types/async-alpine/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
47 changes: 47 additions & 0 deletions types/async-alpine/async-alpine-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Typescript definition tests for async-alpine module
*
* Note: These tests are intended to test the definitions only
* in the sense of typing and call signature consistency. They
* are not intended as functional tests.
*/

import Alpine, { type DirectiveCallback } from "alpinejs";
import AsyncAlpine, { type AlpineAsyncOptions } from "async-alpine";

// init plugin
Alpine.plugin(AsyncAlpine);

// setup options
const options: AlpineAsyncOptions = {
defaultStrategy: "idle",
keepRelativeURLs: false,
};
Alpine.asyncOptions(options);

// listen plugin events
window.addEventListener("async-alpine:load", (event) => {
console.log("async-alpine:load", event.detail.id);
});

// usage: data
Alpine.asyncData(
"myComponent",
() => import("./async-alpine_async-component-tests.js"),
);

// usage: url
Alpine.asyncUrl("myComponent", "./async-alpine_async-component-tests.ts");

// usage: alias
Alpine.asyncAlias("./[name].ts");
Alpine.asyncAlias((name) => import(`/${name}.ts`));

// directive with async data
function directive(): DirectiveCallback {
return (el) => {
el._x_async = "init";
el._x_async = undefined;
};
}
directive();
13 changes: 13 additions & 0 deletions types/async-alpine/async-alpine_async-component-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
interface ComponentState {
message: string;
init(): void;
}

export default function myComponent(): ComponentState {
return {
message: "",
init() {
this.message = "my component has initialised!";
},
};
}
31 changes: 31 additions & 0 deletions types/async-alpine/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { AlpineComponent, PluginCallback } from "alpinejs";

declare global {
interface WindowEventMap {
"async-alpine:load": CustomEvent<{ id: string }>;
}
}

export interface AlpineAsyncOptions {
defaultStrategy?: "eager" | "idle" | "visible" | string;
keepRelativeURLs?: boolean;
}

declare module "alpinejs" {
interface Alpine {
asyncOptions(opts: AlpineAsyncOptions): void;
asyncData<T extends { [key in keyof T]: T[key] }>(
name: string,
download: (name: string) => AlpineComponent<T>,
): void;
asyncUrl(name: string, url: string): void;
asyncAlias(path: string | ((name: string) => any)): void;
}

interface XAttributes {
_x_async: "init" | "await" | "loaded";
}
}

declare const asyncAlpinePlugin: PluginCallback;
export default asyncAlpinePlugin;
21 changes: 21 additions & 0 deletions types/async-alpine/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"private": true,
"type": "module",
"name": "@types/async-alpine",
"version": "2.0.9999",
"projects": [
"https://github.com/Accudio/async-alpine"
],
"dependencies": {
"@types/alpinejs": "*"
},
"devDependencies": {
"@types/async-alpine": "workspace:."
},
"owners": [
{
"name": "Bastien Robert",
"githubUsername": "bastienrobert"
}
]
}
21 changes: 21 additions & 0 deletions types/async-alpine/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"async-alpine-tests.ts",
"async-alpine_async-component-tests.ts"
]
}
Loading