How to use the @aurelia/runtime.BindingMode.toView function in @aurelia/runtime

To help you get started, we’ve selected a few @aurelia/runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / __tests__ / 2-runtime / binding-mode-behaviors.spec.ts View on Github external
DI,
  IContainer
} from '@aurelia/kernel';
import {
  PropertyBinding,
  BindingMode,
  FromViewBindingBehavior,
  OneTimeBindingBehavior,
  ToViewBindingBehavior,
  TwoWayBindingBehavior
} from '@aurelia/runtime';
import { assert } from '@aurelia/testing';

const tests = [
  { Behavior: OneTimeBindingBehavior, mode: BindingMode.oneTime },
  { Behavior: ToViewBindingBehavior, mode: BindingMode.toView },
  { Behavior: FromViewBindingBehavior, mode: BindingMode.fromView },
  { Behavior: TwoWayBindingBehavior, mode: BindingMode.twoWay }
];

describe('BindingModeBehavior', function () {
  const container: IContainer = DI.createContainer();
  let sut: OneTimeBindingBehavior;
  let binding: PropertyBinding;

  for (const { Behavior, mode } of tests) {
    const initModeArr = [BindingMode.oneTime, BindingMode.toView, BindingMode.fromView, BindingMode.twoWay, BindingMode.default];

    for (const initMode of initModeArr) {
      describe(Behavior.name, function () {
        // eslint-disable-next-line mocha/no-hooks
        beforeEach(function () {
github aurelia / aurelia / packages / runtime-html / dist / esnext / html-renderer.js View on Github external
render(flags, dom, context, renderable, target, instruction) {
        const expr = ensureExpression(this.parser, instruction.from, 48 /* IsPropertyCommand */ | BindingMode.toView);
        const binding = applyBindingBehavior(new PropertyBinding(expr, target.style, instruction.to, BindingMode.toView, this.observerLocator, context), expr, context);
        addBinding(renderable, binding);
    }
};
github aurelia / aurelia / packages / i18n / src / t / translation-parameters-renderer.ts View on Github external
import { TranslationBinding } from './translation-binding';

export const TranslationParametersInstructionType = 'tpt';
// `.bind` part is needed here only for vCurrent compliance
const attribute = 't-params.bind';

@attributePattern({ pattern: attribute, symbols: '' })
export class TranslationParametersAttributePattern {
  public [attribute](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, '', attribute);
  }
}

export class TranslationParametersBindingInstruction {
  public readonly type: string = TranslationParametersInstructionType;
  public mode: BindingMode.toView = BindingMode.toView;

  public constructor(
    public from: IsBindingBehavior,
    public to: string,
  ) {}
}

@bindingCommand(attribute)
export class TranslationParametersBindingCommand implements BindingCommandInstance {
  public readonly bindingType: BindingType.BindCommand = BindingType.BindCommand;

  public compile(binding: PlainAttributeSymbol | BindingSymbol): TranslationParametersBindingInstruction {
    return new TranslationParametersBindingInstruction(binding.expression as IsBindingBehavior, getTarget(binding, false));
  }
}
github aurelia / aurelia / packages / runtime-html / dist / esnext / html-renderer.js View on Github external
render(flags, dom, context, renderable, target, instruction) {
        const expr = ensureExpression(this.parser, instruction.from, 48 /* IsPropertyCommand */ | BindingMode.toView);
        const binding = applyBindingBehavior(new AttributeBinding(expr, target, instruction.attr /* targetAttribute */, instruction.to /* targetKey */, BindingMode.toView, this.observerLocator, context), expr, context);
        addBinding(renderable, binding);
    }
};
github aurelia / aurelia / packages / jit / src / resource-model.ts View on Github external
public static from(def: CustomAttributeDefinition): AttrInfo {
    const info = new AttrInfo(def.name, def.isTemplateController);
    const bindables = def.bindables;
    const defaultBindingMode = def.defaultBindingMode !== void 0 && def.defaultBindingMode !== BindingMode.default
      ? def.defaultBindingMode
      : BindingMode.toView;

    let bindable: BindableDefinition;
    let prop: string;
    let mode: BindingMode;
    let hasPrimary: boolean = false;
    let isPrimary: boolean = false;
    let bindableInfo: BindableInfo;

    for (prop in bindables) {
      bindable = bindables[prop];
      // explicitly provided property name has priority over the implicit property name
      if (bindable.property !== void 0) {
        prop = bindable.property;
      }
      if (bindable.mode !== void 0 && bindable.mode !== BindingMode.default) {
        mode = bindable.mode;
github aurelia / aurelia / packages / jit / src / binding-command.ts View on Github external
this.bindingType = BindingType.TwoWayCommand;
  }

  public compile(binding: PlainAttributeSymbol | BindingSymbol): AttributeInstruction {
    return new TwoWayBindingInstruction(binding.expression as IsBindingBehavior, getTarget(binding, false));
  }
}
BindingCommandResource.define('two-way', TwoWayBindingCommand);

// Not bothering to throw on non-existing modes, should never happen anyway.
// Keeping all array elements of the same type for better optimizeability.
const modeToProperty = ['', '$1', '$2', '', '$4', '', '$6'];
const commandToMode = {
  'bind': BindingMode.toView,
  'one-time': BindingMode.oneTime,
  'to-view': BindingMode.toView,
  'from-view': BindingMode.fromView,
  'two-way': BindingMode.twoWay,
};

export interface DefaultBindingCommand extends IBindingCommand {}
export class DefaultBindingCommand implements IBindingCommand {
  public static readonly register: IRegistry['register'];
  public readonly bindingType: BindingType.BindCommand;
  public readonly $1: typeof OneTimeBindingCommand.prototype.compile;
  public readonly $2: typeof ToViewBindingCommand.prototype.compile;
  public readonly $4: typeof FromViewBindingCommand.prototype.compile;
  public readonly $6: typeof TwoWayBindingCommand.prototype.compile;

  constructor() {
    this.bindingType = BindingType.BindCommand;
    this.$1 = OneTimeBindingCommand.prototype.compile;
github aurelia / aurelia / packages / examples / test-aot / name-tag-config.ts View on Github external
<input class="au" type="checkbox">
      
    
    <button class="au">Reset</button>
  `,
  instructions: [
    [
      {
        type: TargetedInstructionType.twoWayBinding,
        srcOrExpr: 'name',
        dest: 'value'
      }
    ],
    [
      {
        type: TargetedInstructionType.propertyBinding, mode: BindingMode.toView,
        srcOrExpr: 'name',
        dest: 'textContent'
      },
      {
        type: TargetedInstructionType.stylePropertyBinding,
        srcOrExpr: 'nameTagColor',
        dest: 'color'
      }
    ],
    [
      {
        type: TargetedInstructionType.twoWayBinding,
        srcOrExpr: 'nameTagColor',
        dest: 'value'
      }
    ],
github aurelia / aurelia / packages / __tests__ / 2-runtime / repeater.spec.ts View on Github external
render(itemRenderable) {
            const text = AuNode.createText();
            const wrapper = AuNode.createTemplate().appendChild(text);

            const nodes = new AuNodeSequence(dom, wrapper);
            const itemBinding = new PropertyBinding(new AccessScopeExpression('item'), text, 'textContent', BindingMode.toView, observerLocator, container);
            binding.persistentFlags |= strategy;

            (itemRenderable as Writable).nodes = nodes;
            addBinding(itemRenderable, itemBinding);
          }
        };
github aurelia / aurelia / packages / __tests__ / jit-html / template-compiler.spec.ts View on Github external
        (ctx, $1, [attr, to, value]) => [`${attr}.to-view`,   value, { type: TT.propertyBinding,  from: new AccessScopeExpression(value), to, mode: BindingMode.toView,   oneTime: false }],
        (ctx, $1, [attr, to, value]) => [`${attr}.one-time`,  value, { type: TT.propertyBinding,  from: new AccessScopeExpression(value), to, mode: BindingMode.oneTime,  oneTime: true  }],
github aurelia / aurelia / packages / __tests__ / jit-html / template-compiler.spec.ts View on Github external
        (ctx, pdName, pdProp, pdAttr) => ({ [pdName]: { property: pdProp, attribute: pdAttr, mode: BindingMode.toView   } }),
        (ctx, pdName, pdProp, pdAttr) => ({ [pdName]: { property: pdProp, attribute: pdAttr, mode: BindingMode.fromView } }),