Currently if I need several properties from the context store, each has to be read using a separate global.get('foo') call. It would clean up buch of my function nodes if it was possible to read all properties at once. The syntax could be for example: global.getAll() or just global.get() without arguments.
Examples:
// get multiple libs defined in settings.js
const {fs, moment} = global.getAll();
// get libs and individual functions within
const {moment, lodash: {isEmpty, isString} = global.getAll();
// get all node context props at once with default values if context is still empty
let {count = 0, total = 0} = context.getAll();
let myContext = global.get("myContext") || {}
// now use myContext.x and myContext.y or add new properties
// and obviously global.set it again if necessary
I do realise this but it's just my preference to work directly with the values initially. I do collect them in to an object before storing to context if it makes sense.
This is just me wishing to be able to make more use of the "modern" 2015 JavaScript syntax available since Node 8.x. Mainly due to be able to use the same patterns I use at work.
So to sum the above, this is more or a syntactical preference type of feature request. I do understand and use workarounds around the lack of this feature. It was noticing the presence of global.getKeys() that made me think about this.
The main issue is the potential performance cost. If you have a lot of data in context - particular in a synchronous store - then a getAll requires a lot of work which would be wasted if you then used destructuring to pull out one or two items.
Yep I thought about this but I would happily take the hit as I doubt it to be anything I would notice. With that said, I was assuming the (memory store at least) to just be a single object in the background but I take this so that it isn't?
But yep, did not think about custom stores etc. Then again there might even be use cases for retrieving all the data? Of course that could be done using the keys() function...