Example #1
0
  enter: function(view) {
    if (!View) { View = requireModule('ember-views/views/view')["default"]; } // ES6TODO: this sucks. Have to avoid cycles...

    // Register the view for event handling. This hash is used by
    // Ember.EventDispatcher to dispatch incoming events.
    if (!view.isVirtual) {
      Ember.assert("Attempted to register a view with an id already in use: "+view.elementId, !View.views[view.elementId]);
      View.views[view.elementId] = view;
    }

    Ember.runInDebug(function() {
      addBeforeObserver(view, 'elementId', function() {
        throw new EmberError("Changing a view's elementId after creation is not allowed");
      });
    });
  },
Example #2
0
@submodule ember-views
*/

var inDOM = Object.create(hasElement);

merge(inDOM, {
  enter(view) {
    // Register the view for event handling. This hash is used by
    // Ember.EventDispatcher to dispatch incoming events.
    if (view.tagName !== '') {
      view._register();
    }

    Ember.runInDebug(function() {
      addBeforeObserver(view, 'elementId', function() {
        throw new EmberError('Changing a view\'s elementId after creation is not allowed');
      });
    });
  },

  exit(view) {
    view._unregister();
  },

  appendAttr(view, attrNode) {
    var childViews = view.childViews;

    if (!childViews.length) { childViews = view.childViews = childViews.slice(); }
    childViews.push(attrNode);

    attrNode.parentView = view;
ComponentNodeManager.create = function(renderNode, env, options) {
  let { tagName,
        params,
        attrs,
        parentView,
        parentScope,
        isAngleBracket,
        component,
        layout,
        templates } = options;

  attrs = attrs || {};

  component = component || (isAngleBracket ? GlimmerComponent : LegacyEmberComponent);

  let createOptions = { parentView };

  configureTagName(attrs, tagName, component, isAngleBracket, createOptions);

  // Map passed attributes (e.g. <my-component id="foo">) to component
  // properties ({ id: "foo" }).
  configureCreateOptions(attrs, createOptions);

  // If there is a controller on the scope, pluck it off and save it on the
  // component. This allows the component to target actions sent via
  // `sendAction` correctly.
  if (parentScope.locals.controller) {
    createOptions._controller = getValue(parentScope.locals.controller);
  }

  extractPositionalParams(renderNode, component, params, attrs);

  // Instantiate the component
  component = createComponent(component, isAngleBracket, createOptions, renderNode, env, attrs);

  // If the component specifies its template via the `layout properties
  // instead of using the template looked up in the container, get them
  // now that we have the component instance.
  layout = get(component, 'layout') || layout;

  Ember.runInDebug(() => {
    var assert = Ember.assert;

    if (isAngleBracket) {
      assert(`You cannot invoke the '${tagName}' component with angle brackets, because it's a subclass of Component. Please upgrade to GlimmerComponent. Alternatively, you can invoke as '{{${tagName}}}'.`, component.isGlimmerComponent);
    } else {
      assert(`You cannot invoke the '${tagName}' component with curly braces, because it's a subclass of GlimmerComponent. Please invoke it as '<${tagName}>' instead.`, !component.isGlimmerComponent);
    }

    if (!layout) { return; }

    let fragmentReason = layout.meta.fragmentReason;
    if (isAngleBracket && fragmentReason) {
      switch (fragmentReason.name) {
        case 'missing-wrapper':
          assert(`The <${tagName}> template must have a single top-level element because it is a GlimmerComponent.`);
          break;
        case 'modifiers':
          let modifiers = fragmentReason.modifiers.map(m => `{{${m} ...}}`);
          assert(`You cannot use ${ modifiers.join(', ') } in the top-level element of the <${tagName}> template because it is a GlimmerComponent.`);
          break;
        case 'triple-curlies':
          assert(`You cannot use triple curlies (e.g. style={{{ ... }}}) in the top-level element of the <${tagName}> template because it is a GlimmerComponent.`);
          break;
      }
    }
  });

  let results = buildComponentTemplate(
    { layout, component, isAngleBracket }, attrs, { templates, scope: parentScope }
  );

  return new ComponentNodeManager(component, isAngleBracket, parentScope, renderNode, attrs, results.block, results.createdElement);
};