Add types for uppy.once method (#2965)

Co-authored-by: Merlijn Vos <merlijn@soverin.net>
This commit is contained in:
a-kriya 2021-06-28 12:56:04 +05:30 committed by GitHub
parent ee2f527395
commit 3c8fbe8d87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View file

@ -15,8 +15,8 @@
* will expire before some files can be uploaded.
*
* The long-term solution to this problem is to change the upload pipeline so that files
* can be sent to the next step individually. That requires a breakig change, so it is
* planned for Uppy v2.
* can be sent to the next step individually. That requires a breaking change, so it is
* planned for some future Uppy version.
*
* In the mean time, this plugin is stuck with a hackier approach: the necessary parts
* of the XHRUpload implementation were copied into this plugin, as the MiniXHRUpload

View file

@ -147,17 +147,17 @@ declare module Uppy {
type UploadHandler = (fileIDs: string[]) => Promise<void>
type UploadSuccessCallback<T> = (file: UppyFile<T>, body: any, uploadURL: string) => void
type UploadCompleteCallback<T> = (result: UploadResult<T>) => void
class Uppy<TUseStrictTypes extends TypeChecking = TypeChecking> {
constructor(opts?: UppyOptions)
on<TMeta extends IndexedObject<any> = {}>(
event: 'upload-success',
callback: (file: UppyFile<TMeta>, body: any, uploadURL: string) => void
): this
on<TMeta extends IndexedObject<any> = {}>(
event: 'complete',
callback: (result: UploadResult<TMeta>) => void
): this
on<TMeta extends IndexedObject<any> = {}>(event: 'upload-success', callback: UploadSuccessCallback<TMeta>): this
on<TMeta extends IndexedObject<any> = {}>(event: 'complete', callback: UploadCompleteCallback<TMeta>): this
on(event: Event, callback: (...args: any[]) => void): this
once<TMeta extends IndexedObject<any> = {}>(event: 'upload-success', callback: UploadSuccessCallback<TMeta>): this
once<TMeta extends IndexedObject<any> = {}>(event: 'complete', callback: UploadCompleteCallback<TMeta>): this
once(event: Event, callback: (...args: any[]) => void): this
off(event: Event, callback: (...args: any[]) => void): this
/**
* For use by plugins only.

View file

@ -81,13 +81,17 @@ import DefaultStore = require('@uppy/store-default')
// can emit events with custom event types
uppy.emit('dashboard:modal-closed', () => {})
// can register listners for internal events
// can register listeners for internal events
uppy.on('upload', () => {})
uppy.on('complete', () => {})
uppy.on('error', () => {})
uppy.once('upload', () => {})
uppy.once('complete', () => {})
uppy.once('error', () => {})
// can register listners on custom events
// can register listeners on custom events
uppy.on('dashboard:modal-closed', () => {})
uppy.once('dashboard:modal-closed', () => {})
}
{