Passing the item position to `transformData`?
See original GitHub issueFor the latest integration I did, I had to apply a specific markup to the 4 first displayed hits. In my case it was not applying lazyloading of images to those elements.
So I needed to know, from inside the transformData
method, the current position of the item in the returned set.
There is no easy way to do that at the moment, so I resorted to a hack involving setting a global counter (reseted on every on('render')
), and increasing it on each call to my hits.transformData
. It worked, but was far from optimal (code is separated in several parts, I have no clear guarantee that the transformData
are actually executed in order), etc).
So I’m wondering if we shouldn’t change the transformData
signature to transformData(item, position)
instead of just transformData(item)
.
WDYT?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
True 😃
I’m now wondering if
transformData(data, position)
is the right approach. If I define my own template, I won’t have access to thisposition
variable…Maybe extending the
data
passed totemplates.item
andtransformData.item
with a__position
key instead?Now that I know that I can pass functions to
templates
, I no longer needtransformData
…