Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing subjects to event listeners #16

Open
hmallen99 opened this issue Oct 12, 2024 · 0 comments
Open

Allow passing subjects to event listeners #16

hmallen99 opened this issue Oct 12, 2024 · 0 comments

Comments

@hmallen99
Copy link
Owner

A current antipattern in the code base is something like this:

const Counter: Component<Record<string, Observable<void>>> = () => {
            const click$ = new Subject<void>();
            const onclick =of(() => {
                click$.next();
            });
            const textContent = click$.pipe(
                scan((x) => x + 1, 0),
                map((x) => String(x)),
            );

            return createElement('button', {
                onclick,
                textContent,
            });
        };

We should be able to pass click$ directly to the onclick prop, removing the need for the intermediate onclick observable. To do this, we can simply detect if a subject is being passed, and set the event handler within the createElement code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant