mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
fix promise hanling in value explorer
This commit is contained in:
@@ -16,16 +16,28 @@ const isPromise = object =>
|
|||||||
object instanceof globalThis.run_window.Promise
|
object instanceof globalThis.run_window.Promise
|
||||||
|
|
||||||
const displayed_entries = object => {
|
const displayed_entries = object => {
|
||||||
if(Array.isArray(object)) {
|
if(isPromise(object)) {
|
||||||
|
return displayed_entries(
|
||||||
|
object.status.ok ? object.status.value : object.status.error
|
||||||
|
)
|
||||||
|
} else if(Array.isArray(object)) {
|
||||||
return object.map((v, i) => [i, v])
|
return object.map((v, i) => [i, v])
|
||||||
} else {
|
} else {
|
||||||
return Object.entries(object)
|
return Object.entries(object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const is_expandable = v => typeof(v) == 'object'
|
const is_expandable = v =>
|
||||||
|
isPromise(v)
|
||||||
|
? (
|
||||||
|
v.status != null
|
||||||
|
&& is_expandable(v.status.ok ? v.status.value : v.status.error)
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
typeof(v) == 'object'
|
||||||
&& v != null
|
&& v != null
|
||||||
&& displayed_entries(v).length != 0
|
&& displayed_entries(v).length != 0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
export const stringify_for_header = v => {
|
export const stringify_for_header = v => {
|
||||||
@@ -80,7 +92,15 @@ export const header = object => {
|
|||||||
return 'null'
|
return 'null'
|
||||||
} else if(typeof(object) == 'object') {
|
} else if(typeof(object) == 'object') {
|
||||||
if(isPromise(object)) {
|
if(isPromise(object)) {
|
||||||
return 'Promise<>'
|
if(object.status == null) {
|
||||||
|
return `Promise<pending>`
|
||||||
|
} else {
|
||||||
|
if(object.status.ok) {
|
||||||
|
return `Promise<fulfilled: ${header(object.status.value)}>`
|
||||||
|
} else {
|
||||||
|
return `Promise<rejected: ${header(object.status.error)}>`
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if(isError(object)) {
|
} else if(isError(object)) {
|
||||||
return object.toString()
|
return object.toString()
|
||||||
} else if(Array.isArray(object)) {
|
} else if(Array.isArray(object)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user