Add missing inherited methods from TinyEmitter to type definitions. Fixes #294

pull/299/head
Glen Cheney 5 years ago
parent 7ab9d95dc8
commit 67f868dd47

@ -1,6 +1,7 @@
<h2>Changelog<a href="#changelog"></a></h2>
<p>For a more detailed changelog, visit <a href="https://github.com/Vestride/Shuffle/releases">the latest releases</a> on GitHub.</p>
<ul>
<li><code>v5.2.3</code> 2019-08-29 - Add missing inherited methods from <code>TinyEmitter</code> to TypeScript definitions.</li>
<li><code>v5.2.2</code> 2019-06-03 - Update TypeScript definitions.</li>
<li><code>v5.2.1</code> 2018-12-01 - Change `index.d.ts` to use `export default Shuffle` (<a href="https://github.com/Vestride/Shuffle/issues/214#issuecomment-441409237">#214</a>). Upgrade dev dependencies.</li>
<li><code>v5.2.0</code> 2018-08-19 - Lazily test whether the browser's <code>getComputedStyle</code> includes padding. This allows the bundled file to be imported in node for server side rendering.</li>

14
index.d.ts vendored

@ -2,6 +2,8 @@
// Project: https://github.com/Vestride/Shuffle
// Definitions by: Glen Cheney <https://github.com/Vestride>
import { TinyEmitter } from 'tiny-emitter';
export as namespace Shuffle;
export default Shuffle;
@ -149,10 +151,20 @@ export interface ShuffleItemCss {
export type FilterFunction = (this: HTMLElement, element: HTMLElement, shuffle: Shuffle) => boolean;
export type FilterArg = string | string[] | FilterFunction;
export interface ShuffleEventData {
shuffle: Shuffle;
collection?: HTMLElement[];
}
export type ShuffleEventCallback = (data: ShuffleEventData) => void;
declare class Shuffle {
declare class Shuffle extends TinyEmitter {
constructor(element: HTMLElement, options?: ShuffleOptions);
on(event: Shuffle.EventType, callback: ShuffleEventCallback, context?: any): this;
once(event: Shuffle.EventType, callback: ShuffleEventCallback, context?: any): this;
// Use inherited version of emit.
off(event: Shuffle.EventType, callback?: ShuffleEventCallback): this;
/**
* New items have been appended to shuffle. Mix them in with the current filter or sort status.
* @param {HTMLElement[]} newItems Collection of new items.

@ -25,6 +25,14 @@ const options: ShuffleOptions = {
filterMode: Shuffle.FilterMode.ALL,
};
const shuffle = new Shuffle(mainElement, options);
shuffle.on(Shuffle.EventType.REMOVED, (data) => {
console.log(data.shuffle);
console.log(data.collection);
});
shuffle.off(Shuffle.EventType.REMOVED);
shuffle.filter('wallpaper');
shuffle.filter(function filterEachItem(element, shuffle) {
console.log(`shuffle id: ${shuffle.id}, element id: ${element.id}`);

Loading…
Cancel
Save