atom-archive / xray

An experimental next-generation Electron-based text editor
MIT License
8.48k stars 235 forks source link

[Memo] Change notifications? #155

Open jessegrosjean opened 5 years ago

jessegrosjean commented 5 years ago

Maybe I'm missing something obvious, but is there an API (or plans for an API) to be notified of changes to the work tree. In particular if the work tree gets modified due to remote ops being applied how do I learn when that happens and what has changed.

nathansobo commented 5 years ago

Our original plan was to allow you to detect changes just by inspecting the state. So if you're rendering a tree view, you can just retrieve the entries and re-render. If you have 3 buffers open, you can call changesSince for just those buffers whenever operations get applied to see if any have changed. We're open to iterating on this plan based on feedback. Definitely would be interested in what might work better for you in your use case.

jessegrosjean commented 5 years ago

I think the changesSince API is good for buffers. Could something similar be added to work_tree to report file changes in the work tree?

It's true I can just determine this all by inspecting state. But if I want to update the view in an animated fashion then I need to know which exact files were inserted/removed/etc. I could do that by diffing states, but it gets expensive and complicated. Especially when all the information is already known by memo, seems like just exposing exactly what's changed would be nicer.

My use case is that I'm building a macOS file tree view as a learning project. The view can be updated in two ways. Simple way is to just reloadData... which reloads the entire view. Works, but it's somewhat expensive and doesn't provide any animation. On the other hand if I know exactly which files are removed/inserted/changed then I can just reload those portions of the view that have changed. It's faster and you get animation.