dojo / dojo/framework

Dojo store support for end of list path

Open
#339 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
623
Forks
78
PR merge metrics
No merged PRs in 30d

Description

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

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

> Result

```json
[ "one", "three", "two" ]
```

> Operation

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

> Result

```json
{
"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`.

```ts
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.