Skip to content

Commit a9754b6

Browse files
committed
Runtime: Fix unitFormatter with numberFormatter (2/2)
Ref #704 Ref #719
1 parent 0d31631 commit a9754b6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/common/runtime-stringify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ define([], function( ) {
22

33
return function( args ) {
44
return JSON.stringify( args, function( key, value ) {
5-
if ( typeof value === "function" ) {
6-
return value.runtimeKey; // if undefined, the value will be filtered out.
5+
if ( value && value.runtimeKey ) {
6+
return value.runtimeKey;
77
}
88
return value;
99
} );

src/number-runtime.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ Globalize._validateParameterPresence = validateParameterPresence;
2929
Globalize._validateParameterTypeNumber = validateParameterTypeNumber;
3030
Globalize._validateParameterTypeString = validateParameterTypeString;
3131

32+
// Stamp runtimeKey and return cached fn.
33+
// Note, this function isn't made common to all formatters and parsers, because in practice this is
34+
// only used (at the moment) for numberFormatter used by unitFormatter.
35+
// TODO: Move this function into a common place when this is used by different formatters.
36+
function cached( runtimeKey ) {
37+
Globalize[ runtimeKey ].runtimeKey = runtimeKey;
38+
return Globalize[ runtimeKey ];
39+
}
40+
3241
Globalize.numberFormatter =
3342
Globalize.prototype.numberFormatter = function( options ) {
3443
options = options || {};
35-
return Globalize[ runtimeKey( "numberFormatter", this._locale, [ options ] ) ];
44+
return cached( runtimeKey( "numberFormatter", this._locale, [ options ] ) );
3645
};
3746

3847
Globalize.numberParser =

0 commit comments

Comments
 (0)