brianmhunt / knockout-fast-foreach

Foreach. Faster. For Knockout.
MIT License
59 stars 18 forks source link

Achieve parity with classic foreach functionality (afterRender etc.) #21

Open nmehlei opened 9 years ago

nmehlei commented 9 years ago

In my codebase, I implemented a wrapper around the foreach binding that handles custom scrolling behavior. To update scrolling, I use the afterRender and beforeRemove hooks of said binding.

It would be nice if knockout-fast-foreach could also offer these hooks. That way, it could act as a drop-in replacement as currently I can't use it without them.

cervengoc commented 9 years ago

@nmehlei @brianmhunt I'm planning to work on it soon, because I need it too. Doesn't seem to be too difficoult at first glance.

brianmhunt commented 9 years ago

Fixed (I believe) as of v0.5.4? :)

cervengoc commented 9 years ago

You've added afterAdd and beforeRemove. Not sure if this is compatible. Shouldn't afterAdd be called afterRender?

I think @nmehlei ment compatibility like one should be able to just replace all foreach to fastForEach. But for that to work, parameter names should be exactly the same.

4ver commented 9 years ago

What's being passed to the two callbacks is different so they're not compatible- afterAdd returns the item added to the array whereas afterRender returns the rendered dom elements.

brianmhunt commented 9 years ago

Yeah I noticed that the callbacks are not compatible – I'm not clear on what they should do. Mulling it now. :)

brianmhunt commented 9 years ago

Sorry folks – I've dropped the ball on afterRender and afterAdd, and I've a couple things to do before I get back to it – I'd welcome a PR, but will hope to get it fixed up ASAP.

Thanks for the feedback and patience!

Cheers

cervengoc commented 8 years ago

Some notes for future development.

@brianmhunt What additional value would be added here by implementing a ...All version of these callbacks? Don't exactly see now. I think as far as these callbacks go, being synchronous or not shouldn't matter too much.

brianmhunt commented 8 years ago

Thanks for the comments @cervengoc –

I am of the mindset that an afterAddAll would be misleading in the sense that because it's all processed in an asynchronous batch one might come under the misunderstanding that ...All refers to everything that's added – but the reality is that it's nondeterministic. It might be clearer if they were named afterAddBatch. Is this a real concern?

The single-item callbacks should be synchronous, in the same event loop as FFE's modification of the respective DOM item.

From FFE's perspective, the batch-item callbacks should naturally happen after the queue is flushed. One could batch them on some other condition, but I'm not sure what it would (could) be in library-land.

cervengoc commented 8 years ago

@brianmhunt What do you think about the beforeMove problem?

brianmhunt commented 8 years ago

What do you think about the beforeMove problem

I think it's tricky ;)