Skip to content

Commit

Permalink
Improve TypeScript definitions for dispatched events (#30)
Browse files Browse the repository at this point in the history
* feat(types): improve typings for dispatched events

* ci: replace travis with github workflow
  • Loading branch information
metonym authored Oct 5, 2021
1 parent 2cde741 commit d3165f0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies and build the library
run: |
yarn
yarn prepack
- name: Validate the TypeScript definitions
run: yarn test
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

7 changes: 6 additions & 1 deletion test/IntersectionObserver.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@

<!-- svelte-ignore missing-declaration -->
<IO
on:intersect={(e) => {
on:observe={(e) => {
console.log(e.detail);
console.log(e.detail.intersectionRect);
console.log(e.detail.isIntersecting); // boolean
}}
on:intersect={(e) => {
console.log(e.detail.isIntersecting); // true
}}
/>
16 changes: 15 additions & 1 deletion types/IntersectionObserver.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ export interface IntersectionObserverProps {

export default class SvelteIntersectionObserver extends SvelteComponentTyped<
IntersectionObserverProps,
{ observe: CustomEvent<Entry>; intersect: CustomEvent<Entry> },
{
/**
* Dispatched when the element is first observed
* and also whenever an intersection event occurs.
*/
observe: CustomEvent<IntersectionObserverEntry>;

/**
* Dispatched only when the element is intersecting the viewport.
* `event.detail.isIntersecting` will only be `true`
*/
intersect: CustomEvent<
IntersectionObserverEntry & { isIntersecting: true }
>;
},
{
default: {
intersecting: boolean;
Expand Down

0 comments on commit d3165f0

Please sign in to comment.