MCPcopy Index your code
hub / github.com/react-dates/react-dates / deleteModifier

Function deleteModifier

src/utils/modifiers.js:63–116  ·  view source on GitHub ↗
(updatedDays, day, modifier, props, state)

Source from the content-addressed store, hash-verified

61}
62
63export function deleteModifier(updatedDays, day, modifier, props, state) {
64 const { numberOfMonths: numberOfVisibleMonths, enableOutsideDays, orientation } = props;
65 const { currentMonth: firstVisibleMonth, visibleDays } = state;
66
67 let currentMonth = firstVisibleMonth;
68 let numberOfMonths = numberOfVisibleMonths;
69 if (orientation === VERTICAL_SCROLLABLE) {
70 numberOfMonths = Object.keys(visibleDays).length;
71 } else {
72 currentMonth = getPreviousMonthMemoLast(currentMonth);
73 numberOfMonths += 2;
74 }
75 if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) {
76 return updatedDays;
77 }
78
79 const iso = toISODateString(day);
80
81 let updatedDaysAfterDeletion = { ...updatedDays };
82 if (enableOutsideDays) {
83 const monthsToUpdate = Object.keys(visibleDays).filter((monthKey) => (
84 Object.keys(visibleDays[monthKey]).indexOf(iso) > -1
85 ));
86
87 updatedDaysAfterDeletion = monthsToUpdate.reduce((acc, monthIso) => {
88 const month = updatedDays[monthIso] || visibleDays[monthIso];
89
90 if (month[iso] && month[iso].has(modifier)) {
91 const modifiers = new Set(month[iso]);
92 modifiers.delete(modifier);
93 acc[monthIso] = {
94 ...month,
95 [iso]: modifiers,
96 };
97 }
98
99 return acc;
100 }, updatedDaysAfterDeletion);
101 } else {
102 const monthIso = toISOMonthString(day);
103 const month = updatedDays[monthIso] || visibleDays[monthIso] || {};
104
105 if (month[iso] && month[iso].has(modifier)) {
106 const modifiers = new Set(month[iso]);
107 modifiers.delete(modifier);
108 updatedDaysAfterDeletion[monthIso] = {
109 ...month,
110 [iso]: modifiers,
111 };
112 }
113 }
114
115 return updatedDaysAfterDeletion;
116}

Callers 2

deleteModifierMethod · 0.90
deleteModifierMethod · 0.90

Calls 4

getPreviousMonthMemoLastFunction · 0.85
isDayVisibleFunction · 0.85
toISODateStringFunction · 0.85
toISOMonthStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…