Hello,
I’m writing a project based on existing code not written by me and I’m quite puzzled by why this work because I think it shouldn’t
In a note there is an inline dv field whose value is:
my_view:: `$=dv.view("example", {file: "Hello there"})`
and later, on the note’s body the view is execute with the following line
=this.my_view
This puzzled me for two reason:
- I do have a folder named
example
that contains a file namedview.js
- This folder is NOT located at the vault root, it’s stored under a
_views
folder. - According to the documentation the first parameter of
dv.view
should be the full path where the file or folder containing the js code is.
- This folder is NOT located at the vault root, it’s stored under a
Question 1: why does this code code work even tough the full path of the js file is not specified?
The correct one should be dv.view("_views/example", {file: "Hello there"})
.
HINT: I’m using obsidian-modules, can it be that this plugin is exposing the folders under _views
as modules globally available to any dataviewjs
query into the entire vault?
- The documentation also shows that
dv.view
should be awaited and used like so:await dv.view("views/custom", { arg1: ..., arg2: ... });
- In my case the code is stored in an inline field as an inline js query (because of the
$=...
) - Then this field is invoked via an inline DQL with
=this.my_view
- In my case the code is stored in an inline field as an inline js query (because of the
Question 2: why does this work without any await
?
Question 3: why the dv.view
expression is saved as an inline query and assigned to my_view
? What would be the reasoning here?
Also noticed that if I use a dataviewjs code block in the notes’s body like so, it produces the same result. In this case the await
is required, without it it just produces a Promise
object (as it seems logic).
//dataviewjs
await dv.view("example", {file: "Hello there"})
Question 2.1: So does it means that the inline DQL =this.my_view
automatically resolve the promise?
I couldn’t find anything on dv documentation about promises.