-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
2758
-
Not Needed
-
SDK FY21-Q3, SDK FY21-Q3.
Goals
Using console.log during debugging is a fairly common practice and the output of calling this on an object or collection from a Realm should be informative.
Expected Results
I would expect that logging a Collection of objects (such as Results) would give information on the type of items in the collection, the size of the collection and perhaps a preview of the first couple of elements in the collection. As a reference, calling console.log on an array and objects yields respectively:
console.log(a);
// [ { name: 'Alice' }, { name: 'Bob' }, { name: 'Charlie' } ]
console.log(a[0])
// { name: 'Alice' }
Actual Results, Steps to Reproduce & Code Sample
const Realm = require('realm'); const realm = new Realm({ schema: [{ name: "Person", properties: { name: "string" } }] }); realm.write(() =>{ realm.create('Person', { name: "Alice" }); }); const persons = realm.objects("Person"); console.log(persons) // Results {} console.log(persons[0]) // Person { [Symbol(_external)]: [External] }
In addition to this, in the Node.js REPL, when executing an expression the REPL prints its value, for a collection, this prints:
Proxy [ Results {}, {} ]
All of the output above have very limited value to a user while debugging their code.
NOTE: https://nodejs.org/dist/latest-v12.x/docs/api/util.html#util_custom_inspection_functions_on_objects might come in handy when solving this.
Version of Realm and Tooling
- Realm JS SDK Version: 5.0.0
- Node or React Native: Node.js
- Client OS & Version: Tested on MacOS
- Which debugger for React Native: None