Przeglądaj źródła

simpler way to do businessHour slicing

Adam Shaw 7 lat temu
rodzic
commit
79c5d1fc25
3 zmienionych plików z 22 dodań i 41 usunięć
  1. 20 23
      src/common/slicing-utils.ts
  2. 1 1
      src/exports.ts
  3. 1 17
      src/structs/business-hours.ts

+ 20 - 23
src/common/slicing-utils.ts

@@ -1,12 +1,11 @@
 import { DateRange } from '../datelib/date-range'
-import { EventStore } from '../structs/event-store'
+import { EventStore, expandRecurring } from '../structs/event-store'
 import { EventUiHash } from '../component/event-ui'
 import { sliceEventStore, EventRenderRange } from '../component/event-rendering'
 import { DateProfile } from '../DateProfileGenerator'
 import { Seg, EventSegUiInteractionState } from '../component/DateComponent'
 import { DateSpan, fabricateEventRange } from '../structs/date-span'
 import { EventInteractionState } from '../interactions/event-interaction-state'
-import { sliceBusinessHours } from '../structs/business-hours'
 import DateComponent from '../component/DateComponent'
 import { Duration } from '../datelib/duration'
 import reselector from '../util/reselector'
@@ -44,6 +43,25 @@ export class Slicer<
     this.slice = slice
   }
 
+  businessHoursToSegs (
+    businessHours: EventStore,
+    dateProfile: DateProfile,
+    nextDayThreshold: Duration,
+    otherArgs: OtherArgsType
+  ): SegType[] {
+    if (!businessHours) {
+      return []
+    }
+
+    return this.eventStoreToSegs(
+      expandRecurring(businessHours, dateProfile.activeRange, otherArgs.component.calendar),
+      {},
+      dateProfile,
+      nextDayThreshold,
+      otherArgs
+    ).bg
+  }
+
   eventStoreToSegs(
     eventStore: EventStore,
     eventUiBases: EventUiHash,
@@ -64,27 +82,6 @@ export class Slicer<
     }
   }
 
-  businessHoursToSegs (
-    businessHours: EventStore,
-    dateProfile: DateProfile,
-    nextDayThreshold: Duration,
-    otherArgs: OtherArgsType
-  ): SegType[] {
-    if (!businessHours) {
-      return []
-    }
-
-    return this.eventRangesToCompleteSegs(
-      sliceBusinessHours(
-        businessHours,
-        dateProfile.activeRange,
-        nextDayThreshold,
-        otherArgs.component.calendar
-      ),
-      otherArgs
-    )
-  }
-
   dateSpanToCompleteSegs(
     dateSpan: DateSpan,
     eventUiBases: EventUiHash,

+ 1 - 1
src/exports.ts

@@ -9,7 +9,7 @@ export const internalApiVersion = 12
 // types
 export { OptionsInput } from './types/input-types'
 export { EventInput, EventDef, EventInstance, EventInstanceHash } from './structs/event'
-export { BusinessHoursInput, sliceBusinessHours, parseBusinessHours } from './structs/business-hours'
+export { BusinessHoursInput, parseBusinessHours } from './structs/business-hours'
 
 export {
   applyAll,

+ 1 - 17
src/structs/business-hours.ts

@@ -1,10 +1,7 @@
 import Calendar from '../Calendar'
 import { assignTo } from '../util/object'
 import { EventInput } from './event'
-import { EventStore, parseEvents, expandRecurring } from './event-store'
-import { DateRange } from '../datelib/date-range'
-import { Duration } from '../datelib/duration'
-import { EventRenderRange, sliceEventStore } from '../component/event-rendering'
+import { EventStore, parseEvents } from './event-store'
 
 /*
 Utils for converting raw business hour input into an EventStore,
@@ -55,16 +52,3 @@ function refineInputs(input: BusinessHoursInput): EventInput[] {
 
   return rawDefs
 }
-
-
-// TODO: kill this?
-export function sliceBusinessHours(businessHours: EventStore, range: DateRange, nextDayThreshold: Duration, calendar: Calendar): EventRenderRange[] {
-  let expandedStore = expandRecurring(businessHours, range, calendar)
-
-  return sliceEventStore(
-    expandedStore,
-    {}, // eventUiBases
-    range,
-    nextDayThreshold
-  ).bg
-}