From 08d88d68d24029ce0ebd968b19ce58bd37e0c36c Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Mon, 5 Jun 2023 12:37:39 +0300 Subject: [PATCH] refactor --- src/editor/value_explorer.js | 50 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/editor/value_explorer.js b/src/editor/value_explorer.js index 97caf3e..33456d8 100644 --- a/src/editor/value_explorer.js +++ b/src/editor/value_explorer.js @@ -59,20 +59,22 @@ export const stringify_for_header = v => { } else if(type == 'function') { // TODO clickable link, 'fn', cursive return 'fn ' + v.name - } else if (isPromise(v)) { - if(v.status == null) { - return `Promise` - } else { - if(v.status.ok) { - return `Promise` - } else { - return `Promise` - } - } - } else if(isError(v)) { - return v.toString() + } else if(type == 'string') { + return JSON.stringify(v) } else if(type == 'object') { - if(Array.isArray(v)) { + if (isPromise(v)) { + if(v.status == null) { + return `Promise` + } else { + if(v.status.ok) { + return `Promise` + } else { + return `Promise` + } + } + } else if(isError(v)) { + return v.toString() + } else if(Array.isArray(v)) { if(v.length == 0) { return '[]' } else { @@ -87,19 +89,24 @@ export const stringify_for_header = v => { return '{…}' } } - } else if(type == 'string') { - return JSON.stringify(v) } else { return v.toString() } } export const header = object => { - if(typeof(object) == 'undefined') { - return 'undefined' - } else if(object == null) { + const type = typeof(object) + + if(object === null) { return 'null' - } else if(typeof(object) == 'object') { + } else if(object === undefined) { + return 'undefined' + } else if(type == 'function') { + // TODO clickable link, 'fn', cursive + return 'fn ' + object.name + } else if(type == 'string') { + return JSON.stringify(object) + } else if(type == 'object') { if(isPromise(object)) { if(object.status == null) { return `Promise` @@ -133,11 +140,6 @@ export const header = object => { .join(', ') return `${prefix} {${inner}}` } - } else if(typeof(object) == 'function') { - // TODO clickable link, 'fn', cursive - return 'fn ' + object.name - } else if(typeof(object) == 'string') { - return JSON.stringify(object) } else { return object.toString() }