How to use the @aurelia/runtime.Scope.create 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 / testing / dist / esnext / test-builder.js View on Github external
export function createScopeForTest(bindingContext = {}, parentBindingContext) {
    if (parentBindingContext) {
        return Scope.create(0 /* none */, bindingContext, OverrideContext.create(0 /* none */, bindingContext, OverrideContext.create(0 /* none */, parentBindingContext, null)));
    }
    return Scope.create(0 /* none */, bindingContext, OverrideContext.create(0 /* none */, bindingContext, null));
}
// export type CustomAttribute = Writable & IComponentLifecycleMock;
github aurelia / aurelia / packages / __tests__ / 2-runtime / repeater.spec.ts View on Github external
assert.strictEqual(host.textContent, '', 'host.textContent #6');

        runUnbindLifecycle(lifecycle, sut, baseFlags | unbindFlags1);
        if (unbindTwice) {
          runUnbindLifecycle(lifecycle, sut, baseFlags | unbindFlags1);
        }

        // -- Round 2 --

        sut.items = items;
        const expectedText3 = sut.items ? sut.items.join('') : '';

        runBindLifecycle(lifecycle, sut, baseFlags | bindFlags2, scope);
        if (bindTwice) {
          if (newScopeForDuplicateBind) {
            scope = Scope.create(baseFlags, scope.bindingContext);
          }
          runBindLifecycle(lifecycle, sut, baseFlags | bindFlags2, scope);
        }

        runAttachLifecycle(lifecycle, sut, baseFlags | attachFlags2);

        assert.strictEqual(host.textContent, expectedText3, 'host.textContent #7');
        if (attachTwice) {
          runAttachLifecycle(lifecycle, sut, baseFlags | attachFlags2);

          assert.strictEqual(host.textContent, expectedText3, 'host.textContent #8');
        }

        applyMutations(sut, mutations);
        const expectedText4 = sut.items ? sut.items.join('') : '';
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('evaluates undefined bindingContext', function () {
    const scope = Scope.create(LF.none, undefined, null);
    expect(foo.evaluate(LF.none, scope, null)).to.equal(undefined);
    expect(hello.evaluate(LF.none, scope, null)).to.equal(undefined);
  });
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('connects undefined bindingContext', function () {
    const scope = Scope.create(LF.none, undefined, null);
    (binding.observeProperty as any).resetHistory();
    foo.connect(LF.none, scope, binding as any);
    expect(binding.observeProperty.callCount).to.equal(0);
    hello.connect(LF.none, scope, binding as any);
    expect(binding.observeProperty).to.have.been.calledWith(LF.none, scope.overrideContext, 'arg');
  });
github aurelia / aurelia / packages / __tests__ / 2-runtime / binding-context.spec.ts View on Github external
it('{}, null', function () {
      const bindingContext = {} as any;
      const actual = Scope.create(LF.none, bindingContext, null);
      assert.strictEqual(actual.bindingContext, bindingContext, `actual.bindingContext`);
      assert.instanceOf(actual.overrideContext, Object, `actual.overrideContext`);
      assert.strictEqual(actual.overrideContext.bindingContext, bindingContext, `actual.overrideContext.bindingContext`);
      assert.strictEqual(actual.overrideContext.parentOverrideContext, null, `actual.overrideContext.parentOverrideContext`);
    });
github aurelia / aurelia / packages / __tests__ / 2-runtime / binding-context.spec.ts View on Github external
it('null, null', function () {
      const actual = Scope.create(LF.none, null, null);
      assert.strictEqual(actual.bindingContext, null, `actual.bindingContext`);
      assert.instanceOf(actual.overrideContext, Object, `actual.overrideContext`);
      assert.strictEqual(actual.overrideContext.bindingContext, null, `actual.overrideContext.bindingContext`);
      assert.strictEqual(actual.overrideContext.parentOverrideContext, null, `actual.overrideContext.parentOverrideContext`);
    });
github aurelia / aurelia / packages / __tests__ / 2-runtime / binding-context.spec.ts View on Github external
it('{}, {}', function () {
      const bindingContext = {} as any;
      const overrideContext = {} as any;
      const actual = Scope.create(LF.none, bindingContext, overrideContext);
      assert.strictEqual(actual.bindingContext, bindingContext, `actual.bindingContext`);
      assert.strictEqual(actual.overrideContext, overrideContext, `actual.overrideContext`);
      assert.strictEqual(actual.overrideContext.bindingContext, undefined, `actual.overrideContext.bindingContext`);
      assert.strictEqual(actual.overrideContext.parentOverrideContext, undefined, `actual.overrideContext.parentOverrideContext`);
    });
github aurelia / aurelia / packages / __tests__ / util.ts View on Github external
export function createScopeForTest(bindingContext: any = {}, parentBindingContext?: any): IScope {
  if (parentBindingContext) {
    return Scope.create(LF.none, bindingContext, OverrideContext.create(LF.none, bindingContext, OverrideContext.create(LF.none, parentBindingContext, null)));
  }
  return Scope.create(LF.none, bindingContext, OverrideContext.create(LF.none, bindingContext, null));
}
github aurelia / aurelia / packages / __tests__ / 2-runtime / binding.spec.ts View on Github external
const ctx = {};
    const args = Array(count);
    for (let i = 0; i < count; ++i) {
      const prop = args[i] = `$${i}`;
      ctx[prop] = 1;
      if (expr === undefined) {
        expr = new AccessScopeExpression(prop, 0);
      } else {
        expr = new BinaryExpression('+', expr, new AccessScopeExpression(prop, 0));
      }
    }
    const container = RuntimeConfiguration.createContainer();
    const observerLocator = createObserverLocator(container);
    const target = {val: 0};
    const sut = new PropertyBinding(expr as any, target, 'val', BindingMode.toView, observerLocator, container);
    const scope = Scope.create(LF.none, ctx, null);

    sut.$bind(LF.fromBind, scope);

    assert.strictEqual(target.val, count, `target.val`);

    for (let i = 0; i < count; ++i) {
      ctx[args[i]] = 2;
    }

    assert.strictEqual(target.val, count * 2, `target.val`);

    const ctx2 = {};
    for (let i = 0; i < count; ++i) {
      ctx2[args[i]] = 3;
    }
    const scope2 = Scope.create(LF.none, ctx2, null);
github aurelia / aurelia / packages / __tests__ / runtime / custom-attribute.$bind.spec.ts View on Github external
        getScope(sut: CustomAttribute) { return Scope.create(LF.none, sut, null); }
      },