How to use the @glimmer/runtime.PrimitiveReference.create function in @glimmer/runtime

To help you get started, we’ve selected a few @glimmer/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 emberjs / ember.js / packages / @ember / -internals / glimmer / lib / utils / bindings.ts View on Github external
install(
    _element: Simple.Element,
    component: Component,
    rootRef: RootReference,
    parsed: [string, string, boolean],
    operations: ElementOperations
  ) {
    let [prop, attribute, isSimple] = parsed;

    if (attribute === 'id') {
      let elementId = get(component, prop);
      if (elementId === undefined || elementId === null) {
        elementId = component.elementId;
      }
      elementId = PrimitiveReference.create(elementId);
      operations.setAttribute('id', elementId, true, null);
      // operations.addStaticAttribute(element, 'id', elementId);
      return;
    }

    let isPath = prop.indexOf('.') > -1;
    let reference = isPath
      ? referenceForParts(rootRef, prop.split('.'))
      : referenceForKey(rootRef, prop);

    assert(
      `Illegal attributeBinding: '${prop}' is not a valid attribute name.`,
      !(isSimple && isPath)
    );

    if (
github emberjs / ember.js / packages / @ember / -internals / glimmer / lib / utils / bindings.ts View on Github external
install(
    _element: Simple.Element,
    rootRef: RootReference,
    microsyntax: string,
    operations: ElementOperations
  ) {
    let [prop, truthy, falsy] = microsyntax.split(':');
    let isStatic = prop === '';

    if (isStatic) {
      operations.setAttribute('class', PrimitiveReference.create(truthy), true, null);
    } else {
      let isPath = prop.indexOf('.') > -1;
      let parts = isPath ? prop.split('.') : [];
      let value = isPath ? referenceForParts(rootRef, parts) : referenceForKey(rootRef, prop);
      let ref;

      if (truthy === undefined) {
        ref = new SimpleClassNameBindingReference(value, isPath ? parts[parts.length - 1] : prop);
      } else {
        ref = new ColonClassNameBindingReference(value, truthy, falsy);
      }

      operations.setAttribute('class', ref, false, null);
      // // the upstream type for addDynamicAttribute's `value` argument
      // // appears to be incorrect. It is currently a Reference, I
      // // think it should be a Reference.
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / suites / entry-point.ts View on Github external
'does not leak args between invocations'() {
    let delegate = new AotRenderDelegate();
    delegate.registerComponent('Basic', 'Basic', 'Title', `<h1>hello {{@title}}</h1>`);

    let element = delegate.getInitialElement();
    let title = PrimitiveReference.create('renderComponent');
    delegate.renderComponent('Title', { title }, element);
    QUnit.assert.equal((element as Element).innerHTML, '<h1>hello renderComponent</h1>');

    element = delegate.getInitialElement();
    let newTitle = PrimitiveReference.create('new title');
    delegate.renderComponent('Title', { title: newTitle }, element);
    QUnit.assert.equal((element as Element).innerHTML, '<h1>hello new title</h1>');
  }
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / components / emberish-curly.ts View on Github external
didCreateElement(
    component: EmberishCurlyComponent,
    element: Element,
    operations: ElementOperations
  ): void {
    component.element = element;

    operations.setAttribute(
      'id',
      PrimitiveReference.create(`ember${component._guid}`),
      false,
      null
    );
    operations.setAttribute('class', PrimitiveReference.create('ember-view'), false, null);

    let bindings = component.attributeBindings;
    let rootRef = SELF_REF.get(component)!;

    if (bindings) {
      for (let i = 0; i &lt; bindings.length; i++) {
        let attribute = bindings[i];
        let reference = rootRef.get(attribute) as PathReference;

        operations.setAttribute(attribute, reference, false, null);
      }
    }
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / components / emberish-curly.ts View on Github external
didCreateElement(
    component: EmberishCurlyComponent,
    element: Element,
    operations: ElementOperations
  ): void {
    component.element = element;

    operations.setAttribute(
      'id',
      PrimitiveReference.create(`ember${component._guid}`),
      false,
      null
    );
    operations.setAttribute('class', PrimitiveReference.create('ember-view'), false, null);

    let bindings = component.attributeBindings;
    let rootRef = SELF_REF.get(component)!;

    if (bindings) {
      for (let i = 0; i &lt; bindings.length; i++) {
        let attribute = bindings[i];
        let reference = rootRef.get(attribute) as PathReference;

        operations.setAttribute(attribute, reference, false, null);
      }
    }
  }
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / suites / entry-point.ts View on Github external
'can render different components per call'() {
    let delegate = new AotRenderDelegate();
    delegate.registerComponent('Basic', 'Basic', 'Title', `<h1>hello {{@title}}</h1>`);
    delegate.registerComponent('Basic', 'Basic', 'Body', `<p>body {{@body}}</p>`);

    let element = delegate.getInitialElement();
    let title = PrimitiveReference.create('renderComponent');
    delegate.renderComponent('Title', { title }, element);
    QUnit.assert.equal((element as Element).innerHTML, '<h1>hello renderComponent</h1>');

    element = delegate.getInitialElement();
    let body = PrimitiveReference.create('text');
    delegate.renderComponent('Body', { body }, element);
    QUnit.assert.equal((element as Element).innerHTML, '<p>body text</p>');
  }
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / suites / entry-point.ts View on Github external
'does not leak args between invocations'() {
    let delegate = new AotRenderDelegate();
    delegate.registerComponent('Basic', 'Basic', 'Title', `<h1>hello {{@title}}</h1>`);

    let element = delegate.getInitialElement();
    let title = PrimitiveReference.create('renderComponent');
    delegate.renderComponent('Title', { title }, element);
    QUnit.assert.equal((element as Element).innerHTML, '<h1>hello renderComponent</h1>');

    element = delegate.getInitialElement();
    let newTitle = PrimitiveReference.create('new title');
    delegate.renderComponent('Title', { title: newTitle }, element);
    QUnit.assert.equal((element as Element).innerHTML, '<h1>hello new title</h1>');
  }
github glimmerjs / glimmer-vm / packages / @glimmer / test-helpers / lib / environment.ts View on Github external
toConditionalReference(reference: Reference): Reference {
    if (isConst(reference)) {
      return PrimitiveReference.create(emberToBool(reference.value()));
    }

    return new EmberishConditionalReference(reference);
  }
github emberjs / ember.js / packages / @ember / -internals / glimmer / lib / component-managers / curly.ts View on Github external
const ref = new SimpleClassNameBindingReference(classRef, classRef['propertyKey']);
      operations.setAttribute('class', ref, false, null);
    }

    if (classNames && classNames.length) {
      classNames.forEach((name: string) => {
        operations.setAttribute('class', PrimitiveReference.create(name), false, null);
      });
    }

    if (classNameBindings && classNameBindings.length) {
      classNameBindings.forEach((binding: string) => {
        ClassNameBinding.install(element, rootRef, binding, operations);
      });
    }
    operations.setAttribute('class', PrimitiveReference.create('ember-view'), false, null);

    if ('ariaRole' in component) {
      operations.setAttribute('role', referenceForKey(rootRef, 'ariaRole'), false, null);
    }

    component._transitionTo('hasElement');

    if (environment.isInteractive) {
      component.trigger('willInsertElement');
    }
  }
github emberjs / ember.js / packages / @ember / -internals / glimmer / lib / component-managers / curly.ts View on Github external
while (i !== -1) {
    let binding = attributeBindings[i];
    let parsed: [string, string, boolean] = AttributeBinding.parse(binding);
    let attribute = parsed[1];

    if (seen.indexOf(attribute) === -1) {
      seen.push(attribute);
      AttributeBinding.install(element, component, rootRef, parsed, operations);
    }

    i--;
  }

  if (seen.indexOf('id') === -1) {
    let id = component.elementId ? component.elementId : guidFor(component);
    operations.setAttribute('id', PrimitiveReference.create(id), false, null);
  }

  if (
    EMBER_COMPONENT_IS_VISIBLE &&
    IsVisibleBinding !== undefined &&
    seen.indexOf('style') === -1
  ) {
    IsVisibleBinding.install(element, component, rootRef, operations);
  }
}