Adam Shaw 6 лет назад
Родитель
Сommit
56bc8524d4

+ 1 - 1
packages-premium

@@ -1 +1 @@
-Subproject commit 0bf77edf12bd42bfff69b991991884ba31d46fa2
+Subproject commit 271df290cdc23e134735602b12ab1451556197a6

+ 21 - 7
packages/core/src/Calendar.tsx

@@ -82,7 +82,6 @@ export default class Calendar {
   private parseRawLocales = memoize(parseRawLocales)
   private buildDateEnv = memoize(buildDateEnv)
   private computeTitle = memoize(computeTitle)
-  private buildViewApi = memoize(buildViewApi)
   private buildTheme = memoize(buildTheme)
   private buildContext = memoize(buildContext)
   private buildEventUiSingleBase = memoize(buildEventUiSingleBase)
@@ -523,8 +522,8 @@ export default class Calendar {
       throw new Error(`View type "${viewType}" is not valid`)
     }
 
-    let title = this.computeTitle(dateProfile, dateEnv, viewSpec.options)
     let theme = this.buildTheme(rawOptions, pluginHooks)
+    let title = this.computeTitle(dateProfile, dateEnv, viewSpec.options)
     let viewApi = this.buildViewApi(viewType, title, dateProfile, dateEnv)
     let context = this.buildContext(this, pluginHooks, dateEnv, theme, viewApi, rawOptions)
 
@@ -533,6 +532,26 @@ export default class Calendar {
   }
 
 
+  /*
+  will only create a new instance when viewType is changed
+  */
+  buildViewApi(viewType: string, title: string, dateProfile: DateProfile, dateEnv: DateEnv) {
+    let { view } = this
+
+    if (!view || view.type !== viewType) {
+      view = this.view = { type: viewType } as ViewApi
+    }
+
+    view.title = title
+    view.activeStart = dateEnv.toDate(dateProfile.activeRange.start)
+    view.activeEnd = dateEnv.toDate(dateProfile.activeRange.end)
+    view.currentStart = dateEnv.toDate(dateProfile.currentRange.start)
+    view.currentEnd = dateEnv.toDate(dateProfile.currentRange.end)
+
+    return view
+  }
+
+
   getAvailableLocaleCodes() {
     return Object.keys(this.availableRawLocales)
   }
@@ -1199,11 +1218,6 @@ function buildTheme(rawOptions, pluginHooks: PluginHooks) {
 }
 
 
-function buildViewApi(type: string, title: string, dateProfile: DateProfile, dateEnv: DateEnv) {
-  return new ViewApi(type, title, dateProfile, dateEnv)
-}
-
-
 function buildSelectionConfig(this: Calendar, rawOptions) { // DANGEROUS: `this` context must be a Calendar
   return processScopedUiProps('select', rawOptions, this)
 }

+ 3 - 17
packages/core/src/ViewApi.ts

@@ -1,23 +1,9 @@
-import { DateProfile } from './DateProfileGenerator'
-import { DateEnv } from './datelib/env'
-
-export default class ViewApi {
 
+export default interface ViewApi {
+  type: string
+  title: string
   activeStart: Date
   activeEnd: Date
   currentStart: Date
   currentEnd: Date
-
-  constructor(
-    public type: string,
-    public title: string,
-    dateProfile: DateProfile,
-    dateEnv: DateEnv
-  ) {
-    this.activeStart = dateEnv.toDate(dateProfile.activeRange.start)
-    this.activeEnd = dateEnv.toDate(dateProfile.activeRange.end)
-    this.currentStart = dateEnv.toDate(dateProfile.currentRange.start)
-    this.currentEnd = dateEnv.toDate(dateProfile.currentRange.end)
-  }
-
 }

+ 2 - 2
packages/core/src/view-framework-util.tsx

@@ -29,7 +29,7 @@ export abstract class BaseComponent<Props={}, State={}> extends Component<Props,
   shouldComponentUpdate(nextProps: Props, nextState: State, nextContext: ComponentContext) {
     return !compareObjs(this.props, nextProps, this.propEquality) ||
       !compareObjs(this.state, nextState, this.stateEquality) ||
-      !compareObjs(this.context, nextContext)
+      this.context !== nextContext
   }
 
   subrenderDestroy: typeof subrenderDestroy
@@ -197,7 +197,7 @@ function buildFuncSubRenderer(renderFunc, unrenderFunc) {
       } else if (
         !compareObjs(props, currentProps) || (
           renderFunc.length > 1 && // has second arg? cares about context?
-          !compareObjs(context, currentContext)
+          context !== currentContext
         )
       ) {
         unrenderFunc && unrenderFunc.call(thisContext, renderRes, context)