mcmp: rename GetSeries* functions to just Series*
This commit is contained in:
parent
af836c1cab
commit
dedf3a0368
@ -56,19 +56,19 @@ func AddSeriesValue(c *Component, key, value interface{}) {
|
|||||||
c.SetValue(numValueElsKey, lastNumValueEls+1)
|
c.SetValue(numValueElsKey, lastNumValueEls+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSeriesElements returns the sequence of values that have been added to the
|
// SeriesElements returns the sequence of values that have been added to the
|
||||||
// Component under the given key via AddSeriesValue, interlaced with children
|
// Component under the given key via AddSeriesValue, interlaced with children
|
||||||
// which have been spawned from the Component, in the same respective order the
|
// which have been spawned from the Component, in the same respective order the
|
||||||
// events originally happened.
|
// events originally happened.
|
||||||
func GetSeriesElements(c *Component, key interface{}) []SeriesElement {
|
func SeriesElements(c *Component, key interface{}) []SeriesElement {
|
||||||
els, _ := getSeriesElements(c, key)
|
els, _ := getSeriesElements(c, key)
|
||||||
return els
|
return els
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSeriesValues returns the sequence of values that have been added to the
|
// SeriesValues returns the sequence of values that have been added to the
|
||||||
// Component under the given key via AddSeriesValue, in the same order the
|
// Component under the given key via AddSeriesValue, in the same order the
|
||||||
// values were added.
|
// values were added.
|
||||||
func GetSeriesValues(c *Component, key interface{}) []interface{} {
|
func SeriesValues(c *Component, key interface{}) []interface{} {
|
||||||
elsKey, numValueElsKey := seriesKeys(key)
|
elsKey, numValueElsKey := seriesKeys(key)
|
||||||
els, _ := c.Value(elsKey).([]SeriesElement)
|
els, _ := c.Value(elsKey).([]SeriesElement)
|
||||||
numValueEls, _ := c.Value(numValueElsKey).(int)
|
numValueEls, _ := c.Value(numValueElsKey).(int)
|
||||||
|
@ -12,15 +12,15 @@ func TestSeries(t *T) {
|
|||||||
// test empty state
|
// test empty state
|
||||||
c := new(Component)
|
c := new(Component)
|
||||||
massert.Require(t,
|
massert.Require(t,
|
||||||
massert.Length(GetSeriesElements(c, key), 0),
|
massert.Length(SeriesElements(c, key), 0),
|
||||||
massert.Length(GetSeriesValues(c, key), 0),
|
massert.Length(SeriesValues(c, key), 0),
|
||||||
)
|
)
|
||||||
|
|
||||||
// test after a single value has been added
|
// test after a single value has been added
|
||||||
AddSeriesValue(c, key, 1)
|
AddSeriesValue(c, key, 1)
|
||||||
massert.Require(t,
|
massert.Require(t,
|
||||||
massert.Equal([]SeriesElement{{Value: 1}}, GetSeriesElements(c, key)),
|
massert.Equal([]SeriesElement{{Value: 1}}, SeriesElements(c, key)),
|
||||||
massert.Equal([]interface{}{1}, GetSeriesValues(c, key)),
|
massert.Equal([]interface{}{1}, SeriesValues(c, key)),
|
||||||
)
|
)
|
||||||
|
|
||||||
// test after a child has been added
|
// test after a child has been added
|
||||||
@ -28,9 +28,9 @@ func TestSeries(t *T) {
|
|||||||
massert.Require(t,
|
massert.Require(t,
|
||||||
massert.Equal(
|
massert.Equal(
|
||||||
[]SeriesElement{{Value: 1}, {Child: childA}},
|
[]SeriesElement{{Value: 1}, {Child: childA}},
|
||||||
GetSeriesElements(c, key),
|
SeriesElements(c, key),
|
||||||
),
|
),
|
||||||
massert.Equal([]interface{}{1}, GetSeriesValues(c, key)),
|
massert.Equal([]interface{}{1}, SeriesValues(c, key)),
|
||||||
)
|
)
|
||||||
|
|
||||||
// test after another value has been added
|
// test after another value has been added
|
||||||
@ -38,8 +38,8 @@ func TestSeries(t *T) {
|
|||||||
massert.Require(t,
|
massert.Require(t,
|
||||||
massert.Equal(
|
massert.Equal(
|
||||||
[]SeriesElement{{Value: 1}, {Child: childA}, {Value: 2}},
|
[]SeriesElement{{Value: 1}, {Child: childA}, {Value: 2}},
|
||||||
GetSeriesElements(c, key),
|
SeriesElements(c, key),
|
||||||
),
|
),
|
||||||
massert.Equal([]interface{}{1, 2}, GetSeriesValues(c, key)),
|
massert.Equal([]interface{}{1, 2}, SeriesValues(c, key)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func triggerHooks(
|
|||||||
key interface{},
|
key interface{},
|
||||||
next func([]mcmp.SeriesElement) (mcmp.SeriesElement, []mcmp.SeriesElement),
|
next func([]mcmp.SeriesElement) (mcmp.SeriesElement, []mcmp.SeriesElement),
|
||||||
) error {
|
) error {
|
||||||
els := mcmp.GetSeriesElements(cmp, hookKey{key})
|
els := mcmp.SeriesElements(cmp, hookKey{key})
|
||||||
var el mcmp.SeriesElement
|
var el mcmp.SeriesElement
|
||||||
for {
|
for {
|
||||||
if len(els) == 0 {
|
if len(els) == 0 {
|
||||||
|
@ -21,7 +21,7 @@ func Component() *mcmp.Component {
|
|||||||
mlog.SetLogger(cmp, logger)
|
mlog.SetLogger(cmp, logger)
|
||||||
|
|
||||||
mrun.InitHook(cmp, func(context.Context) error {
|
mrun.InitHook(cmp, func(context.Context) error {
|
||||||
envVals := mcmp.GetSeriesValues(cmp, envCmpKey(0))
|
envVals := mcmp.SeriesValues(cmp, envCmpKey(0))
|
||||||
env := make([]string, 0, len(envVals))
|
env := make([]string, 0, len(envVals))
|
||||||
for _, val := range envVals {
|
for _, val := range envVals {
|
||||||
tup := val.([2]string)
|
tup := val.([2]string)
|
||||||
|
Loading…
Reference in New Issue
Block a user