You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* This class implements an object data store, similar to Dojo's Memory Store. It could
* forseeably be replaced by a WeakMap() in the future.
*/
The Store was lifted almost in its entirety from the DojoToolkit's MemoryStore 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:
A map API could be implemented in JavaScript with two arrays (one for keys, one for values) shared by the four API methods. Setting elements on this map would involve pushing a key and value onto the end of each of those arrays simultaneously.
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 a WeakMap().
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.
The text was updated successfully, but these errors were encountered:
This commit removes the previous `Store.js` internals and replaces them
with a simple JavaScript `Map()` while retaining the same API. It is
likely more efficient than the previous version.
ClosesIMA-WorldHealth#7387.
This commit removes the previous `Store.js` internals and replaces them
with a simple JavaScript `Map()` while retaining the same API. It is
likely more efficient than the previous version.
ClosesIMA-WorldHealth#7387.
The first lines of the BHIMA
Store
starts with:bhima/client/src/js/services/Store.js
Lines 4 to 10 in 9e66f54
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.The text was updated successfully, but these errors were encountered: