-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add ability to rename grouped traces #1919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
aef38e5
d886c9e
e6f5e13
7a2316d
4e6a0aa
952e4ea
8f37fc7
dd035ef
7298a0c
64d2bcd
57dfe4a
c0089ea
42d76e0
efcef43
daac59d
6aefb41
be0e693
4943e3a
4b04131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ var NONE = 0; | |
var NAME = 1; | ||
var VALUE = 2; | ||
var BOTH = 3; | ||
var UNSET = 4; | ||
|
||
module.exports = function keyedContainer(baseObj, path, keyName, valueName) { | ||
keyName = keyName || 'name'; | ||
|
@@ -43,16 +44,18 @@ module.exports = function keyedContainer(baseObj, path, keyName, valueName) { | |
var obj = { | ||
// NB: this does not actually modify the baseObj | ||
set: function(name, value) { | ||
var changeType = NONE; | ||
var changeType = value === null ? UNSET : NONE; | ||
|
||
var idx = indexLookup[name]; | ||
if(idx === undefined) { | ||
changeType = BOTH; | ||
changeType = changeType | BOTH; | ||
idx = arr.length; | ||
indexLookup[name] = idx; | ||
} else if(value !== (isSimpleValueProp ? arr[idx][valueName] : nestedProperty(arr[idx], valueName).get())) { | ||
changeType = VALUE; | ||
changeType = changeType | VALUE; | ||
} | ||
var newValue = {}; | ||
|
||
var newValue = arr[idx] = arr[idx] || {}; | ||
newValue[keyName] = name; | ||
|
||
if(isSimpleValueProp) { | ||
|
@@ -61,7 +64,11 @@ module.exports = function keyedContainer(baseObj, path, keyName, valueName) { | |
nestedProperty(newValue, valueName).set(value); | ||
} | ||
|
||
arr[idx] = newValue; | ||
// If it's not an unset, force that bit to be unset. This is all related to the fact | ||
// that undefined and null are a bit specially implemented in nestedProperties. | ||
if(value !== null) { | ||
changeType = changeType & ~UNSET; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm tracking what needs to be updated with a bit mask (which, before adding a bit to track whether it's unset in a way that |
||
} | ||
|
||
changeTypes[idx] = changeTypes[idx] | changeType; | ||
|
||
|
@@ -93,7 +100,17 @@ module.exports = function keyedContainer(baseObj, path, keyName, valueName) { | |
}, | ||
remove: function(name) { | ||
var idx = indexLookup[name]; | ||
|
||
if(idx === undefined) return obj; | ||
|
||
var object = arr[idx]; | ||
if(Object.keys(object).length > 2) { | ||
// This object contains more than just the key/value, so unset | ||
// the value without modifying the entry otherwise: | ||
changeTypes[idx] = changeTypes[idx] | VALUE; | ||
return obj.set(name, null); | ||
} | ||
|
||
for(i = idx; i < arr.length; i++) { | ||
changeTypes[i] = changeTypes[i] | BOTH; | ||
} | ||
|
@@ -118,9 +135,9 @@ module.exports = function keyedContainer(baseObj, path, keyName, valueName) { | |
} | ||
if(changeTypes[idx] & VALUE) { | ||
if(isSimpleValueProp) { | ||
update[astr + '.' + valueName] = arr[idx][valueName]; | ||
update[astr + '.' + valueName] = (changeTypes[idx] & UNSET) ? null : arr[idx][valueName]; | ||
} else { | ||
update[astr + '.' + valueName] = nestedProperty(arr[idx], valueName).get(); | ||
update[astr + '.' + valueName] = (changeTypes[idx] & UNSET) ? null : nestedProperty(arr[idx], valueName).get(); | ||
} | ||
} | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I like it.
@rreusser can you of other situations where this could be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. It's also used in group styles, for one, though that case might be slightly more complicated. Also frames, though again, slightly more complicated. It's more a matter of realizing that unless we allow custom keys in the schema, abstracting this pattern seems like the only sane way forward.