]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Immutable Locale#set
authorLucas Sanders <butterflyhug@google.com>
Sun, 19 Mar 2017 03:58:05 +0000 (23:58 -0400)
committerLucas Sanders <butterflyhug@google.com>
Wed, 22 Mar 2017 11:00:20 +0000 (07:00 -0400)
src/lib/locale/constructor.js
src/lib/locale/prototype.js
src/lib/locale/set.js

index dfaaed2a3a309aaab2f937e4213823947078f891..fb8b3f1aa6bffb36247a52d966d4c518a4c02ba9 100644 (file)
@@ -1,7 +1,23 @@
-import { set } from './set';
+import isFunction from '../utils/is-function';
 
 export function Locale(config) {
-    if (config != null) {
-        set.call(this, config);
+    if (config == null) {
+        return;
     }
+    var prop, i;
+    for (i in config) {
+        prop = config[i];
+        if (isFunction(prop)) {
+            this[i] = prop;
+        } else {
+            this['_' + i] = prop;
+        }
+    }
+    this._config = config;
+    // Lenient ordinal parsing accepts just a number in addition to
+    // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
+    // TODO: Remove "ordinalParse" fallback in next major release.
+    this._dayOfMonthOrdinalParseLenient = new RegExp(
+        (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
+            '|' + (/\d{1,2}/).source);
 }
index 5be98757f79a428ac894f672595aaed06fe3bab4..a357ba3a7e5cd82faa64c9d18aa842d631ba54ae 100644 (file)
@@ -9,7 +9,6 @@ import { ordinal } from './ordinal';
 import { preParsePostFormat } from './pre-post-format';
 import { relativeTime, pastFuture } from './relative';
 import { set } from './set';
-import wrap from '../utils/wrap';
 
 proto.calendar        = calendar;
 proto.longDateFormat  = longDateFormat;
@@ -19,7 +18,7 @@ proto.preparse        = preParsePostFormat;
 proto.postformat      = preParsePostFormat;
 proto.relativeTime    = relativeTime;
 proto.pastFuture      = pastFuture;
-proto.set             = wrap(Locale, set);
+proto.set             = set;
 
 // Month
 import {
index c63d5adec10e340b35738c183d1df32e7b7863f8..afa19b6ac35155c05eb2c7cddbfd18140b6e2cda 100644 (file)
@@ -1,25 +1,10 @@
-import isFunction from '../utils/is-function';
+import { Locale } from './constructor';
 import extend from '../utils/extend';
 import isObject from '../utils/is-object';
 import hasOwnProp from '../utils/has-own-prop';
 
 export function set (config) {
-    var prop, i;
-    for (i in config) {
-        prop = config[i];
-        if (isFunction(prop)) {
-            this[i] = prop;
-        } else {
-            this['_' + i] = prop;
-        }
-    }
-    this._config = config;
-    // Lenient ordinal parsing accepts just a number in addition to
-    // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
-    // TODO: Remove "ordinalParse" fallback in next major release.
-    this._dayOfMonthOrdinalParseLenient = new RegExp(
-        (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
-            '|' + (/\d{1,2}/).source);
+    return new Locale(mergeConfigs(this._config, config));
 }
 
 export function mergeConfigs(parentConfig, childConfig) {