Просмотр исходного кода

just use dateProfile instead of currentDate

Adam Shaw 7 лет назад
Родитель
Сommit
0e817c6ed9
4 измененных файлов с 12 добавлено и 16 удалено
  1. 6 3
      src/Calendar.ts
  2. 1 1
      src/DateProfileGenerator.ts
  3. 1 1
      src/datelib/date-range.ts
  4. 4 11
      src/reducers/main.ts

+ 6 - 3
src/Calendar.ts

@@ -309,14 +309,17 @@ export default class Calendar {
       this.dispatch({ type: 'ADD_EVENT_SOURCE', rawSource })
     }
 
-    this.dispatch({ type: 'SET_VIEW_TYPE', viewType: this.opt('defaultView') })
+    this.dispatch({
+      type: 'SET_VIEW_TYPE',
+      viewType: this.opt('defaultView'),
+      dateMarker: this.getInitialDate()
+    })
   }
 
 
   buildInitialState(): CalendarState {
     return {
       loadingLevel: 0,
-      currentDate: this.getInitialDate(),
       dateProfile: null,
       eventSources: {},
       eventStore: {
@@ -679,7 +682,7 @@ export default class Calendar {
 
   // for external API
   getDate(): Date {
-    return this.dateEnv.toDate(this.state.currentDate)
+    return this.dateEnv.toDate(this.state.dateProfile.date)
   }
 
 

+ 1 - 1
src/DateProfileGenerator.ts

@@ -14,7 +14,7 @@ export interface DateProfile {
   minTime: Duration
   maxTime: Duration
   isValid: boolean
-  date: DateMarker
+  date: DateMarker // TODO: rename to currentDate
   dateIncrement: Duration
 }
 

+ 1 - 1
src/datelib/date-range.ts

@@ -39,7 +39,7 @@ export function parseRange(input: DateRangeInput, dateEnv: DateEnv): OpenDateRan
   return { start, end }
 }
 
-// SIDE-EFFECT: will mutate eventRanges.
+// SIDE-EFFECT: will mutate ranges.
 // Will return a new array result.
 export function invertRanges(ranges: DateRange[], constraintRange: DateRange): DateRange[] {
   let invertedRanges: DateRange[] = []

+ 4 - 11
src/reducers/main.ts

@@ -1,7 +1,6 @@
 import Calendar from '../Calendar'
 import { DateComponentRenderState } from '../component/DateComponent'
 import { EventSourceHash } from '../structs/event-source'
-import { DateMarker } from '../datelib/marker'
 import { assignTo } from '../util/object'
 import { reduceEventSourceHash } from './event-sources'
 import { reduceEventStore } from './event-store'
@@ -9,7 +8,6 @@ import { reduceEventStore } from './event-store'
 export interface CalendarState extends DateComponentRenderState {
   loadingLevel: number
   eventSources: EventSourceHash
-  currentDate: DateMarker
 }
 
 export function reduce(state: CalendarState, action: any, calendar: Calendar): CalendarState {
@@ -18,7 +16,6 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
     eventSources: reduceEventSourceHash(state.eventSources, action, calendar),
     eventStore: reduceEventStore(state.eventStore, action, calendar),
     dateProfile: state.dateProfile,
-    currentDate: state.currentDate,
     selection: state.selection,
     dragState: state.dragState,
     eventResizeState: state.eventResizeState,
@@ -36,9 +33,7 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
         calendar.view = view
         calendar.dispatch({
           type: 'SET_DATE_PROFILE',
-          dateProfile: view.computeDateProfile(
-            action.dateMarker || state.currentDate
-          )
+          dateProfile: view.computeDateProfile(action.dateMarker)
         })
       }
       break
@@ -46,8 +41,6 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
     case 'SET_DATE_PROFILE':
       if (action.dateProfile.isValid) {
         newState.dateProfile = action.dateProfile
-        // why not just always use action.dateProfile.date ???
-        newState.currentDate = action.dateProfile.date // might have been constrained by view dates
         calendar.view.updateMiscDateProps(action.dateProfile)
       }
       break
@@ -77,7 +70,7 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
         dateProfile: calendar.view.computeDateProfile(
-          calendar.dateEnv.addYears(newState.currentDate, -1)
+          calendar.dateEnv.addYears(newState.dateProfile.date, -1)
         )
       })
       break
@@ -86,7 +79,7 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
         dateProfile: calendar.view.computeDateProfile(
-          calendar.dateEnv.addYears(newState.currentDate, 1)
+          calendar.dateEnv.addYears(newState.dateProfile.date, 1)
         )
       })
       break
@@ -102,7 +95,7 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
         dateProfile: calendar.view.computeDateProfile(
-          calendar.dateEnv.add(newState.currentDate, action.delta)
+          calendar.dateEnv.add(newState.dateProfile.date, action.delta)
         )
       })
       break