question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Add path notation.

See original GitHub issue

Without a path notation it is not actually possible to edit an update spec object with an update spec since it cannot distinguish a key from an operation. Adding path notation also has the advantage that it would also provide dot notation as requested in #17.

The method to disambiguate unusual keys is to use the normal bracket notation (with escaping for at least the close bracket) optionally with quote support. With this the operation doesn’t actually need any special handling since it must always be the last element in any path.

This then gives the following:

const newData = updatePath(myData, {
  "x.y.z.$set": 7,
  "a.b.$push": [9]
});
const newCollection = updatePath(collection, { "2.a.$splice": [[1, 1, 13, 14]]});
const newPathed = updatePath(pathed, {
  "[path.with.dots][next.part].$set": true, // sets pathed["path.with.dots"]["next.part"]
  "$set.$merge.$push": [1], // pushes to pathed.$set.$merge
  "[bracket\\]prop].$set": "eugh escapes", // sets pathed["bracket]prop"]
});

As an extension if double quotes are allowed in the brackets then automatic escaping of strings can be managed through JSON.stringify(). Consider:

const newData = updatePath(myData, {
  [`[${JSON.stringify(computedName)}].$set`]: "supports primitive values",
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kolodnycommented, Nov 14, 2017

That seems out of scope to this library but you can use the flatulence library with this to accomplish that

const flatulence = require("flatulence")

const newData = updatePath(myData, flatulence.unflatten({
  "x.y.z.$set": 7,
  "a.b.$push": [9]
}));
0reactions
hoytechcommented, Oct 3, 2017

I should say that it’s possible that the memoisation would effectively offset the parsing overhead (from all but the first run). The problem is reconstructing a hierarchical update (as I think you’re referring to re: reduce). If efficiency is a concern, it’s simplest just to represent your update hierarchically in which case the trivial recursive implementation is optimal at using the fewest number of shallow copies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] support for path variables #519 - GitHub
Would be nice to have a support for path variables: /users/{userId}/numbers Currently we can only use an environment variable in that case.
Read more >
3 ways to manage software feature request - Amoeboids
The best way to keep feature requests in one place is to set up a centralized repository. Whether a feature request is received...
Read more >
How to Submit a Feature Request - Pathable
Select Feature Request Forum in the upper-right corner of the page · Select "New Post" button on the right-side of the page ·...
Read more >
Submit a feature request for Solarwinds Products
This article describes how to submit a feature request to SolarWinds. Feature requests and votes by you and other SolarWinds users help ...
Read more >
[Absolute or Relative path] `Default location for new notes ...
Currently, create new notes from relative path is very problematic as noted in a related feature request Obsidian has trouble creating new notes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found