Open
Conversation
With an arbitrary set of object changes, including keys that contain dots or
slashes, it can be difficult to retrieve, via dot notation, an object whose
property is changing. Consider this set of operations:
```
let test;
let p;
const ObservableSlim = require("./observable-slim.js");
test = {};
p = ObservableSlim.create(
test,
false,
(changes) =>
{
console.log(JSON.stringify(changes, null, " "));
});
p.hello = "world";
p["a.b"] = { c : {} };
p["a.b"].c["e.f"] = 42;
```
The output of the final change is:
```
[
{
"type": "add",
"target": {
"e.f": 42
},
"property": "e.f",
"newValue": 42,
"currentPath": "a.b.c.e.f",
"jsonPointer": "/a/b/c/e/f",
"proxy": {
"e.f": 42
}
}
]
```
Note that it is not exactly trivial to figure out how to update a remote
object based on this information. There is nothing here that would tell you
that of currentPath "a.b.c.e.f", the "a.b" part is a single key.
To help resolve this problem, I have added the parent path to the change
map. With the parent path, an array, it is easy to iterate through the array
beginning at the top-level object, to then add/update/whatever the given
property. With the change, the above test yields, as the final change, the
following, which includes the `parent` array member:
```
[
{
"type": "add",
"target": {
"e.f": 42
},
"parent": [
"a.b",
"c"
],
"property": "e.f",
"newValue": 42,
"currentPath": "a.b.c.e.f",
"jsonPointer": "/a/b/c/e/f",
"proxy": {
"e.f": 42
}
}
]
```
Pull Request Test Coverage Report for Build 101
💛 - Coveralls |
Owner
|
@derrell My sincere apologies for not seeing this until now! I'll take a look at this contribution this week or by early next week. One thing that I noticed right off the bat is the use of spaces instead of tabs for indentation. Would you be able to switch it to tabs on your fork? |
Author
|
@ElliotNB Sorry about the formatting issue. I try to be careful to match the format of code I'm changing, but obviously missed it here. Fixed now. |
f83c25f to
a6f7d90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With an arbitrary set of object changes, including keys that contain dots or
slashes, it can be difficult to retrieve, via dot notation, an object whose
property is changing. Consider this set of operations:
The output of the final change is:
Note that it is not exactly trivial to figure out how to update a remote
object based on this information. There is nothing here that would tell you
that of currentPath "a.b.c.e.f", the "a.b" part is a single key.
To help resolve this problem, I have added the parent path to the change
map. With the parent path, an array, it is easy to iterate through the array
beginning at the top-level object, to then add/update/whatever the given
property. With the change, the above test yields, as the final change, the
following, which includes the
parentarray member: