Closed PEZO19 closed 1 year ago
you may use the standard Javascript splice to do that insert
splice(2, 0, 2, 3, 4) would be the equivalent to your insert
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
@xaviergonz Oh great, thanks. Somehow I though it is necessary to keep the same number of elements (deleted/replaced) in MST/keystone environment, I do not know why I had this assumption.
Hi there! I am fairly new to MST/keystone and trying to wrap my head around the philosophy, features, implementation details.
I have found many issues around arrays/ordering in MST/keystone repos (adding-replacing gotchas, problems around safeReference, etc.), however I did not find something like
.insert(index, newElementArray)
as part of the API..insert
like behaviour? What are the gotchas?.insert
across the app state.Eg.:
**Patch/inverse patch info (merged to be more concise)
replace, 2, 5->2 replace, 3, 6->3 add, 4, 4 add, 5, 5 add, 6, 6
And I do not know about the implementation how references can / should work in all cases, but if an identity is resolved through an explicit
ID/address
, then this shift/insert does not seem to be an issue (for references pointing to indices after the added part), meanwhile, in case ofpath
-based identity, we could just update the observers not to observe/2
/3
anymore, but/5
and/6
instead (just adding the same +3 everywhere). Maybe both are semantically valid insertion types,.insertKeepingPathRef
vs.insertKeepingIdRef
. Furthermore, ifpath
based identity is lazily used/calculated, then there is no update/change needed for observers (of this array) at all.Unfortunately, I am not familiar with array/model semantics of keystone, so I felt I had to raise this question, sorry if it misses some points.