Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { destroy, detach, types } from "mobx-state-tree";
import { SharedStoreModel } from "./model";
import { Stores } from "./mixin";
 
/**
 * StoreExtender injects into the AnnotationStore and holds every created SharedStore.
 *
 * Underlying tags that use SharedStoreMixin have access to methods of this mixin to add
 * their SharedStore instances.
 */
export const StoreExtender = types
  .model("StoreExtender", {
    sharedStores: types.optional(types.map(SharedStoreModel), {}),
  })
  .actions((self) => ({
    addSharedStore(store) {
      self.sharedStores.set(store.id, store);
    },
    beforeReset() {
      self.sharedStores.forEach((store) => {
        detach(store);
      });
      self.sharedStores.clear();
    },
    afterReset() {
      Stores.forEach((store) => {
        self.addSharedStore(store);
      });
    },
    beforeDestroy() {
      self.sharedStores.forEach((store) => {
        detach(store);
        destroy(store);
      });
      self.sharedStores.clear();
    },
  }));