LabelBuilder
LabelBuilder()
LabelBuilder provides a factory for creating label expressions for your widgets.
The label expressions can be single labels or combinations of labels with logical AND or OR conditions. You can simply use the static methods provided by LabelBuilder to create your expressions.
Usage:
-
Creating a single label expression: singleLabel
const singleLabel = BlazeSDK.LabelBuilder().singleLabel("Blue")This creates a label expression representing a single label "Blue".
-
Creating an AND expression: mustInclude
const andExpression = BlazeSDK.LabelBuilder().mustInclude("Blue", "Green")This creates a label expression representing the logical AND of the labels "Blue" and "Green". In other words, the expression is true if and only if both "Blue" and "Green" are present.
-
Creating an OR expression: atLeastOneOf
const orExpression = BlazeSDK.LabelBuilder().atLeastOneOf("Blue", "Green")This creates a label expression representing the logical OR of the labels "Blue" and "Green". In other words, the expression is true if either "Blue" or "Green" (or both) are present.
-
Combining expressions: You can also combine the expressions using AND and OR operations. For example, you can create an expression that is true if "Red" and either "Blue" or "Green" are present:
const blueOrGreen = BlazeSDK.LabelBuilder().atLeastOneOf("Blue", "Green") const combinedExpression = BlazeSDK.LabelBuilder().mustInclude(blueOrGreen, BlazeSDK.LabelBuilder().singleLabel("Red"))The
BlazeSDK.LabelBuilder().singleLabel(a),BlazeSDK.LabelBuilder().mustInclude(a,b), andBlazeSDK.LabelBuilder().atLeastOneOf(a,b)methods return instances ofBlazeWidgetLabel, which represents the label expressions.
Build a complex expression by nesting: create the sub-expression first, then pass it in as an argument, as shown in the previous example. To express "for-you AND (player OR team)":
const playerOrTeam = BlazeSDK.LabelBuilder().atLeastOneOf("player", "team")
const forYouAndEither = BlazeSDK.LabelBuilder().mustInclude("for-you", playerOrTeam)
// [and, for-you, [or, player, team]]Always nest. A returned BlazeWidgetLabel also exposes its own mustInclude and atLeastOneOf methods, so a chained call like LabelBuilder().mustInclude("for-you", "x").atLeastOneOf("player", "team") runs, but it produces [or, [and, for-you, x], player, team]: a top-level OR that matches content carrying any single one of the labels. Chaining does not narrow the expression the way it reads.
mustInclude and atLeastOneOf each need at least two arguments. Calling either with a single argument throws Invalid label format. Use singleLabel for one label.
Related
DataSourceBuilder | BlazeDataSourceType | Labels data source | Labels mechanism
Updated 16 days ago
