Skip to content

Commit bf4eb5a

Browse files
committed
fix(ui): immutable functions need return value
1 parent 00f9dda commit bf4eb5a

File tree

4 files changed

+99
-107
lines changed

4 files changed

+99
-107
lines changed

packages/ui/src/composables/useInterval.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export default function (
425425
}
426426

427427
if (now) {
428-
updateRelative(timestamp, now, true)
428+
timestamp = updateRelative(timestamp, now, true)
429429
}
430430

431431
return timestamp
@@ -457,7 +457,7 @@ export default function (
457457
}
458458

459459
if (now) {
460-
updateRelative(timestamp, now, true)
460+
timestamp = updateRelative(timestamp, now, true)
461461
}
462462

463463
return timestamp
@@ -489,7 +489,7 @@ export default function (
489489
}
490490

491491
if (now) {
492-
updateRelative(timestamp, now, true)
492+
timestamp = updateRelative(timestamp, now, true)
493493
}
494494

495495
return timestamp

packages/ui/src/composables/useMove.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import {
1010
updateWeekday,
1111
nextDay,
1212
prevDay,
13-
today
13+
today,
1414
} from '../utils/Timestamp.js'
1515

16-
export const useMoveEmits = [
17-
'moved'
18-
]
16+
export const useMoveEmits = ['moved']
1917

2018
/**
2119
* export of default funtion
@@ -35,16 +33,10 @@ export const useMoveEmits = [
3533
* @param {import('vue').Ref} param.emittedValue reactive sting that is emitted when changed (YYYY-MM-DD)
3634
* @param {Function} param.emit Vue emit function
3735
*/
38-
export default function (props, {
39-
parsedView,
40-
parsedValue,
41-
weekdaySkips,
42-
direction,
43-
maxDays,
44-
times,
45-
emittedValue,
46-
emit
47-
}) {
36+
export default function (
37+
props,
38+
{ parsedView, parsedValue, weekdaySkips, direction, maxDays, times, emittedValue, emit },
39+
) {
4840
/**
4941
* Moves the calendar the desired amount. This is based on the 'view'.
5042
* A month calendar moves by prev/next month
@@ -53,7 +45,7 @@ export default function (props, {
5345
* @param {Number} amount The amount to move (default 1)
5446
* @fires 'moved' with current Timestamp
5547
*/
56-
function move (amount = 1) {
48+
function move(amount = 1) {
5749
if (amount === 0) {
5850
emittedValue.value = today()
5951
return
@@ -64,50 +56,52 @@ export default function (props, {
6456
const limit = forward ? DAYS_IN_MONTH_MAX : DAY_MIN
6557
let count = forward ? amount : -amount
6658
direction.value = forward ? 'next' : 'prev'
67-
const dayCount = weekdaySkips.value.filter(x => x !== 0).length
59+
const dayCount = weekdaySkips.value.filter((x) => x !== 0).length
6860

6961
while (--count >= 0) {
7062
switch (parsedView.value) {
7163
case 'month':
64+
// set to 1st or last day of the month
7265
moved.day = limit
73-
mover(moved)
74-
updateWeekday(moved)
75-
while (weekdaySkips.value[ moved.weekday ] === 0) {
66+
moved = mover(moved)
67+
moved = updateWeekday(moved)
68+
while (weekdaySkips.value[moved.weekday] === 0) {
7669
moved = addToDate(moved, { day: forward === true ? 1 : -1 })
7770
}
7871
break
7972
case 'week':
8073
case 'week-agenda':
8174
case 'week-scheduler':
82-
relativeDays(moved, mover, dayCount, props.weekdays)
75+
moved = relativeDays(moved, mover, dayCount, props.weekdays)
8376
break
8477
case 'day':
8578
case 'scheduler':
8679
case 'agenda':
87-
relativeDays(moved, mover, maxDays.value, props.weekdays)
80+
moved = relativeDays(moved, mover, maxDays.value, props.weekdays)
8881
break
8982
case 'month-interval':
9083
case 'month-agenda':
9184
case 'month-scheduler':
85+
// set to 1st or last day of the month
9286
moved.day = limit
93-
mover(moved)
87+
moved = mover(moved)
9488
break
9589
case 'resource':
96-
relativeDays(moved, mover, maxDays.value, props.weekdays)
90+
moved = relativeDays(moved, mover, maxDays.value, props.weekdays)
9791
break
9892
}
9993
}
10094

101-
updateWeekday(moved)
102-
updateFormatted(moved)
103-
updateDayOfYear(moved)
104-
updateRelative(moved, times.now)
95+
moved = updateWeekday(moved)
96+
moved = updateFormatted(moved)
97+
moved = updateDayOfYear(moved)
98+
moved = updateRelative(moved, times.now)
10599

106100
emittedValue.value = moved.date
107101
emit('moved', moved)
108102
}
109103

110104
return {
111-
move
105+
move,
112106
}
113107
}

packages/ui/src/composables/useRenderValues.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ import {
99
getEndOfWeek,
1010
moveRelativeDays,
1111
updateFormatted,
12-
nextDay
12+
nextDay,
1313
} from '../utils/Timestamp.js'
1414

15-
export default function (props, {
16-
parsedView,
17-
parsedValue,
18-
times
19-
}) {
15+
export default function (props, { parsedView, parsedValue, times }) {
2016
const renderValues = computed(() => {
2117
const around = parsedValue.value
2218
let maxDays = props.maxDays
@@ -38,27 +34,32 @@ export default function (props, {
3834
case 'day':
3935
case 'scheduler':
4036
case 'agenda':
41-
end = moveRelativeDays(copyTimestamp(end), nextDay, maxDays > 1 ? maxDays - 1 : maxDays, props.weekdays)
42-
updateFormatted(end)
37+
end = moveRelativeDays(
38+
copyTimestamp(end),
39+
nextDay,
40+
maxDays > 1 ? maxDays - 1 : maxDays,
41+
props.weekdays,
42+
)
43+
end = updateFormatted(end)
4344
break
4445
case 'month-interval':
4546
case 'month-scheduler':
4647
case 'month-agenda':
4748
start = getStartOfMonth(around)
4849
end = getEndOfMonth(around)
49-
updateFormatted(end)
50+
end = updateFormatted(end)
5051
maxDays = daysInMonth(start.year, start.month)
5152
break
5253
case 'resource':
5354
maxDays = 1
5455
end = moveRelativeDays(copyTimestamp(end), nextDay, maxDays, props.weekdays)
55-
updateFormatted(end)
56+
end = updateFormatted(end)
5657
break
5758
}
5859
return { start, end, maxDays }
5960
})
6061

6162
return {
62-
renderValues
63+
renderValues,
6364
}
6465
}

0 commit comments

Comments
 (0)