]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Remove _bubble() from Duration prototype and make its API immutable
authorLucas Sanders <butterflyhug@google.com>
Sun, 30 Oct 2016 18:27:56 +0000 (14:27 -0400)
committerLucas Sanders <butterflyhug@google.com>
Wed, 22 Mar 2017 10:12:27 +0000 (06:12 -0400)
The bubble function now returns a new data object instead of
mutating the duration's existing data (which had always been empty
when we called _bubble anyway).

src/lib/duration/bubble.js
src/lib/duration/constructor.js
src/lib/duration/prototype.js

index 0c4a336ec47d3b89fa3e077be878a4caa7d7c7a4..f24ec5c5d4a585335d76e47d5e7a8a188d0141e6 100644 (file)
@@ -2,11 +2,11 @@ import absFloor from '../utils/abs-floor';
 import absCeil from '../utils/abs-ceil';
 import { createUTCDate } from '../create/date-from-array';
 
-export function bubble () {
-    var milliseconds = this._milliseconds;
-    var days         = this._days;
-    var months       = this._months;
-    var data         = this._data;
+export function bubble (duration) {
+    var milliseconds = duration._milliseconds;
+    var days         = duration._days;
+    var months       = duration._months;
+    var data         = {};
     var seconds, minutes, hours, years, monthsFromDays;
 
     // if we have a mix of positive and negative values, bubble down first
@@ -45,8 +45,7 @@ export function bubble () {
     data.days   = days;
     data.months = months;
     data.years  = years;
-
-    return this;
+    return data;
 }
 
 export function daysToMonths (days) {
index 5c97ef1087a82d869504b613267826a91638d5fb..578ba34f617ec7d2994dd2de8617b9926b3bf2f0 100644 (file)
@@ -1,6 +1,7 @@
 import { normalizeObjectUnits } from '../units/aliases';
 import { getLocale } from '../locale/locales';
-import isDurationValid from './valid.js';
+import { bubble } from './bubble';
+import isDurationValid from './valid';
 
 export function Duration (duration) {
     var normalizedInput = normalizeObjectUnits(duration),
@@ -32,11 +33,9 @@ export function Duration (duration) {
         quarters * 3 +
         years * 12;
 
-    this._data = {};
+    this._data = bubble(this);
 
     this._locale = getLocale();
-
-    this._bubble();
 }
 
 export function isDuration (obj) {
index 3fd516a5650d4127816fb51e416afa6d741abf50..7eaca44612c7656a2402983eaa0bc46f25942151 100644 (file)
@@ -27,7 +27,6 @@ proto.asWeeks        = asWeeks;
 proto.asMonths       = asMonths;
 proto.asYears        = asYears;
 proto.valueOf        = valueOf;
-proto._bubble        = bubble;
 proto.get            = get;
 proto.milliseconds   = milliseconds;
 proto.seconds        = seconds;