mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] devtools: sort object keys in alphabetical order
Some big objects are quite hard to read because keys are sorted by order of definition inside the object. It is better to sort them in alphabetical order as is done in the base devtools.
This commit is contained in:
committed by
Géry Debongnie
parent
aeed79c7e5
commit
fcda17c8e9
@@ -1026,7 +1026,9 @@
|
|||||||
break;
|
break;
|
||||||
case "object":
|
case "object":
|
||||||
case "function":
|
case "function":
|
||||||
Reflect.ownKeys(obj).forEach((key) => {
|
Reflect.ownKeys(obj)
|
||||||
|
.sort(compareKeys)
|
||||||
|
.forEach((key) => {
|
||||||
if (
|
if (
|
||||||
key !== "__proto__" &&
|
key !== "__proto__" &&
|
||||||
Object.getOwnPropertyDescriptor(obj, key).hasOwnProperty("get")
|
Object.getOwnPropertyDescriptor(obj, key).hasOwnProperty("get")
|
||||||
@@ -1053,7 +1055,9 @@
|
|||||||
oldBranch?.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) children.push(child);
|
if (child) {
|
||||||
|
children.push(child);
|
||||||
|
}
|
||||||
index++;
|
index++;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1155,7 +1159,9 @@
|
|||||||
const propsPath = isApp
|
const propsPath = isApp
|
||||||
? [...path, { type: "item", value: "props" }]
|
? [...path, { type: "item", value: "props" }]
|
||||||
: [...path, { type: "item", value: "component" }, { type: "item", value: "props" }];
|
: [...path, { type: "item", value: "component" }, { type: "item", value: "props" }];
|
||||||
Reflect.ownKeys(props).forEach((key) => {
|
Reflect.ownKeys(props)
|
||||||
|
.sort(compareKeys)
|
||||||
|
.forEach((key) => {
|
||||||
let oldBranch = oldTree?.props.children[component.props.children.length];
|
let oldBranch = oldTree?.props.children[component.props.children.length];
|
||||||
const property = this.serializeObjectChild(
|
const property = this.serializeObjectChild(
|
||||||
props,
|
props,
|
||||||
@@ -1176,7 +1182,9 @@
|
|||||||
const envPath = isApp
|
const envPath = isApp
|
||||||
? [...path, { type: "item", value: "env" }]
|
? [...path, { type: "item", value: "env" }]
|
||||||
: [...path, { type: "item", value: "component" }, { type: "item", value: "env" }];
|
: [...path, { type: "item", value: "component" }, { type: "item", value: "env" }];
|
||||||
Reflect.ownKeys(env).forEach((key) => {
|
Reflect.ownKeys(env)
|
||||||
|
.sort(compareKeys)
|
||||||
|
.forEach((key) => {
|
||||||
let oldBranch = oldTree?.env.children[component.env.children.length];
|
let oldBranch = oldTree?.env.children[component.env.children.length];
|
||||||
const envElement = this.serializeObjectChild(
|
const envElement = this.serializeObjectChild(
|
||||||
env,
|
env,
|
||||||
@@ -1229,7 +1237,9 @@
|
|||||||
const instance = isApp ? node : node.component;
|
const instance = isApp ? node : node.component;
|
||||||
component.instance = { toggled: oldTree ? oldTree.instance.toggled : true, children: [] };
|
component.instance = { toggled: oldTree ? oldTree.instance.toggled : true, children: [] };
|
||||||
const instancePath = isApp ? path : [...path, { type: "item", value: "component" }];
|
const instancePath = isApp ? path : [...path, { type: "item", value: "component" }];
|
||||||
Reflect.ownKeys(instance).forEach((key) => {
|
Reflect.ownKeys(instance)
|
||||||
|
.sort(compareKeys)
|
||||||
|
.forEach((key) => {
|
||||||
if (!["env", "props"].includes(key)) {
|
if (!["env", "props"].includes(key)) {
|
||||||
let oldBranch = oldTree?.instance.children[component.instance.children.length];
|
let oldBranch = oldTree?.instance.children[component.instance.children.length];
|
||||||
const instanceElement = this.serializeObjectChild(
|
const instanceElement = this.serializeObjectChild(
|
||||||
@@ -1747,6 +1757,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compareKeys(a, b) {
|
||||||
|
const isSymbolA = typeof a === "symbol";
|
||||||
|
const isSymbolB = typeof b === "symbol";
|
||||||
|
|
||||||
|
if (isSymbolA && !isSymbolB) {
|
||||||
|
return 1; // Place Symbols at the end
|
||||||
|
} else if (!isSymbolA && isSymbolB) {
|
||||||
|
return -1; // Place non-Symbols at the beginning
|
||||||
|
} else {
|
||||||
|
return String(a).localeCompare(String(b)); // Sort other keys alphabetically
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function checkOwlStatus() {
|
function checkOwlStatus() {
|
||||||
let owlStatus = 2;
|
let owlStatus = 2;
|
||||||
if (!window.__OWL__DEVTOOLS_GLOBAL_HOOK__) {
|
if (!window.__OWL__DEVTOOLS_GLOBAL_HOOK__) {
|
||||||
|
|||||||
Reference in New Issue
Block a user