obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

file view dependent context

Open GottZ opened this issue 1 year ago • 2 comments

image

the above image is the result of this code:

```dataviewjs
const root = dv.component.component.containerEl;
dv.span("def: has context? " + ("ctx" in root ? root.ctx : "no"));
if (!("ctx" in root)) {
	root.ctx = Math.random();
	dv.span("<br>");
	dv.span("setting context to: " + root.ctx);
}
```

```dataviewjs
const root = dv.component.component.containerEl;
dv.span("use: has context? " + ("ctx" in root ? root.ctx : "no"));
```

I'm currently experimenting with view based contexts. right now, I could detect if I'm either in insert mode or in reading mode too. both have their own contexts.

ToDo's:

  • [ ] ensure cleanup when navigating away / providing a event queue for this task
  • [ ] reducing the barrier to a minimum.. maybe even adding dv.ctx or something, to have a context for the current document view. (opening the same document twice, would result in two separate contexts)
  • [ ] documentation
  • [ ] example for the test vault

Why?

well.. I don't like having all the code in one block if I could have many blocks being able to access data defined by the top block. this would also not only provide access to simple data, but object instances too. one could literally instanciate an API wrapper at the top and use it in consecutive dataviewjs blocks.

I already have the proof of concept done. I just need to iterate it a little and make it more user friendly. I'll work on this after sleep. cya tomorrow :)

GottZ avatar Mar 25 '24 21:03 GottZ

What would you use this for? And can you use dv.evaluationContext for this?

holroy avatar Mar 26 '24 08:03 holroy

What would you use this for? And can you use dv.evaluationContext for this?

that's codeblock scoped. not file scoped.

GottZ avatar Mar 26 '24 11:03 GottZ