framework icon indicating copy to clipboard operation
framework copied to clipboard

Dojo store support for end of list path

Open devpaul opened this issue 5 years ago • 0 comments

In Dojo Stores there isn't a clear way to refer to the end of a list. While there does appear to be some support for JSON Patch's - path element there doesn't seem to be a way to refer to it using path or at and even when it is used it appears to be buggy.

Operation

apply([
  add(path('list'), [ 'one', 'two' ]),
  add(at(path('list'), '-'), 'three')  // type error
]);

Result

[ "one", "three", "two" ]

Operation

apply([
  add(at(path('list'), '-'), 'three')  // type error
]);

Result

{
  "list": {
    "-": "three"
  }
}

Proposed solutions

One solution would be to add a function that explicitly indexes the end of a list. We could add this function to at.

apply([
  add(at.end(path('list')), 'three')
]);

This has the benefit of flowing pretty well, being human readable, and not significantly expanding the interface of CommandRequest.

Another solution would be to simply change at to accept a number | '-' or number | undefined and in the instance where it is undefined simply add to the end of the list. I'm not fond of either of these solutions as the first doesn't read as well to anyone unfamiliar with JSON Patch and the second makes it easy to omit a value and unintentionally act on the end of the list.

We should also ensure that add, replace, remove, and test behave as expected with this addition.

devpaul avatar May 16 '19 01:05 devpaul