Skip to content

Commit

Permalink
remove custom event dispatcher (#1168)
Browse files Browse the repository at this point in the history
* remove custom event dispatcher

* fix: missing create_custom_event

* fix: unnecessary export
  • Loading branch information
jjagielka authored Dec 2, 2023
1 parent de4682e commit 944c622
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
13 changes: 7 additions & 6 deletions src/lib/forms/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import CloseButton from '$lib/utils/CloseButton.svelte';
import { twMerge } from 'tailwind-merge';
import type { FormSizeType, SelectOptionType } from '../types';
import createEventDispatcher from '$lib/utils/createEventDispatcher';
const dispatch = createEventDispatcher();
export let items: SelectOptionType<any>[] = [];
export let value: (string | number)[] = [];
Expand Down Expand Up @@ -52,23 +49,27 @@
}
};
function create_custom_event(type: string, detail: any, { bubbles = false, cancelable = false } = {}) {
return new CustomEvent(type, { detail, bubbles, cancelable });
}
function init(node: HTMLSelectElement, value: any) {
const inital = value; // hack for below
return {
update: (value: any) => {
selectItems = items.filter((x) => value.includes(x.value));
// avoid initial event emitting
if (value !== inital) {
dispatch('change', node, selectItems);
dispatch('input', node, selectItems);
node.dispatchEvent(create_custom_event('input', selectItems));
node.dispatchEvent(create_custom_event('change', selectItems));
}
}
};
}
</script>

<!-- Hidden select for form submission -->
<select use:init={value} {...$$restProps} {value} hidden multiple>
<select use:init={value} {...$$restProps} {value} hidden multiple on:change on:input>
{#each items as { value, name }}
<option {value}>{name}</option>
{/each}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/utils/Popper.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script lang="ts">
import type { ComputePositionReturn, Middleware, Placement, Side } from '@floating-ui/dom';
import * as dom from '@floating-ui/dom';
import { onMount, type ComponentProps } from 'svelte';
import { onMount, type ComponentProps, createEventDispatcher } from 'svelte';
import { twJoin } from 'tailwind-merge';
import Frame from './Frame.svelte';
import createEventDispatcher from './createEventDispatcher';
// propagate props type from underlying Frame
interface $$Props extends ComponentProps<Frame> {
Expand Down
24 changes: 0 additions & 24 deletions src/lib/utils/createEventDispatcher.ts

This file was deleted.

2 comments on commit 944c622

@vercel
Copy link

@vercel vercel bot commented on 944c622 Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 944c622 Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.