2
0
Adam Shaw 5 жил өмнө
parent
commit
de1e6574e5

+ 1 - 1
packages/__tests__/src/lib/ViewDateUtils.js

@@ -1,6 +1,6 @@
 
 
 export function expectRenderRange(start, end) {
 export function expectRenderRange(start, end) {
-  let { dateProfile } = currentCalendar.component.props // not a great way to get this info
+  let { dateProfile } = currentCalendar.getCurrentState() // not a great way to get this info
 
 
   expect(dateProfile.renderRange.start).toEqualDate(start)
   expect(dateProfile.renderRange.start).toEqualDate(start)
   expect(dateProfile.renderRange.end).toEqualDate(end)
   expect(dateProfile.renderRange.end).toEqualDate(end)

+ 12 - 4
packages/core/src/reducers/CalendarStateReducer.ts

@@ -71,8 +71,8 @@ export class CalendarStateReducer {
 
 
         if (Object.keys(updates).length || removals.length) {
         if (Object.keys(updates).length || removals.length) {
           let hash = isDynamic
           let hash = isDynamic
-            ? (dynamicOptionOverrides = { ...dynamicOptionOverrides, updates })
-            : (optionOverrides = { ...optionOverrides, updates })
+            ? (dynamicOptionOverrides = { ...dynamicOptionOverrides, ...updates })
+            : (optionOverrides = { ...optionOverrides, ...updates })
 
 
           for (let removal of removals) {
           for (let removal of removals) {
             delete hash[removal]
             delete hash[removal]
@@ -149,8 +149,16 @@ export class CalendarStateReducer {
     }
     }
 
 
     let currentDate = state.currentDate || getInitialDate(viewOptions, dateEnv) // weird how we do INIT
     let currentDate = state.currentDate || getInitialDate(viewOptions, dateEnv) // weird how we do INIT
+
+    let prevDateProfileGenerator = state.dateProfileGenerator
     let dateProfileGenerator = this.buildDateProfileGenerator(viewSpec, viewOptions, dateEnv)
     let dateProfileGenerator = this.buildDateProfileGenerator(viewSpec, viewOptions, dateEnv)
-    let dateProfile = reduceDateProfile(state.dateProfile, action, currentDate, dateProfileGenerator)
+    let dateProfile = state.dateProfile
+
+    if (prevDateProfileGenerator !== dateProfileGenerator) { // weird. happens for INIT as well
+      dateProfile = dateProfileGenerator.build(currentDate, undefined, true) // forceToValid=true
+    }
+
+    dateProfile = reduceDateProfile(dateProfile, action, currentDate, dateProfileGenerator)
     currentDate = reduceCurrentDate(currentDate, action, dateProfile)
     currentDate = reduceCurrentDate(currentDate, action, dateProfile)
 
 
     let eventSources = reduceEventSources(state.eventSources, action, dateProfile, reducerContext)
     let eventSources = reduceEventSources(state.eventSources, action, dateProfile, reducerContext)
@@ -262,7 +270,7 @@ function buildTheme(rawOptions, pluginHooks: PluginHooks) {
 }
 }
 
 
 
 
-function buildDateProfileGenerator(viewSpec: ViewSpec, viewOptions: any, dateEnv: DateEnv) {
+function buildDateProfileGenerator(viewSpec: ViewSpec, viewOptions: any, dateEnv: DateEnv): DateProfileGenerator {
   let DateProfileGeneratorClass = viewSpec.optionDefaults.dateProfileGeneratorClass || DateProfileGenerator
   let DateProfileGeneratorClass = viewSpec.optionDefaults.dateProfileGeneratorClass || DateProfileGenerator
 
 
   return new DateProfileGeneratorClass(viewSpec, viewOptions, dateEnv)
   return new DateProfileGeneratorClass(viewSpec, viewOptions, dateEnv)

+ 2 - 8
packages/core/src/reducers/date-profile.ts

@@ -7,15 +7,9 @@ import { rangeContainsMarker } from '../datelib/date-range'
 export function reduceDateProfile(currentDateProfile: DateProfile | null, action: Action, currentDate: DateMarker, dateProfileGenerator: DateProfileGenerator): DateProfile {
 export function reduceDateProfile(currentDateProfile: DateProfile | null, action: Action, currentDate: DateMarker, dateProfileGenerator: DateProfileGenerator): DateProfile {
   let newDateProfile: DateProfile
   let newDateProfile: DateProfile
 
 
-  switch (action.type) {
-    case 'INIT':
-      newDateProfile = dateProfileGenerator.build(
-        currentDate,
-        undefined,
-        true // forceToValid
-      )
-      break
+  // the "INIT" will happen in CalendarStateReducer
 
 
+  switch (action.type) {
     case 'CHANGE_DATE':
     case 'CHANGE_DATE':
     case 'CHANGE_VIEW_TYPE':
     case 'CHANGE_VIEW_TYPE':
       if (
       if (