How to use @aurelia/kernel - 10 common examples

To help you get started, we’ve selected a few @aurelia/kernel 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__ / 3-runtime-html / self-binding-behavior.spec.ts View on Github external
describe('SelfBindingBehavior', function () {
  const container: IContainer = DI.createContainer();
  let sut: SelfBindingBehavior;
  let binding: PropertyBinding;
  let originalCallSource: () => void;

  // eslint-disable-next-line mocha/no-hooks
  beforeEach(function () {
    sut = new SelfBindingBehavior();
    binding = new PropertyBinding(undefined, undefined, undefined, undefined, undefined, container as any);
    originalCallSource = binding['callSource'] = function () { return; };
    binding['targetEvent'] = 'foo';
    sut.bind(undefined, undefined, binding as any);
  });

  // TODO: test properly (different binding types)
  it('bind()   should apply the correct behavior', function () {
    assert.strictEqual(binding['selfEventCallSource'] === originalCallSource, true, `binding['selfEventCallSource'] === originalCallSource`);
github aurelia / aurelia / packages / __tests__ / kernel / platform.spec.ts View on Github external
it(`${input} -> ${expected}`, function () {
        const actual = camelCase(input);
        assert.strictEqual(actual, expected, `actual`);
        assert.strictEqual(camelCase(input), actual, `camelCase(input)`); // verify via code coverage report that cache is being hit
      });
    }
github aurelia / aurelia / packages / __tests__ / integration / integration.spec.ts View on Github external
$it(`binds an object array to checkbox-list - ${id}`, function ({ host, ctx }) {
      const app = getViewModel(host);
      const products = app[collProp];
      const inputs: HTMLInputElement[] = toArray(host.querySelectorAll(`checkbox-list #${id} label input[type=checkbox]`));
      const size = products.length;
      assert.equal(inputs.length, size);

      // assert radio buttons and selection
      assert.equal(inputs[0].checked, true, 'checked0');

      // assert if the choice is changed in VM, it is propagated to view
      app[chosenProp].push(products[1]);
      ctx.scheduler.getRenderTaskQueue().flush();
      assert.equal(inputs[0].checked, true, 'checked00');
      assert.equal(inputs[1].checked, true, 'checked1');

      // assert that when choice is changed from view, it is propagaetd to VM
      inputs[0].click();
      inputs[2].click();
      ctx.scheduler.getRenderTaskQueue().flush();
github aurelia / aurelia / packages / __tests__ / integration / integration.spec.ts View on Github external
$it(title, function ({ host, ctx }) {
      const app = getViewModel(host);
      const items = app[collProp];
      const select: HTMLSelectElement = host.querySelector(`select-dropdown select#select${id}`);
      const options: HTMLOptionElement[] = toArray(select.querySelectorAll('option'));
      const size = items.length;

      // initial
      assert.equal(options.length, size + 1);
      assert.equal(options[1].selected, true, 'option10');

      // assert if the choice is changed in VM, it is propagated to view
      app[chosenProp].push(items[1].id);
      ctx.scheduler.getRenderTaskQueue().flush();
      assert.equal(options[1].selected, true, 'option11');
      assert.equal(options[2].selected, true, 'option21');

      // assert that when choice is changed from view, it is propagaetd to VM
      options[3].selected = true;
      select.dispatchEvent(new Event('change'));
      ctx.scheduler.getRenderTaskQueue().flush();
github aurelia / aurelia / packages / testing / src / au-dom.ts View on Github external
register(container: IContainer): void {
    container.register(
      RuntimeConfiguration,
      AuTextRenderer as unknown as IRegistry,
      Registration.singleton(IDOM, AuDOM),
      Registration.singleton(IDOMInitializer, AuDOMInitializer),
      Registration.singleton(IProjectorLocator, AuProjectorLocator),
      Registration.singleton(ITargetAccessorLocator, AuObserverLocator),
      Registration.singleton(ITargetObserverLocator, AuObserverLocator),
      Registration.singleton(ITemplateFactory, AuTemplateFactory),
      Registration.instance(ITemplateCompiler, {}), // TODO: fix this dep tree
    );
  },
  createContainer(): IContainer {
github aurelia / aurelia / packages / jit / dist / index.es6.js View on Github external
getBindingCommand(syntax) {
        const name = syntax.command;
        if (name === null) {
            return null;
        }
        let result = this.commandLookup[name];
        if (result === void 0) {
            result = this.resources.create(BindingCommandResource, name);
            if (result == null) {
                // unknown binding command
                throw Reporter.error(0); // TODO: create error code
            }
            this.commandLookup[name] = result;
        }
        return result;
    }
}
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);
    }
github aurelia / aurelia / packages / jit / dist / esnext / expression-parser.js View on Github external
function parseForOfStatement(state, result) {
    if ((result.$kind & 65536 /* IsForDeclaration */) === 0) {
        throw Reporter.error(106 /* InvalidForDeclaration */, { state });
    }
    if (state.currentToken !== 1051179 /* OfKeyword */) {
        throw Reporter.error(106 /* InvalidForDeclaration */, { state });
    }
    nextToken(state);
    const declaration = result;
    const statement = parse(state, 0 /* Reset */, 61 /* Variadic */, 0 /* None */);
    return new ForOfStatement(declaration, statement);
}
/**
github aurelia / aurelia / packages / runtime / dist / esnext / binding / ast.js View on Github external
iterate(flags, result, func) {
        switch (toStringTag.call(result)) {
            case '[object Array]': return $array(flags | 8388608 /* isOriginalArray */, result, func);
            case '[object Map]': return $map(flags | 8388608 /* isOriginalArray */, result, func);
            case '[object Set]': return $set(flags | 8388608 /* isOriginalArray */, result, func);
            case '[object Number]': return $number(flags | 8388608 /* isOriginalArray */, result, func);
            case '[object Null]': return;
            case '[object Undefined]': return;
            default: throw Reporter.error(0); // TODO: Set error code
        }
    }
    connect(flags, scope, binding, part) {
github aurelia / aurelia / packages / jit / dist / index.es6.js View on Github external
if (state.currentChar === 36 /* Dollar */) {
            if ((state.index + 1) < state.length && state.input.charCodeAt(state.index + 1) === 123 /* OpenBrace */) {
                state.index++;
                tail = false;
                break;
            }
            else {
                result += '$';
            }
        }
        else if (state.currentChar === 92 /* Backslash */) {
            result += String.fromCharCode(unescapeCode(nextChar(state)));
        }
        else {
            if (state.index >= state.length) {
                throw Reporter.error(109 /* UnterminatedTemplate */, { state });
            }
            result += String.fromCharCode(state.currentChar);
        }
    }
    nextChar(state);
    state.tokenValue = result;
    if (tail) {
        return 540713 /* TemplateTail */;
    }
    return 540714 /* TemplateContinuation */;
}
function scanTemplateTail(state) {