bindDirectiveInputs function

void bindDirectiveInputs(
  1. List<Binding> inputs,
  2. MatchedDirective directive,
  3. CompileElement? compileElement, {
  4. bool isHostComponent = false,
})

Implementation

void bindDirectiveInputs(
  List<ir.Binding> inputs,
  ir.MatchedDirective directive,
  CompileElement? compileElement, {
  bool isHostComponent = false,
}) {
  if (!directive.hasInputs) return;
  var view = compileElement!.view!;
  var detectChangesInInputsMethod = view.detectChangesInInputsMethod;
  var afterChanges = directive.hasLifecycle(ir.Lifecycle.afterChanges);
  var isOnPushComp = directive.isComponent && directive.isOnPush;
  var calcChanged = isOnPushComp || afterChanges;

  // We want to call AfterChanges lifecycle only if we detect a change.
  // Therefore we keep track of changes using bool changed variable.
  // At the beginning of change detecting inputs we reset this flag to false,
  // and then set it to true if any of it's inputs change.
  if (calcChanged && !isHostComponent) {
    detectChangesInInputsMethod
        .addStmt(DetectChangesVars.changed.set(o.literal(false)).toStmt());
  }
  bindAndWriteToRenderer(
    inputs,
    BoundValueConverter.forView(view),
    directive.providerSource!.build(),
    null,
    false,
    view.nameResolver,
    view.storage,
    detectChangesInInputsMethod,
    isHostComponent: isHostComponent,
    calcChanged: calcChanged,
  );
  if (isOnPushComp) {
    detectChangesInInputsMethod.addStmt(o.IfStmt(DetectChangesVars.changed, [
      compileElement.componentView!.callMethod('markAsCheckOnce', []).toStmt()
    ]));
  }
}