I would like to increment a counter in a method, like this:
row(title, height):: {
_panels:: [],
_panelSlot:: 0,
addPanel(panel):: self {
self._panelSlot = self._panelSlot + 1,
_panels+: [{
slot: panelSlot,
panel: panel,
}],
},
The line self._panelSlot = self._panelSlot +1
is what I have expected to work, however that does cause the following error:
STATIC ERROR: lib/grafana/builder.libsonnet:157:7-11: unexpected: self while parsing field definition
My second try:
I'm unsure whether this would overwrite the _panelSlot
variable, but I couldn't confirm because I failed to access that variable on my object array:
row(title, height):: {
_panels:: [],
// height is the row's height in grid numbers and it is used' to calculate the
// panel's height and y pos accordingly.
_height:: height,
// panelSlot is the row panels' current position from left-to-right. If there are
// two or more stacked panels they share the same slot. This is used to calculate
// the width for each panel.
_panelSlot:: 0,
addPanel(panel):: self {
local parent = self,
_panelSlot:: self._panelSlot + 1,
_panels+: [{
slot: parent._panelSlot,
panel: panel,
}],
},
RUNTIME ERROR: max stack frames exceeded.
...
<anonymous>
lib/grafana/builder.libsonnet:(13:9)-(15:10) thunk <array_element>
lib/grafana/builder.libsonnet:19:29-35 object <anonymous>
lib/grafana/builder.libsonnet:19:15-37 thunk <array_element>
lib/grafana/builder.libsonnet:(7:24)-(20:6) object <anonymous>
During manifestation
My question
How can I modify variables (i.e. increment a counter) within a method, so that the modified variable is accessible in the next call of that method?