[fieldFormats] shorten #defaultFor() to #for()

This commit is contained in:
Spencer Alger 2015-04-08 18:13:47 -07:00
parent 60d05b39e5
commit 32a0dbb663
6 changed files with 8 additions and 12 deletions

View file

@ -27,7 +27,7 @@ define(function (require) {
if (field && field.type === 'date' && field.format) {
return field.format;
} else {
return fieldFormats.converterFor('number');
return fieldFormats.for('number');
}
};

View file

@ -10,7 +10,7 @@ define(function (require) {
var type = fieldTypes.byName[spec.type];
if (!type) throw new TypeError('unknown field type :' + spec.type);
var format = fieldFormats.byName[spec.formatName] || fieldFormats.defaultFor(spec.type);
var format = fieldFormats.byName[spec.formatName] || fieldFormats.for(spec.type);
var indexed = !!spec.indexed;
var scripted = !!spec.scripted;
var sortable = indexed && type.sortable;

View file

@ -270,7 +270,7 @@ define(function (require) {
AggConfig.prototype.fieldFormatter = function () {
var field = this.field();
var format = field && field.format;
var strFormat = fieldFormats.defaultByType.string;
var strFormat = fieldFormats.for('string');
if (this.type.getFormat) {
format = this.type.getFormat(this) || format;

View file

@ -8,7 +8,7 @@ define(function (require) {
return function ($parent, $scope, field) {
$scope.field = field;
$scope.defaultFormatName = fieldFormats.defaultFor(field.type).name;
$scope.defaultFormatName = fieldFormats.for(field.type).name;
$scope.formatOptionNames = [DEFAULT].concat(
_.pluck(fieldFormats.byFieldType[field.type], 'name')
);
@ -34,4 +34,4 @@ define(function (require) {
};
};
};
});
});

View file

@ -13,14 +13,10 @@ define(function (require) {
constructor: function (config) {
this.defaultFor = function (type, fallbackFormat) {
this.for = function (type, fallbackFormat) {
var name = config.get('defaultFormat:' + type);
return this.byName[name] || (fallbackFormat || defaultFallbackFormat);
};
this.converterFor = function (type) {
return this.defaultFor(type).convert;
};
}
});
});
});

View file

@ -20,7 +20,7 @@ define(function (require) {
Object.defineProperty(field, 'format', {
enumerable: false,
get: function () {
return fieldFormats.defaultFor(field.type);
return fieldFormats.for(field.type);
}
});