-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Create an Angular wrapper for @simulcast/core. The expected DX is as follows:
import { broadcast } from "@simulcast/core";
import { SimulcastComponent } from "@simulcast/angular";
const { registry } = broadcast<{ click: MouseEvent }>();
@Component({
selector: "app-example",
template: `
<button (click)="emitClick($event)" type="button">Click me!</button>
`,
})
export class AppExample extends SimulcastComponent(registry) implements OnInit {
ngOnInit(): void {
this.onClick(console.log);
}
}Extra details
Base class
SimulcastComponent should be a mixing that takes the registry and returns a class:
import type { EventRegistry, EventTypeDictionary } from "@simulcast/core";
export const SimulcastComponent = <Events extends EventTypeDictionary>(
registry: EventRegistry<Events>,
) => {
// Do as much as possible in a functional way out here
return class {
// Handle ngOnDestroy and constructor setup with proxy for component here
// everything else should be handled outside
};
};Cleanup
SimulcastComponent should keep track of the added listeners cleanup functions in a private IterableIterator, and then call them all when ngOnDestroy happens.
Proxy
SimulcastComponent should proxy itself to have on${Event} and emit${Event} methods, but also still need to have on and emit (similar to the React, Preact and Vue implementations).
Metadata
Metadata
Assignees
Labels
No labels