Skip to content

Commit

Permalink
WIP PR cleanup to rename rawString
Browse files Browse the repository at this point in the history
  • Loading branch information
iezer committed Jan 31, 2018
1 parent 999d93d commit 4dc4587
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
12 changes: 6 additions & 6 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function isFactoryInstance(container, fullName, { instantiate, singleton }) {
}

function instantiateFactory(container, fullName, options) {
let factoryManager = EMBER_MODULE_UNIFICATION && options ? container.factoryFor(fullName, options) : container.factoryFor(fullName);
let factoryManager = container.factoryFor(fullName, options);

if (factoryManager === undefined) {
return;
Expand Down Expand Up @@ -319,10 +319,10 @@ function buildInjections(container, injections) {
let injection;
for (let i = 0; i < injections.length; i++) {
injection = injections[i];
let {name, rawString, type} = parseInjectionString(injection.fullName);
hash[injection.property] = lookupWithRawString(container, type, rawString || name);
let {name, namespace, type} = parseInjectionString(injection.fullName);
hash[injection.property] = lookupWithRawString(container, type, namespace || name);
if (!isDynamic) {
isDynamic = !isSingleton(container, injection.fullName, {[RAW_STRING_OPTION_KEY]: rawString});
isDynamic = !isSingleton(container, injection.fullName, {[RAW_STRING_OPTION_KEY]: namespace});
}
}
}
Expand Down Expand Up @@ -462,7 +462,7 @@ export function parseInjectionString(injectionString) {
let fullName = type.indexOf(':') === -1 ? `${type}:${name}` : `${type}${name}`;
return {
fullName,
rawString: namespace,
namespace,
type
};
}
Expand All @@ -485,7 +485,7 @@ export function factoryForWithRawString(container, type, rawString) {
return container.factoryFor(`${type}:${rawString}`);
} else {
let [ namespace, name ] = rawString.split('::');
// type might already contain : eg. "template:components/"
// type might already contain ":" eg. "template:components/"
let fullName = type.indexOf(':') === -1 ? `${type}:${name}` : `${type}${name}`;
return container.factoryFor(fullName, {
[RAW_STRING_OPTION_KEY]: namespace
Expand Down
29 changes: 10 additions & 19 deletions packages/container/lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { DEBUG } from 'ember-env-flags';
import { ENV } from 'ember-environment';

const VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;

let missingResolverFunctionsDeprecation = 'Passing a `resolver` function into a Registry is deprecated. Please pass in a Resolver object with a `resolve` method.';
const missingResolverFunctionsDeprecation = 'Passing a `resolver` function into a Registry is deprecated. Please pass in a Resolver object with a `resolve` method.';

/**
A registry used to store factory and option information keyed
Expand Down Expand Up @@ -188,7 +187,6 @@ export default class Registry {

this._localLookupCache = Object.create(null);


delete this.registrations[normalizedName];
delete this._resolveCache[cacheKey];
delete this._options[cacheKey];
Expand Down Expand Up @@ -329,9 +327,9 @@ export default class Registry {
}

let source = options && options.source && this.normalize(options.source);
let rawString = options && options[RAW_STRING_OPTION_KEY];
let namespace = options && options[RAW_STRING_OPTION_KEY];

return has(this, this.normalize(fullName), source, rawString);
return has(this, this.normalize(fullName), source, namespace);
}

/**
Expand Down Expand Up @@ -554,14 +552,7 @@ export default class Registry {
return assign({}, fallbackKnown, localKnown, resolverKnown);
}

isValidFullName(fullName, options) {
if(EMBER_MODULE_UNIFICATION) {
/* With a rawString, the fullName doesn't need to contain a : */
if (options && options[RAW_STRING_OPTION_KEY] && fullName) {
return true;
}
}

isValidFullName(fullName) {
return VALID_FULL_NAME_REGEXP.test(fullName);
}

Expand Down Expand Up @@ -642,9 +633,9 @@ if (DEBUG) {
if (hash.hasOwnProperty(key)) {
let {
fullName,
rawString
namespace
} = parseInjectionString(hash[key]);
assert(`Expected a proper full name, given '${fullName}'`, this.isValidFullName(fullName, {[RAW_STRING_OPTION_KEY]: rawString}));
assert(`Expected a proper full name, given '${fullName}'`, this.isValidFullName(fullName, {[RAW_STRING_OPTION_KEY]: namespace}));

injections.push({
property: key,
Expand All @@ -662,10 +653,10 @@ if (DEBUG) {
for (let i = 0; i < injections.length; i++) {
let {
fullName,
rawString
namespace
} = parseInjectionString(injections[i].fullName);

assert(`Attempting to inject an unknown injection: '${fullName}'`, this.has(fullName, {[RAW_STRING_OPTION_KEY]: rawString}));
assert(`Attempting to inject an unknown injection: '${fullName}'`, this.has(fullName, {[RAW_STRING_OPTION_KEY]: namespace}));
}
};
}
Expand Down Expand Up @@ -732,10 +723,10 @@ function resolve(registry, normalizedName, options) {
return resolved;
}

function has(registry, fullName, source, rawString) {
function has(registry, fullName, source, namespace) {
return registry.resolve(fullName, {
source,
[RAW_STRING_OPTION_KEY]: rawString
[RAW_STRING_OPTION_KEY]: namespace
}) !== undefined;
}

Expand Down

0 comments on commit 4dc4587

Please sign in to comment.