-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trouble with integrating with Vue #7
Comments
@OrkhanAlikhanov Greets and congrats, you are the first issuer of the vscroll repo! Your request seems quite important, but I have one doubt, the point is that the scroller engine has its own asynchronicity related to updating the DOM: vscroll/src/processes/render.ts Lines 13 to 15 in b16a4d2
This is the Render process, the heart of the VScroll Workflow. I would agree, it looks not perfect, but it should be enough to catch 1 tick. I wonder if you need more time... We can think about how to control this asynchronicity, something like new Workflow({
element: ...,
datasource: ...,
run: ...,
onRender: done => this.$nextTick(() => done()) // default: done => setTimeout(() => done())
}) and then replace onRender(() => {
if (Render.doRender(scroller)) { ...
...
}) Also, there should be a way to cancel render, something like |
Hey! Thank you for quick response! That approach seems more appropriate way of solving this. Having said that, I patched the library locally and rendering works, but now I'm running into another issue where Thank you for the meeting offer 🙂, I'd like to dive into this a bit more and get it working with Vue so that I can become more helpful in the Vue integration process |
I couldn't reproduce late rendering issue except locally, but was able to reproduce reload issue. Would be great if you could take a look at it, maybe my setup is broken. Let me know if you have any questions. https://stackblitz.com/edit/vue-vscroll |
@OrkhanAlikhanov Well, vscroll v1.0.0 have been just released, a new chapter of this story begins, and I'd love to have You are right with Adapter.reload -> Buffer.reset -> Workflow.run call stack. Lines 44 to 47 in 640abc4
Line 45 is responsible for display-none, line 47 forces Workflow.run to be invoked, and as it follows from the doc (run-callback requirements section):
Explicit hiding occurs internally, it is synchronous and allows to avoid any blinking. But physical removal is a consumer responsibility, it means when you get [] in Workflow.run, you have to remove all items from DOM by yourself, using PS Feel free to ping me by email, I'm pretty interested in Vue, though I still know nothing about it 😁 |
@OrkhanAlikhanov I looked at your stackblitz. The main problem with The suggestion is quite simple: add reload counter to prefix = workflow.scroller.adapter.id + '.' + workflow.scroller.adapter.reloadCounter + '.'; or (equivalent) prefix = workflow.scroller.adapter.reloadId + '.'; This will guarantee key uniqueness across reload/reset. In addition I would state a few basic points that you should implement in your project:
|
Thank you for taking a look at it. That I think I know why it happens. The way vue renders is through diffing 2 virtual DOMs and patching the differences. Before reload, DOM has everything in place from item 0 to 10 let's say. When we hit reload, Giving What do you think about Thank you for your suggestions about only exposing
I'm just dumping my experience here to give you some ideas based on my usage. Not trying to force anything into the library 🙂 Thank you for the awesome work! |
@OrkhanAlikhanov 👍 That's it. On hiding/removal please refer to this comment. In two words: a consumer must clean up the DOM, but the Scroller is not sure if it will happen immediately and synchronously hides the elements to be removed. Questions:
async doReload(index: number, scrollPosition?: number) {
await this.datasource.adapter.reload(index);
if (scrollPosition !== void 0) {
this.datasource.adapter.fix({ scrollPosition });
}
} |
Thank you for your help! You did help me a lot. Here is the state so far https://stackblitz.com/edit/vue-vscroll
When the given vscroll data set changes, UI should be updated accordingly. There can be 2 types of change:
For the second case, vscroll has to reload. watch: {
items(newItems, oldItems) {
const identity = (items: any[]) => items.map(x => x[this.uniqueKey]).join('-')
if (identity(newItems) === identity(oldItems)) {
/// just update displayed data
this.dataItems.forEach((item) => {
item.data = newItems[item.$index]
})
} else {
/// else reload completely
this.datasource = this.generateDataSource()
this.workflow.scroller.adapter.reset(this.datasource)
}
},
}, I understand this is not efficient, there are things that can be optimized further like How does |
@OrkhanAlikhanov I made some updates in your demo: https://stackblitz.com/edit/vscroll-vue-integration. The main point is that the App data is separated from the Vue Scroller component. I had to expose the Datasource class as a component property, hope this doesn't violate standard practices. Please check if it looks in agreement with Vue way, I'd like to have it as a shareable consumer proto-sample.... Adapter.reload does return promise, it resolves when the Scroller stops after the reload process is started and completed. This vscroll functionality has spec in ngx-ui-scroll repo. Speaking of in-place updates which should not force the rows to fully re-render, I'd suggest to look at Adapter.fix({ updater }) API. It provides access to buffered items and allows modifications without updating the Buffer items array reference (and without Workflow.run call). But as I can see, this also works when we make a simple assignment, like in the demo: this.items[index].checked = !this.items[index].checked // just don't do `this.items = ...`, the reference must persist I also removed |
Hi, I'm running into an issue where Vue updates dom a bit late than the flow expects. Basically the updates happen after
run
callback returns. It would be great if we hadrun
's signature as something like(items: Item[], done: () => void) => {}
where we calldone()
after dom update.What do you think?
The text was updated successfully, but these errors were encountered: