mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-22 17:58:05 +00:00
* relocate .vscode
* Switch to transloadit linter
* Update .eslintrc.json
* autofix code
* unlink and install eslint-config-transloadit@1.1.1
* Change 0 to "off"
* Don't change 'use strict'
* Do not vertically align
* disable key-spacing
* add import/no-extraneous-dependencies per package
* add more react/a11y warnings
* Revert "autofix code"
This reverts commit 14c8a8cde8.
* add import/no-extraneous-dependencies per example and main package
* autofix code (2)
* Allow devDependencies in ./bin
* Change import/no-extraneous-dependencies to warn again
* upgrade linter
* Set import/no-extraneous-dependencies to warn
44 lines
863 B
JavaScript
44 lines
863 B
JavaScript
var deepFreeze = require('deep-freeze')
|
|
|
|
/**
|
|
* Default store + deepFreeze on setState to make sure nothing is mutated accidentally
|
|
*/
|
|
class DeepFrozenStore {
|
|
constructor () {
|
|
this.state = {}
|
|
this.callbacks = []
|
|
}
|
|
|
|
getState () {
|
|
return this.state
|
|
}
|
|
|
|
setState (patch) {
|
|
const prevState = { ...this.state }
|
|
const nextState = deepFreeze({ ...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 DeepFrozenStore()
|
|
}
|