UNPKG

uppy

Version:

Extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:

43 lines (36 loc) 792 B
/** * Default store that keeps state in a simple object. */ class DefaultStore { constructor () { this.state = {} this.callbacks = [] } getState () { return this.state } setState (patch) { const prevState = Object.assign({}, this.state) const nextState = Object.assign({}, this.state, patch) this.state = nextState this._publish(prevState, nextState, patch) } subscribe (listener) { this.callbacks.push(listener) return () => { // Remove the listener. this.callbacks.splice( this.callbacks.indexOf(listener), 1 ) } } _publish (...args) { this.callbacks.forEach((listener) => { listener(...args) }) } } module.exports = function defaultStore () { return new DefaultStore() }