How to use the @aurelia/kernel.PLATFORM.emptyArray function in @aurelia/kernel

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 / jit-html / src / template-compiler.ts View on Github external
private compileBindings(symbol: ISymbolWithBindings): HTMLAttributeInstruction[] {
    let bindingInstructions: HTMLAttributeInstruction[];
    if (symbol.flags & SymbolFlags.hasBindings) {
      // either a custom element with bindings, a custom attribute / template controller with dynamic options,
      // or a single value custom attribute binding
      const { bindings } = symbol;
      const len = bindings.length;
      bindingInstructions = Array(len);
      let i = 0;
      for (; i < len; ++i) {
        bindingInstructions[i] = this.compileBinding(bindings[i]);
      }
    } else {
      bindingInstructions = PLATFORM.emptyArray as typeof PLATFORM.emptyArray & HTMLAttributeInstruction[];
    }
    return bindingInstructions;
  }
github aurelia / aurelia / packages / jit-html / dist / index.es6.js View on Github external
compileAttributes(symbol, offset) {
        let attributeInstructions;
        if (symbol.flags & 2048 /* hasAttributes */) {
            // any attributes on a custom element (which are not bindables) or a plain element
            const { attributes } = symbol;
            const len = attributes.length;
            attributeInstructions = Array(offset + len);
            for (let i = 0; i < len; ++i) {
                attributeInstructions[i + offset] = this.compileAttribute(attributes[i]);
            }
        }
        else if (offset > 0) {
            attributeInstructions = Array(offset);
        }
        else {
            attributeInstructions = PLATFORM.emptyArray;
        }
        return attributeInstructions;
    }
    compileCustomAttribute(symbol) {
github aurelia / aurelia / packages / runtime / dist / esnext / observation / proxy-observer.js View on Github external
    apply(target, thisArg, argArray = PLATFORM.emptyArray) {
        // eslint-disable-next-line @typescript-eslint/ban-types
        return Reflect.apply(target, target, argArray); // Reflect API dictates this
    }
    subscribe(subscriber, key) {
github aurelia / aurelia / packages / testing / dist / esnext / h.js View on Github external
import { kebabCase, PLATFORM, } from '@aurelia/kernel';
import { DOM, } from '@aurelia/runtime-html';
const emptyArray = PLATFORM.emptyArray;
export function h(name, attrs = null, ...children) {
    const el = DOM.createElement(name);
    for (const attr in attrs) {
        if (attr === 'class' || attr === 'className' || attr === 'cls') {
            let value = attrs[attr];
            value = value === undefined || value === null
                ? emptyArray
                : Array.isArray(value)
                    ? value
                    : (`${value}`).split(' ');
            el.classList.add(...value.filter(Boolean));
        }
        else if (attr in el || attr === 'data' || attr.startsWith('_')) {
            el[attr.replace(/^_/, '')] = attrs[attr];
        }
        else {
github aurelia / aurelia / packages / runtime / src / resources / custom-attributes / if.ts View on Github external
IObserversLookup,
} from '../../observation';
import { SetterObserver } from '../../observation/setter-observer';
import { Bindable } from '../../templating/bindable';
import {
  CustomAttributeResource,
  ICustomAttributeResource
} from '../custom-attribute';

export class If {
  public static readonly inject: InjectArray = [IViewFactory, IRenderLocation];

  public static readonly kind: ICustomAttributeResource = CustomAttributeResource;
  public static readonly description: Required = Object.freeze({
    name: 'if',
    aliases: PLATFORM.emptyArray as typeof PLATFORM.emptyArray & string[],
    defaultBindingMode: BindingMode.toView,
    hasDynamicOptions: false,
    isTemplateController: true,
    bindables: Object.freeze(Bindable.for({ bindables: ['value'] }).get()),
    strategy: BindingStrategy.getterSetter,
    hooks: Object.freeze(new HooksDefinition(If.prototype)),
  });

  public readonly id: number;

  public get value(): boolean {
    return this._value;
  }
  public set value(newValue: boolean) {
    const oldValue = this._value;
    if (oldValue !== newValue) {
github aurelia / aurelia / packages / jit-html / src / template-compiler.ts View on Github external
const plainAttributes = symbol.plainAttributes;
      const customAttributeLength = customAttributes.length;
      const plainAttributesLength = plainAttributes.length;
      attributeInstructions = Array(offset + customAttributeLength + plainAttributesLength);
      for (let i = 0; customAttributeLength > i; ++i) {
        attributeInstructions[offset] = this.compileCustomAttribute(customAttributes[i] as CustomAttributeSymbol);
        offset++;
      }
      for (let i = 0; plainAttributesLength > i; ++i) {
        attributeInstructions[offset] = this.compilePlainAttribute(plainAttributes[i] as PlainAttributeSymbol);
        offset++;
      }
    } else if (offset > 0) {
      attributeInstructions = Array(offset);
    } else {
      attributeInstructions = PLATFORM.emptyArray as typeof PLATFORM.emptyArray & HTMLAttributeInstruction[];
    }
    return attributeInstructions;
  }
github aurelia / aurelia / packages / runtime-html / src / observation / style-attribute-accessor.ts View on Github external
private getStyleTuplesFromArray(currentValue: unknown[]): [string, string][] {
    const len = currentValue.length;
    if (len > 0) {
      const styles: [string, string][] = [];
      for (let i = 0; i < len; ++i) {
        styles.push(...this.getStyleTuples(currentValue[i]));
      }
      return styles;
    }
    return PLATFORM.emptyArray;
  }
github aurelia / aurelia / packages / aot / src / system / npm-package-loader.ts View on Github external
const withIndexJs = joinPath(entryFilePath, 'index.js');
          entryFile = files.find(x => x.path.endsWith(withIndexJs));
        }
      }
    }

    if (entryFile === void 0) {
      throw new Error(`No entry file could be located for package ${pkgName}`);
    }

    this.entryFile = entryFile;

    if (pkgJson.dependencies instanceof Object) {
      this.deps = Object.keys(pkgJson.dependencies).map(name => new NPMPackageDependency(this, name));
    } else {
      this.deps = PLATFORM.emptyArray;
    }
  }
github aurelia / aurelia / packages / runtime / src / observation / computed-observer.ts View on Github external
public getValue(): unknown {
    if (Tracer.enabled) { Tracer.enter('GetterObserver', 'getValue', slice.call(arguments)); }
    if (this.subscriberCount === 0 || this.isCollecting) {
      this.currentValue = Reflect.apply(this.descriptor.get, this.proxy, PLATFORM.emptyArray);
    } else {
      this.currentValue = Reflect.apply(this.descriptor.get, this.obj, PLATFORM.emptyArray);
    }
    if (Tracer.enabled) { Tracer.leave(); }
    return this.currentValue;
  }
github aurelia / aurelia / packages / runtime / src / binding / ast.ts View on Github external
constructor(parts: ReadonlyArray, expressions?: ReadonlyArray) {
    this.$kind = ExpressionKind.Interpolation;
    this.assign = PLATFORM.noop as () => unknown;
    this.parts = parts;
    this.expressions = expressions === void 0 ? PLATFORM.emptyArray : expressions;
    this.isMulti = this.expressions.length > 1;
    this.firstExpression = this.expressions[0];
  }