Skip to content

Commit

Permalink
Merge pull request #1 from glimmerjs/app-identify
Browse files Browse the repository at this point in the history
Support `identify` method directly on Application
  • Loading branch information
dgeb committed Feb 2, 2017
2 parents 0a23760 + 22a02a2 commit d697e4a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@glimmer/application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test": "testem ci"
},
"dependencies": {
"@glimmer/di": "^0.1.6",
"@glimmer/di": "^0.1.7",
"@glimmer/util": "^0.21.0"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/@glimmer/application/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export default class Application implements Owner {
this._registry.registerInjection(normalizedSpecifier, property, normalizedInjection);
}

identify(specifier: string, referrer?: string): string {
return this._toAbsoluteSpecifier(specifier, referrer);
}

factoryFor(specifier: string, referrer?: string): Factory<any> {
let absoluteSpecifier = this._toAbsoluteSpecifier(specifier, referrer);
return this._container.factoryFor(absoluteSpecifier);
Expand Down
21 changes: 21 additions & 0 deletions packages/@glimmer/application/test/application-container-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ const { module, test } = QUnit;

module('Application - Container interface');

test('#identify - returns an absolute specifier unchanged', function(assert) {
let app = new Application();
let absSpecifier = 'component:/app/components/date-picker';
assert.equal(app.identify(absSpecifier), absSpecifier, 'specifier was returned unchanged');
});

test('#identify - uses a resolver to convert a relative specifier to an absolute specifier', function(assert) {
assert.expect(2);

class FakeResolver implements Resolver {
identify(specifier: string, referrer?: string) {
assert.equal(specifier, 'component:date-picker', 'FakeResolver#identify was invoked');
return 'component:/app/components/date-picker';
}
}
let resolver = new FakeResolver();
let app = new Application(resolver);
let specifier = 'component:date-picker';
assert.equal(app.identify(specifier, 'component:/app/components/form-controls'), 'component:/app/components/date-picker', 'absolute specifier was returned');
});

test('#factoryFor - returns a registered factory', function(assert) {
class DatePicker {
static create() { return { foo: 'bar' }; }
Expand Down

0 comments on commit d697e4a

Please sign in to comment.