Skip to content

Commit

Permalink
feat: New events (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleysin authored Jan 14, 2024
1 parent 1637acd commit 6ea2d04
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/lib/event.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import UIBuilder from "./builder";

enum ServerEventType {
update = "update",
updateLayout = "updateLayout",
navigation = "navigation",
openUrl = "openUrl",
}

export abstract class ServerEvent {
Expand All @@ -27,4 +27,42 @@ export class LayoutUpdateEvent extends ServerEvent {
super();
this.layout = layout;
}
}

export class NavigationEvent extends ServerEvent {
type = ServerEventType.navigation as const;
path: string;
extra?: Record<string, any>;

constructor(path: string, extra?: Record<string, any>) {
super();
this.path = path;
this.extra = extra;
}
}

export class OpenUrlEvent extends ServerEvent {
type = ServerEventType.openUrl as const;
url: string;

constructor(url: string) {
super();
this.url = url;
}
}

export const CreateUpdateEvent = (updates: Record<string, any>) => {
return new UpdateEvent(updates);
}

export const CreateLayoutUpdateEvent = (layout: string) => {
return new LayoutUpdateEvent(layout);
}

export const CreateNavigationEvent = (path: string, extra?: Record<string, any>) => {
return new NavigationEvent(path, extra);
}

export const CreateOpenUrlEvent = (url: string) => {
return new OpenUrlEvent(url);
}

0 comments on commit 6ea2d04

Please sign in to comment.