gabrielcsapo / ember-resolver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ember Resolver CI Build

The Ember Resolver is the mechanism responsible for looking up code in your application and converting its naming conventions into the actual classes, functions, and templates that Ember needs to resolve its dependencies, for example, what template to render for a given route. It is a system that helps the app resolve the lookup of JavaScript modules agnostic of what kind of module system is used, which can be AMD, CommonJS or just plain globals. It is used to lookup routes, models, components, templates, or anything that is used in your Ember app.

This project provides the Ember resolver used by ember-cli

Installation

ember-resolver is an ember-cli addon, and should be installed with ember install:

ember install ember-resolver

Configuration

To customize pluralization provide a pluralizedTypes object to your applications resolver:

// app/app.js
import Resolver from 'ember-resolver';

export default class AppResolver extends Resolver {
  pluralizedTypes = {
    'sheep': 'sheep',
    'strategy': 'strategies'
  }
}

// ...snip...
export default class App extends Application {
  // ...snip...
  Resolver = AppResolver;
}

// ...snip...

Strict

Note This was originally developed as https://github.com/stefanpenner/ember-strict-resolver

in app/resolver.js

export { default } from "ember-resolver/strict";

Migration

Migrating to the strict resolver from the classic can be done piecemeal by supporting a sub-set of the old resolution formats.

Note normalize is needed because without it you will get errors related to failing to be able to inject services that were never normalized in the registry.

// app/resolver.js

import Resolver from "ember-resolver/strict";

export default class extends Resolver {
  legacyMappings = {
    "service:camelCaseNotSupported": "service:camel-case-not-supported",
  };

  resolve(_fullName) {
    return super.resolve(this.legacyMappings[_fullName] || _fullName);
  }

  normalize(_fullName) {
    return this.legacyMappings[_fullName] || _fullName;
  }
}

This will allow you file PRs with libraries that currently do not support the strict resolver in its entirety.

If you have a component that is failing to resolve correctly with the error Attempted to lookup "helper:nameOfVariable". Use "helper:name-of-variable" instead., please convert your template to use explicit-this (also required by Ember v4.0). The template lint can be enabled by turning on no-implicit-this.

An example of what this looks like is the following

// addon/components/templates/foo.hbs

<div>
  {{fullName}}
</div>

This will result in the error, Attempted to lookup "helper:fullName". Use "helper:full-name" instead.. The fix for this would be to decide if this is a argument being passed into foo or if this is a local property.

fullName is coming from an invocation of Foo like the following:

<Foo
  @fullName="The Teamster"
/>

Then the fix for your template would be:

// addon/components/templates/foo.hbs

<div>
  {{@fullName}}
</div>

If fullName is a property on your component the fix would be:

// addon/components/templates/foo.hbs

<div>
  {{this.fullName}}
</div>

Addon Development

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

About

License:MIT License


Languages

Language:JavaScript 97.2%Language:HTML 2.8%Language:Handlebars 0.0%