Skip to content

Dojo store support for end of list path #339

@devpaul

Description

@devpaul

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions