Skip to content

Commit

Permalink
Merge pull request #11 from WorldMaker:max/cruel-meadowlark
Browse files Browse the repository at this point in the history
Rename Event type to avoid obvious name conflict with common DOM type
  • Loading branch information
WorldMaker authored Oct 27, 2023
2 parents 09afc67 + c282d90 commit 584bef6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
NodeDescription,
makeTestComponentContext,
} from './component.js'
import { Event, makeTestEvent } from './events.js'
import { ObservableEvent, makeTestEvent } from './events.js'
import { Children, jsx } from './jsx.js'

describe('component', () => {
Expand All @@ -16,7 +16,7 @@ describe('component', () => {

it('supports custom component contexts at the jsx level', () => {
interface CustomEvents {
click: Event<MouseEvent>
click: ObservableEvent<MouseEvent>
}
const clickHandler = () => console.log('clicked')
const TestComponent = (
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('component', () => {

it('supports binding children', () => {
interface CustomEvents {
click: Event<MouseEvent>
click: ObservableEvent<MouseEvent>
}

const hello = of('Hello')
Expand Down
6 changes: 3 additions & 3 deletions events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Observable } from 'rxjs'

const ButterfloatEvent = Symbol('Butterfloat Event')

export type Event<T> = Observable<T> & { [ButterfloatEvent]: unknown }
export type ObservableEvent<T> = Observable<T> & { [ButterfloatEvent]: unknown }

export type DefaultEvents = Record<string, Event<unknown>>
export type DefaultEvents = Record<string, ObservableEvent<unknown>>

export function makeTestEvent<T>(observable: Observable<T>) {
const event = observable as Event<T>
const event = observable as ObservableEvent<T>
event[ButterfloatEvent] = '⚠ Test Event'
return event
}
4 changes: 2 additions & 2 deletions jsx.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { deepEqual } from 'node:assert/strict'
import { describe, it } from 'node:test'
import { Observable, of } from 'rxjs'
import { ComponentContext, NodeDescription } from './component.js'
import { Event, makeTestEvent } from './events.js'
import { ObservableEvent, makeTestEvent } from './events.js'
import { Fragment, jsx } from './jsx.js'

describe('jsx', () => {
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('jsx', () => {
) => (
<h1
bind={{ innerText: props.hello }}
events={{ click: events.click as Event<MouseEvent> }}
events={{ click: events.click as ObservableEvent<MouseEvent> }}
/>
)
const hello = of('Hello')
Expand Down
4 changes: 2 additions & 2 deletions jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
NodeDescription,
DefaultBind,
} from './component'
import { DefaultEvents, Event } from './events'
import { DefaultEvents, ObservableEvent } from './events'

namespace JSXInternal {
export type Element = NodeDescription
Expand Down Expand Up @@ -56,7 +56,7 @@ namespace JSXInternal {
}

type HtmlEvents<EventMap = HTMLElementEventMap> = {
[Property in keyof EventMap]?: Event<EventMap[Property]>
[Property in keyof EventMap]?: ObservableEvent<EventMap[Property]>
}

type HtmlElements = {
Expand Down

0 comments on commit 584bef6

Please sign in to comment.