Closed cossssmin closed 4 years ago
Extracted to a getLoopMeta
function where I check what we're iterating over and compute the object with loop metadata accordingly. Please check and let me know what you think.
Forgot to add docs, doing it now!
publish v1.3.0
Proposed Changes
This PR adds functionality that exposes some information about the loop currently being executed.
A
loop
object is constructed and passed into thelocals
of the loop being executed.Inside a loop, you now have access to the following variables:
loop.index
- the current iteration of the loop (0 indexed)loop.remaining
- number of iterations until the end (0 indexed)loop.first
- boolean indicating if it's the first iterationloop.last
- boolean indicating if it's the last iterationloop.length
- total number of itemsUsage
Nested loops
The
loop
object contains information about the current loop.This means you can't access the
loop.remaining
variable of the parent loop.A possible solution, though outside the scope of this PR, would be for the
<each>
tag to accept alocals=""
attribute, which could be used to pass down data - in this case, the parent loop's metadata.Types of Changes
Checklist
If merged, this PR closes #65