mirror of
https://github.com/transloadit/uppy.git
synced 2026-08-02 14:52:24 +00:00
And remove the proposal-object-rest-spread plugin because it is built into preset-env now.
44 lines
847 B
JavaScript
44 lines
847 B
JavaScript
/**
|
|
* Default store that keeps state in a simple object.
|
|
*/
|
|
class DefaultStore {
|
|
static VERSION = require('../package.json').version
|
|
|
|
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()
|
|
}
|