Problem:
get/set is fine for small data types like numbers, text, booleans.
But when storing arrays or objects, it's a lot of steps:
- get the array
- modify the array
- set the array again
Solution
It would be nice if there were some sort of option for modifying objects that could be a single step.
There should probably be a put and/or patch option where:
- If the item doesn't exist, it's created with
.set()
- If the item does exist, and it's an object, it's treated as an object where the new data is merged in via something like
Object.assign()
- Instructions for this warn that if it's an array, then ordering may be borked?
- It then returns the updated value?
- it also ofc triggers the notification system and has the type "put"
Implementations?
But, there should maybe be two kinds of in-place editing
- put: puts all new data on to the object
- patch: does a smart merge (compares to source and removes what isn't there, adds what is)
Chainable methods?
Maybe the solution could be that it's chainable?
storage.get('someObject').put('newObject')
This could mean that .get has to be modified to put a method on the object prototype only when it's an object. That means modifying the prototype, which could be sketch.
Method(s) with callbacks
Maybe a method with a callback is the right answer:
storage.patch('someObject', (objectData) => {
return whateverTheUpdateIs
})
This doesn't require messing with prototype, and is cleaner visually. It also wouldn't matter, then, if it's an array or object.
Problem:
get/set is fine for small data types like numbers, text, booleans.
But when storing arrays or objects, it's a lot of steps:
Solution
It would be nice if there were some sort of option for modifying objects that could be a single step.
There should probably be a
putand/orpatchoption where:.set()Object.assign()Implementations?
But, there should maybe be two kinds of in-place editing
Chainable methods?
Maybe the solution could be that it's chainable?
storage.get('someObject').put('newObject')This could mean that
.gethas to be modified to put a method on the object prototype only when it's an object. That means modifying the prototype, which could be sketch.Method(s) with callbacks
Maybe a method with a callback is the right answer:
This doesn't require messing with prototype, and is cleaner visually. It also wouldn't matter, then, if it's an array or object.