Open jniles opened 8 months ago
Note that this fix is currently stalled because some modules are $watch
-ing the store.data array. This array doesn't exist in the when using a native Map()
. We'll have to refactor the APIs that watch these items to make sure we can appropriately handle these cases.
The first lines of the BHIMA
Store
starts with:https://github.com/IMA-WorldHealth/bhima/blob/9e66f548538674242f0043f5a74ef7676e9a3e97/client/src/js/services/Store.js#L4-L10
The
Store
was lifted almost in its entirety from the DojoToolkit'sMemoryStore
implemented back in 2010. Javascript has evolved since then, and built its own native version of a Store - the Map/WeakMap. Indeed, the MDN documentation for WeakMap states:This is almost exactly what the BHIMA store does, except we use an object for our index, not an array. Because of this, and the fact that we need to be able to iterate over the contents of a store, we should use a
Map()
instead of aWeakMap()
.I propose we keep all the methods of Store, and keep the Store service, but transparently replace the implementation with
Map()
. The test should still pass, and no other code outside of the Store service will need to be changed. It will be a silent upgrade to one of the oldest modules in the BHIMA library.