Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Replace private and deprecated _lookupFactory with public & performant factoryFor #442

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions addon/-private/factory-for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
Utility to use `ApplicationInstance#factoryFor` if available (2.12+) and
fallback to private `_lookupFactory` otherwise
*/
export default function factoryFor(owner, type) {
let factory;
if (owner.factoryFor) {
let maybeFactory = owner.factoryFor(type);
factory = maybeFactory && maybeFactory.class;
} else {
factory = owner._lookupFactory(type);
}
return factory;
}
3 changes: 2 additions & 1 deletion addon/validations/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Ember from 'ember';
import flatten from '../utils/flatten';
import assign from '../utils/assign';
import ValidationResult from '../-private/result';
import factoryFor from '../-private/factory-for';
import ResultCollection from './result-collection';
import BaseValidator from '../validators/base';
import cycleBreaker from '../utils/cycle-breaker';
Expand Down Expand Up @@ -738,7 +739,7 @@ function createValidatorsFor(attribute, model) {
* @return {Class} Validator class or undefined if not found
*/
function lookupValidator(owner, type) {
let validatorClass = owner._lookupFactory(`validator:${type}`);
let validatorClass = factoryFor(owner, `validator:${type}`);

if (isNone(validatorClass)) {
throw new Error(`[ember-cp-validations] Validator not found of type: ${type}.`);
Expand Down
3 changes: 2 additions & 1 deletion addon/validators/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import Ember from 'ember';
import Messages from 'ember-cp-validations/validators/messages';
import Options from 'ember-cp-validations/-private/options';
import factoryFor from '../-private/factory-for';
import { unwrapString, getValidatableValue, mergeOptions } from 'ember-cp-validations/utils/utils';

const {
Expand Down Expand Up @@ -88,7 +89,7 @@ const Base = Ember.Object.extend({

if (!isNone(owner)) {
// Since default error messages are stored in app/validators/messages, we have to look it up via the owner
errorMessages = owner._lookupFactory('validator:messages');
errorMessages = factoryFor(owner, 'validator:messages');
}

// If for some reason, we can't find the messages object (i.e. unit tests), use default
Expand Down