Skip to content

Commit

Permalink
Runtime: Fix unitFormatter with numberFormatter (2/2)
Browse files Browse the repository at this point in the history
Ref #704
Ref #719
  • Loading branch information
rxaviers committed Jul 13, 2018
1 parent 0d31631 commit a9754b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/common/runtime-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ define([], function( ) {

return function( args ) {
return JSON.stringify( args, function( key, value ) {
if ( typeof value === "function" ) {
return value.runtimeKey; // if undefined, the value will be filtered out.
if ( value && value.runtimeKey ) {
return value.runtimeKey;
}
return value;
} );
Expand Down
11 changes: 10 additions & 1 deletion src/number-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ Globalize._validateParameterPresence = validateParameterPresence;
Globalize._validateParameterTypeNumber = validateParameterTypeNumber;
Globalize._validateParameterTypeString = validateParameterTypeString;

// Stamp runtimeKey and return cached fn.
// Note, this function isn't made common to all formatters and parsers, because in practice this is
// only used (at the moment) for numberFormatter used by unitFormatter.
// TODO: Move this function into a common place when this is used by different formatters.
function cached( runtimeKey ) {
Globalize[ runtimeKey ].runtimeKey = runtimeKey;
return Globalize[ runtimeKey ];
}

Globalize.numberFormatter =
Globalize.prototype.numberFormatter = function( options ) {
options = options || {};
return Globalize[ runtimeKey( "numberFormatter", this._locale, [ options ] ) ];
return cached( runtimeKey( "numberFormatter", this._locale, [ options ] ) );
};

Globalize.numberParser =
Expand Down

0 comments on commit a9754b6

Please sign in to comment.