MCPcopy
hub / github.com/transloadit/uppy / DeepFrozenStore

Class DeepFrozenStore

packages/@uppy/core/src/mocks/DeepFrozenStore.mjs:6–37  ·  view source on GitHub ↗

* Default store + deepFreeze on setState to make sure nothing is mutated accidentally

Source from the content-addressed store, hash-verified

4 * Default store + deepFreeze on setState to make sure nothing is mutated accidentally
5 */
6class DeepFrozenStore {
7 constructor() {
8 this.state = {}
9 this.callbacks = []
10 }
11
12 getState() {
13 return this.state
14 }
15
16 setState(patch) {
17 const prevState = { ...this.state }
18 const nextState = deepFreeze({ ...this.state, ...patch })
19
20 this.state = nextState
21 this._publish(prevState, nextState, patch)
22 }
23
24 subscribe(listener) {
25 this.callbacks.push(listener)
26 return () => {
27 // Remove the listener.
28 this.callbacks.splice(this.callbacks.indexOf(listener), 1)
29 }
30 }
31
32 _publish(...args) {
33 this.callbacks.forEach((listener) => {
34 listener(...args)
35 })
36 }
37}
38
39export default function defaultStore() {
40 return new DeepFrozenStore()

Callers 1

Uppy.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…