Reducers are the incremental state management layer of Shiftly’s domain. When a user edits a shift, only the affected day needs to be recalculated — not the entire month. Reducers make this efficient by supporting three operations: creating an empty baseline state, accumulating a new contribution into the running total, and subtracting a prior contribution when it is replaced or removed. The result is aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dmaman86/shiftly/llms.txt
Use this file to discover all available pages before exploring further.
MonthPayMap that always reflects the sum of all days recorded so far, updated in O(1) relative to the number of days in the month.
The Reducer Interface
State is the type being maintained (e.g. MonthPayMap, MealAllowance). Input defaults to State but can differ — MonthPayMapReducer uses WorkDayMap as its input type while maintaining MonthPayMap as its state.
Why Reducers Exist
When a shift is edited:- The day’s old
WorkDayMap(stored in Redux) is subtracted from the runningMonthPayMap. - The day’s newly computed
WorkDayMapis accumulated into the sameMonthPayMap.
subtract → accumulate pattern avoids iterating over all 30+ days whenever a single shift changes. All subtract operations clamp at 0 to prevent negative hour counts from floating-point rounding.
Reducers Overview
MonthPayMapReducer
The top-level orchestrator: accumulates and subtracts a full
WorkDayMap into the running MonthPayMap by delegating to sub-reducers.RegularByMonthAccumulator
Accumulates
RegularBreakdown values across shifts within a day, and across days within the month.FixedSegmentMonthReducer
Tracks sick-day hours, vacation hours, and extra-Shabbat hours across all days of the month.
MealAllowanceMonthReducer
Accumulates meal allowance points and monetary amounts (large and small) across the month.
WorkDayMonthReducer
Accumulates regular, extra, and special pay breakdowns from each day’s
workMap into the monthly totals.MonthPayMapReducer
MonthPayMapReducer is the root reducer for the monthly payslip state. It implements Reducer<MonthPayMap, WorkDayMap> and coordinates four sub-reducers, each responsible for a distinct slice of MonthPayMap.
State Shape
Methods
RegularByMonthAccumulator
RegularByMonthAccumulator extends BaseRegularCalculator and inherits its accumulate and subtract implementations. It is used as the month-level reducer for regular hours, accumulating each day’s RegularBreakdown contribution into the running MonthPayMap.
FixedSegmentMonthReducer
FixedSegmentMonthReducer accumulates the three fixed-rate segments that appear as separate payslip line items rather than as part of the regular overtime calculation.
FixedSegmentFactory.create(hours) to construct the Segment — ensuring the percent field is always 1.0 regardless of the hours accumulated.
| Field | Source | Meaning |
|---|---|---|
hours100Sick | WorkDayMap.hours100Sick | Sick-day hours paid at standard rate |
hours100Vacation | WorkDayMap.hours100Vacation | Vacation-day hours paid at standard rate |
extra100Shabbat | WorkDayMap.extra100Shabbat | Shabbat/holiday shift hours for separate line tracking |
MealAllowanceMonthReducer
MealAllowanceMonthReducer accumulates meal allowance across all days of the month, maintaining separate running totals for large and small allowances.
points and amount are accumulated independently, so the month-level total reflects the sum of each day’s entitlement. Subtraction clamps both fields at 0.
WorkDayMonthReducer
WorkDayMonthReducer accumulates the three core pay breakdowns — regular, extra, and special — from each day’s workMap into the running monthly state.
add.workMap.regular, add.workMap.extra, and add.workMap.special — the shift-level computation results embedded in the day’s WorkDayMap.
The Subtract + Accumulate Pattern
The Redux actionaddDayPayMap in globalSlice.ts demonstrates the canonical update pattern that all reducers are designed for:
MonthPayMap is always the exact sum of all stored WorkDayMap values — no full month recomputation is ever needed, regardless of how many shifts have been recorded.