I'm looking to control some sorted lists using an event-based model
(pre-existing). Adding and deleting elements works wonderfully.
However, when an element is moved in the array, this (naturally) triggers a
delete followed by an add event. My best guess is to use setTimeout (ick)
and simply wait around some small length (20 ms) to see if an add event
immediately follows.
This seems a bit sloppy and unreliable (what if there is a lot going on and
the timeout is exceeded? what if a large number of moves take place, each
delayed by x ms?)
Is there a simple way I could suppress the delete/add notifications and
create my own from within knockout? Maybe using an extender?
I'm not looking for anyone to write the code--I'll do my homework and ask
questions if I have issues.
I simply want to see if any features or patterns spring to mind that I
should investigate or if this is a previously invented wheel.
The next version of Knockout, 2.2, will include beforeMove and afterMove events for moved items. This is already included in the code available in GitHub (https://github.com/SteveSanderson/knockout), which you can use to build the latest Knockout. In your case, if you want to respond to only a single event, you could just pick either one. One caveat, though, is that deleting or adding an item will cause other items to move, triggering move events for them.
On Wednesday, September 19, 2012 11:03:53 AM UTC-10, Michael Wulf wrote:
> Hello gents,
> I'm looking to control some sorted lists using an event-based model > (pre-existing). Adding and deleting elements works wonderfully.
> However, when an element is moved in the array, this (naturally) triggers > a delete followed by an add event. My best guess is to use setTimeout (ick) > and simply wait around some small length (20 ms) to see if an add event > immediately follows.
> This seems a bit sloppy and unreliable (what if there is a lot going on > and the timeout is exceeded? what if a large number of moves take place, > each delayed by x ms?)
> Is there a simple way I could suppress the delete/add notifications and > create my own from within knockout? Maybe using an extender?
> I'm not looking for anyone to write the code--I'll do my homework and ask > questions if I have issues.
> I simply want to see if any features or patterns spring to mind that I > should investigate or if this is a previously invented wheel.
Is there also a move method then? Or does 2.2 utilize a similar pattern to
what I was looking for, reading a delete/add of the same record as a
move? (right now I'm using splice() to move the records--I assume ko is
taking a similar approach)
On Wed, Sep 19, 2012 at 3:32 PM, Michael Best <mb...@dasya.com> wrote:
> The next version of Knockout, 2.2, will include beforeMove and afterMove
> events for moved items. This is already included in the code available in
> GitHub (https://github.com/SteveSanderson/knockout), which you can use to
> build the latest Knockout. In your case, if you want to respond to only a
> single event, you could just pick either one. One caveat, though, is that
> deleting or adding an item will cause other items to move, triggering move
> events for them.
> -- Michael
> On Wednesday, September 19, 2012 11:03:53 AM UTC-10, Michael Wulf wrote:
>> Hello gents,
>> I'm looking to control some sorted lists using an event-based model
>> (pre-existing). Adding and deleting elements works wonderfully.
>> However, when an element is moved in the array, this (naturally) triggers
>> a delete followed by an add event. My best guess is to use setTimeout (ick)
>> and simply wait around some small length (20 ms) to see if an add event
>> immediately follows.
>> This seems a bit sloppy and unreliable (what if there is a lot going on
>> and the timeout is exceeded? what if a large number of moves take place,
>> each delayed by x ms?)
>> Is there a simple way I could suppress the delete/add notifications and
>> create my own from within knockout? Maybe using an extender?
>> I'm not looking for anyone to write the code--I'll do my homework and ask
>> questions if I have issues.
>> I simply want to see if any features or patterns spring to mind that I
>> should investigate or if this is a previously invented wheel.
On Wednesday, September 19, 2012 12:40:11 PM UTC-10, Michael Wulf wrote:
> Is there also a move method then? Or does 2.2 utilize a similar pattern to > what I was looking for, reading a delete/add of the same record as a > move? (right now I'm using splice() to move the records--I assume ko is > taking a similar approach)
> On Wed, Sep 19, 2012 at 3:32 PM, Michael Best <mb...@dasya.com<javascript:> > > wrote:
>> The next version of Knockout, 2.2, will include beforeMove and afterMove >> events for moved items. This is already included in the code available in >> GitHub (https://github.com/SteveSanderson/knockout), which you can use >> to build the latest Knockout. In your case, if you want to respond to only >> a single event, you could just pick either one. One caveat, though, is that >> deleting or adding an item will cause other items to move, triggering move >> events for them.