How to use the @aurelia/runtime.BindingMode.twoWay 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.spec.ts View on Github external
it(`$bind() [two-way]  target=${$1} prop=${$2} newValue1,newValue2=${$3} expr=${$4} flags=${$5} scope=${$6}`, function () {
        const originalScope = JSON.parse(JSON.stringify(scope));
        // - Arrange - Part 1
        const { sut, lifecycle, container, observerLocator } = createFixture(expr, target, prop, BindingMode.twoWay);
        const srcVal = expr.evaluate(LF.none, scope, container);
        const targetObserver = observerLocator.getObserver(LF.none, target, prop) as IBindingTargetObserver;

        // massSpy(targetObserver, 'setValue', 'getValue', 'callSubscribers', 'subscribe');
        // massSpy(expr, 'evaluate', 'connect', 'assign');
        // massSpy(sut, 'addObserver', 'observeProperty', 'handleChange', 'unobserve');

        // - Act - Part 1
        sut.$bind(flags, scope);

        // - Assert - Part 1
        // verify the behavior inside $bind
        const observer00: SetterObserver = sut['_observer0'];
        const observer01: SetterObserver = sut['_observer1'];
        const observer02: SetterObserver = sut['_observer2'];
github aurelia / aurelia / packages / runtime-html / dist / esnext / resources / binding-behaviors / update-trigger.js View on Github external
bind(flags, scope, binding, ...events) {
        if (events.length === 0) {
            throw Reporter.error(9);
        }
        if (binding.mode !== BindingMode.twoWay && binding.mode !== BindingMode.fromView) {
            throw Reporter.error(10);
        }
        this.persistentFlags = flags & 2080374799 /* persistentBindingFlags */;
        // ensure the binding's target observer has been set.
        const targetObserver = this.observerLocator.getObserver(this.persistentFlags | flags, binding.target, binding.targetProperty);
        if (!targetObserver.handler) {
            throw Reporter.error(10);
        }
        binding.targetObserver = targetObserver;
        // stash the original element subscribe function.
        targetObserver.originalHandler = binding.targetObserver.handler;
        // replace the element subscribe function with one that uses the correct events.
        targetObserver.handler = new EventSubscriber(binding.locator.get(IDOM), events);
    }
    unbind(flags, scope, binding) {
github aurelia / aurelia / packages / runtime-html / src / resources / custom-attributes / focus.ts View on Github external
BindingMode,
  customAttribute,
  IController,
  IDOM,
  INode,
  State
} from '@aurelia/runtime';
import { HTMLDOM } from '../../dom';

/**
 * Focus attribute for element focus binding
 */
@customAttribute('focus')
export class Focus {

  @bindable({ mode: BindingMode.twoWay })
  public value: unknown;

  /**
   * Indicates whether `apply` should be called when `attached` callback is invoked
   */
  private needsApply: boolean = false;

  // This is set by the controller after this instance is constructed
  private readonly $controller!: IController;

  private readonly element: HTMLElement;

  public constructor(
    @INode element: INode,
    @IDOM private readonly dom: HTMLDOM
  ) {
github aurelia / aurelia / packages / __tests__ / 5-jit-html / template-compiler.convention.spec.ts View on Github external
it(`compile <${el} ${bindingAttr}.bind="..." ${elAttrsStr} />`, function () {
      const ctx = TestContext.createHTMLTestContext();
      const compiler = ctx.container.get(ITemplateCompiler);
      const template = `<${el} ${bindingAttr}.bind="value" ${elAttrsStr}>`;
      const { instructions: rootInstructions } = compiler.compile(
        ctx.dom,
        { name: '', template, surrogates: [], instructions: [] },
        new RuntimeCompilationResources(ctx.container)
      );

      const expectedElInstructions: IExpectedInstruction[] = [
        { toVerify: ['type', 'mode', 'to'], mode: BindingMode.twoWay, to: bindingProp, type: TT.propertyBinding }
      ];
      verifyInstructions(rootInstructions[0], expectedElInstructions);
    });
  }
github aurelia / aurelia / packages / __tests__ / jit-html / template-compiler.spec.ts View on Github external
it('understands binding commands', function () {
        @customElement('el')
        class El {
          @bindable({ mode: BindingMode.twoWay }) public propProp1: string;
          @bindable() public prop2: string;
          @bindable() public propProp3: string;
          @bindable() public prop4: string;
          @bindable() public propProp5: string;
        }
        const actual = compileWith(
          `<template>
            
          </template>`,
          [El]
github aurelia / aurelia / packages / __tests__ / 2-runtime / binding.spec.ts View on Github external
beforeEach(function () {
    dummySourceExpression = {} as any;
    dummyTarget = {foo: 'bar'};
    dummyTargetProperty = 'foo';
    dummyMode = BindingMode.twoWay;
  });
github aurelia / aurelia / packages / __tests__ / jit-html / template-compiler.spec.ts View on Github external
        (ctx) => BindingMode.twoWay
      ] as ((ctx: HTMLTestContext) => BindingMode | undefined)[],
github aurelia / aurelia / packages / __tests__ / jit-html / template-compiler.spec.ts View on Github external
        (ctx) => [{ asdf: { attribute: 'bazBaz', property: 'bazBaz', mode: BindingMode.twoWay } }, BindingMode.twoWay, 'bazBaz'],
        (ctx) => [{ asdf: { attribute: 'bazBaz', property: 'bazBaz', mode: BindingMode.default } }, BindingMode.default, 'bazBaz']
github aurelia / aurelia / packages / jit / src / binding-commands.ts View on Github external
mode = binding.bindable.mode;
    } else {
      const command = binding.syntax.command;
      switch (command) {
        case 'bind':
        case 'to-view':
          mode = BindingMode.toView;
          break;
        case 'one-time':
          mode = BindingMode.oneTime;
          break;
        case 'from-view':
          mode = BindingMode.fromView;
          break;
        case 'two-way':
          mode = BindingMode.twoWay;
          break;
      }
    }

    switch (mode) {
      case BindingMode.default:
      case BindingMode.toView:
        return ToViewBindingCommand.prototype.compile(binding);
      case BindingMode.oneTime:
        return OneTimeBindingCommand.prototype.compile(binding);
      case BindingMode.fromView:
        return FromViewBindingCommand.prototype.compile(binding);
      case BindingMode.twoWay:
        return TwoWayBindingCommand.prototype.compile(binding);
    }
  }
github aurelia / aurelia / packages / plugin-conventions / dist / esnext / strip-meta-data.js View on Github external
function toBindingMode(mode) {
    if (mode) {
        const normalizedMode = kebabCase(mode);
        if (normalizedMode === 'one-time')
            return BindingMode.oneTime;
        if (normalizedMode === 'one-way' || normalizedMode === 'to-view')
            return BindingMode.toView;
        if (normalizedMode === 'from-view')
            return BindingMode.fromView;
        if (normalizedMode === 'two-way')
            return BindingMode.twoWay;
    }
}
//# sourceMappingURL=strip-meta-data.js.map