Skip to content

Commit

Permalink
♻️ Update debugger property to be alphabetical with an “_” exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Apr 26, 2022
1 parent 80e83e0 commit 9c1b88b
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ extension DebugViewModel {

// flatten the nested `_identity` auto-properties into individual top level items.
let autoProps = (properties["_identity"] as? [String: Any] ?? [:])
.sorted { $0.key > $1.key }
.sortedWithAutoProperties()
.map { ($0.key, String(describing: $0.value)) }
properties["_identity"] = nil

let userProps = properties
.sorted { $0.key > $1.key }
.sortedWithAutoProperties()
.map { ($0.key, String(describing: $0.value)) }

if !userProps.isEmpty {
Expand Down Expand Up @@ -305,6 +305,23 @@ extension DebugViewModel {
}
}

private extension Dictionary where Key == String, Value == Any {
func sortedWithAutoProperties() -> [(key: Key, value: Value)] {
self.sorted {
switch ($0.key.first, $1.key.first) {
case ("_", "_"):
return $0.key <= $1.key
case ("_", _):
return false
case (_, "_"):
return true
default:
return $0.key <= $1.key
}
}
}
}

private extension String {
var prettifiedEventName: String {
self
Expand Down

0 comments on commit 9c1b88b

Please sign in to comment.