-
Notifications
You must be signed in to change notification settings - Fork 0
Reactivator API: dumpValue()
Appurist (Paul) edited this page Sep 18, 2020
·
1 revision
Parameters: (thing, objToJSON)
Returns: a text string representing the thing
parameter
This is a convenience function for reporting and debugging. It accepts any data item as a parameter and attempts to return a text string that provides the best representation of the thing
possible (without working too hard or assuming too much about the caller).
If the objToJSON
parameter is provided and truthy, if the thing
turns out to be an object, the JSON equivalent will be returned, otherwise the simpler standard "[object Object]" will be returned.
The second (advanced) example on the reactive() page illustrates this method in a more complete example, but the relevant portions of that example are provided below.
import { dumpValue } from '../dist/reactivator.esm.js'
console.log(dumpValue(100))
console.log(dumpValue('a string'))
console.log(dumpValue("another string"))
console.log(dumpValue(1 === 2))
console.log(dumpValue(2 === 2))
console.log(dumpValue([ ]))
console.log(dumpValue([ 'one', 'two', 'three' ]))
console.log(dumpValue({ sub1a: 'value1a', sub1b: 'value1b' }, false))
console.log(dumpValue({ sub1a: 'value1a', sub1b: 'value1b' }, true))
100
'a string'
'another string'
false
true
[ ]
['one','two','three']
[object Object]
{"sub1a":"value1a","sub1b":"value1b"}