RoleVar class final
A value of BrickContribution.vars for code that depends on whether a role is present in the app: present with role, absent without it.
A module does not branch on the roles of the app when it contributes
(see SmfModule.contribute). So a template whose code differs with a
role that its module only uses needs two mustache branches under the
presence flag of the role, around the code and again around its import.
With a RoleVar the template reads one variable instead, and the
pipeline takes its value by the presence of the role, as it tells by a
Contribution.when whether a contribution applies:
BrickContribution(
bundle,
vars: {
'zones': RoleVar(
clockRole,
present: Fragment(
'createClock().zones',
imports: [ImportRef.app('core/clock/clock_factory.dart')],
),
absent: 'const <String>[]',
),
},
)
A template with List<String> zones() => {{{zones}}}; then calls
createClock(), with the import of its file, in an app with the clock,
and returns const <String>[] in an app without it.
- role is a role that the contributor provides, requires or uses, as the roles of a Contribution.when are.
- Each value is code, as the variable renders it: a Fragment with the imports that the code needs, or a string of code that needs none. It is no plain data for mustache, such as a list to iterate or a boolean to test: a template tests the presence of a role with the presence flag of the role (see Role.presenceFlag).
- The variable is a fragment variable in every app, whichever value the
app gets, so that a template reads it rightly in every app or in
none. A template reads it as it reads the fragment variable of a
render hook (see RoleOutput.vars): as it is,
{{{zones}}}, and a path cannot read it. The pipeline adds the imports of the value that the app gets to every Dart file of the brick that reads the variable. When either value has imports, only a Dart library may read the variable, not a part file or a file that is not Dart. A line that holds nothing but the variable goes away in an app whose value has no code. - The code depends on one role, so a template reads the variable outside every mustache section, that of the presence flag of another role included. Code that needs a second role goes into a brick of its own, which the module contributes with a Contribution.when of that role and whose template reads the variable.
- Only the whole value of a variable of a brick depends on a role: a
RoleVaris no item of a list or a map and no value of anotherRoleVar. The variables of a render hook take none: a hook asks for the presence of the roles that its role requires or uses itself (see RoleHookInput.has).
Like any variable of a brick, it needs no template that reads it.
- Annotations
-
- @immutable
Constructors
Properties
- absent → Object
-
The code in an app without role: a Fragment, or a string of code
that needs no imports.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- present → Object
-
The code in an app with role: a Fragment, or a string of code that
needs no imports.
final
-
role
→ Role<
Object> -
The role whose presence decides the code.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited