Skip to content

Create @simulcast/angular #12

@loucyx

Description

@loucyx

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
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions