How to use the @glimmer/reference.ReferenceCache function in @glimmer/reference

To help you get started, we’ve selected a few @glimmer/reference 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 glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / dom.ts View on Github external
APPEND_OPCODES.add(Op.PushRemoteElement, vm => {
  let elementRef = vm.stack.pop>();
  let nextSiblingRef = vm.stack.pop>>();

  let element: Simple.Element;
  let nextSibling: Option;

  if (isConstReference(elementRef)) {
    element = elementRef.value();
  } else {
    let cache = new ReferenceCache(elementRef);
    element = cache.peek();
    vm.updateWith(new Assert(cache));
  }

  if (isConstReference(nextSiblingRef)) {
    nextSibling = nextSiblingRef.value();
  } else {
    let cache = new ReferenceCache(nextSiblingRef);
    nextSibling = cache.peek();
    vm.updateWith(new Assert(cache));
  }

  vm.elements().pushRemoteElement(element, nextSibling);
});
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / dom.ts View on Github external
flush(env: Environment): Option {
    let { reference, element } = this;

    if (isConstReference(reference)) {
      let value = reference.value();
      this.attributeManager.setAttribute(env, element, value, this.namespace);
      return null;
    } else {
      let cache = this.cache = new ReferenceCache(reference);
      let value = cache.peek();
      this.attributeManager.setAttribute(env, element, value, this.namespace);
      return new PatchElementOpcode(this);
    }
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / dom.ts View on Github external
let insertBefore: Maybe;
  let guid = guidRef.value() as string;

  if (isConst(elementRef)) {
    element = check(elementRef.value(), CheckElement);
  } else {
    let cache = new ReferenceCache(elementRef as Reference);
    element = check(cache.peek(), CheckElement);
    vm.updateWith(new Assert(cache));
  }

  if (insertBeforeRef.value() !== undefined) {
    if (isConst(insertBeforeRef)) {
      insertBefore = check(insertBeforeRef.value(), CheckOption(CheckNode));
    } else {
      let cache = new ReferenceCache(insertBeforeRef as Reference>);
      insertBefore = check(cache.peek(), CheckOption(CheckNode));
      vm.updateWith(new Assert(cache));
    }
  }

  let block = vm.elements().pushRemoteElement(element, guid, insertBefore);
  if (block) vm.associateDestroyable(block);
});
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / dom.ts View on Github external
let element: Simple.Element;
  let nextSibling: Option;

  if (isConstReference(elementRef)) {
    element = elementRef.value();
  } else {
    let cache = new ReferenceCache(elementRef);
    element = cache.peek();
    vm.updateWith(new Assert(cache));
  }

  if (isConstReference(nextSiblingRef)) {
    nextSibling = nextSiblingRef.value();
  } else {
    let cache = new ReferenceCache(nextSiblingRef);
    nextSibling = cache.peek();
    vm.updateWith(new Assert(cache));
  }

  vm.elements().pushRemoteElement(element, nextSibling);
});
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
(vm, { op1: target }) => {
    let reference = check(vm.stack.pop(), CheckReference);

    if (isConst(reference)) {
      if (!reference.value()) {
        vm.goto(target);
      }
    } else {
      let cache = new ReferenceCache(reference);

      if (!cache.peek()) {
        vm.goto(target);
      }

      vm.updateWith(new Assert(cache));
    }
  },
  OpcodeKind.Mut
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
vm => {
    let reference = check(vm.stack.peek(), CheckReference);

    if (!isConst(reference)) {
      vm.updateWith(Assert.initialize(new ReferenceCache(reference)));
    }
  },
  OpcodeKind.Mut
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / component.ts View on Github external
APPEND_OPCODES.add(Op.PushDynamicComponentManager, vm => {
  let stack = vm.stack;
  let reference = stack.pop>>();
  let cache = isConst(reference) ? undefined : new ReferenceCache>(reference);
  let definition = cache ? cache.peek() : reference.value();

  stack.push(definition);
  stack.push(definition.manager);

  if (cache) {
    vm.updateWith(new Assert(cache));
  }
});
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
APPEND_OPCODES.add(Op.JumpUnless, (vm, { op1: target }) => {
  let reference = check(vm.stack.pop(), CheckReference);

  if (isConst(reference)) {
    if (!reference.value()) {
      vm.goto(target);
    }
  } else {
    let cache = new ReferenceCache(reference);

    if (!cache.peek()) {
      vm.goto(target);
    }

    vm.updateWith(new Assert(cache));
  }
});