Sha256: d9a55ded4ef9f5240f517907d1437892e4026393a22a25e1df177ae022b817e1

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

import { EMBER_MODULE_UNIFICATION } from '@ember/canary-features';

function lookupModuleUnificationComponentPair(componentLookup, owner, name, options) {
  let localComponent = componentLookup.componentFor(name, owner, options);
  let localLayout = componentLookup.layoutFor(name, owner, options);

  let globalComponent = componentLookup.componentFor(name, owner);
  let globalLayout = componentLookup.layoutFor(name, owner);

  // TODO: we shouldn't have to recheck fallback, we should have a lookup that doesn't fallback
  if (
    localComponent !== undefined &&
    globalComponent !== undefined &&
    globalComponent.class === localComponent.class
  ) {
    localComponent = undefined;
  }
  if (
    localLayout !== undefined &&
    globalLayout !== undefined &&
    localLayout.referrer.moduleName === globalLayout.referrer.moduleName
  ) {
    localLayout = undefined;
  }

  if (localLayout !== undefined || localComponent !== undefined) {
    return { layout: localLayout, component: localComponent };
  }

  return { layout: globalLayout, component: globalComponent };
}

function lookupComponentPair(componentLookup, owner, name, options) {
  if (EMBER_MODULE_UNIFICATION) {
    return lookupModuleUnificationComponentPair(componentLookup, owner, name, options);
  }

  let component = componentLookup.componentFor(name, owner, options);
  let layout = componentLookup.layoutFor(name, owner, options);

  let result = { layout, component };

  return result;
}

export default function lookupComponent(owner, name, options) {
  let componentLookup = owner.lookup('component-lookup:main');

  if (options && (options.source || options.namespace)) {
    let localResult = lookupComponentPair(componentLookup, owner, name, options);

    if (localResult.component || localResult.layout) {
      return localResult;
    }
  }

  return lookupComponentPair(componentLookup, owner, name);
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/-internals/views/lib/utils/lookup-component.js
discourse-ember-source-3.5.1.1 dist/es/ember-views/lib/utils/lookup-component.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-views/lib/utils/lookup-component.js