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

rerendering. kill rerenderEvents

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

+ 4 - 5
packages/core/src/Calendar.tsx

@@ -36,6 +36,7 @@ import { TaskRunner, DelayedRunner } from './util/runner'
 import ViewApi from './ViewApi'
 import { globalPlugins } from './global-plugins'
 import { removeExact } from './util/array'
+import { guid } from './util/misc'
 
 
 export interface DateClickApi extends DatePointApi {
@@ -177,6 +178,9 @@ export default class Calendar {
       this.renderableEventStore = createEmptyEventStore()
       this.renderRunner.request()
       window.addEventListener('resize', this.handleWindowResize)
+    } else {
+      // hack for RERENDERING
+      this.setOption('renderId', guid())
     }
   }
 
@@ -1141,11 +1145,6 @@ export default class Calendar {
   }
 
 
-  rerenderEvents() { // API method. destroys old events if previously rendered.
-    this.dispatch({ type: 'RESET_EVENTS' })
-  }
-
-
   // Public Event Sources API
   // -----------------------------------------------------------------------------------------------------------------
 

+ 5 - 1
packages/core/src/common/DayHeader.tsx

@@ -20,6 +20,7 @@ export default class DayHeader extends BaseComponent<DayHeaderProps> { // TODO:
 
 
   render(props: DayHeaderProps, state: {}, context: ComponentContext) {
+    let { dateEnv } = this.context
     let { dates, datesRepDistinctDays } = props
     let cells: VNode[] = []
 
@@ -33,11 +34,14 @@ export default class DayHeader extends BaseComponent<DayHeaderProps> { // TODO:
     )
 
     for (let date of dates) {
+      let distinctDateStr = datesRepDistinctDays ? dateEnv.formatIso(date, { omitTime: true }) : ''
+
       cells.push(
         <TableDateCell
+          key={distinctDateStr || date.getDay()}
+          distinctDateStr={distinctDateStr}
           dateMarker={date}
           dateProfile={props.dateProfile}
-          datesRepDistinctDays={datesRepDistinctDays}
           colCnt={dates.length}
           colHeadFormat={colHeadFormat}
         />

+ 6 - 6
packages/core/src/common/TableDateCell.tsx

@@ -11,9 +11,9 @@ import { BaseComponent } from '../vdom-util'
 
 
 export interface TableDateCellProps {
+  distinctDateStr: string
   dateMarker: DateMarker
   dateProfile: DateProfile
-  datesRepDistinctDays: boolean
   colCnt: number
   colHeadFormat: DateFormatter
   colSpan?: number
@@ -24,7 +24,7 @@ export default class TableDateCell extends BaseComponent<TableDateCellProps> {
 
   render(props: TableDateCellProps, state: {}, context: ComponentContext) {
     let { dateEnv, options } = context
-    let { dateMarker, dateProfile, datesRepDistinctDays } = props
+    let { dateMarker, dateProfile, distinctDateStr } = props
     let isDateValid = rangeContainsMarker(dateProfile.activeRange, dateMarker) // TODO: called too frequently. cache somehow.
     let classNames = [ 'fc-day-header' ]
     let innerText
@@ -43,7 +43,7 @@ export default class TableDateCell extends BaseComponent<TableDateCellProps> {
     }
 
     // if only one row of days, the classNames on the header can represent the specific days beneath
-    if (datesRepDistinctDays) {
+    if (distinctDateStr) {
       classNames = classNames.concat(
         // includes the day-of-week class
         // noThemeHighlight=true (don't highlight the header)
@@ -55,8 +55,8 @@ export default class TableDateCell extends BaseComponent<TableDateCellProps> {
 
     let attrs = {} as any
 
-    if (isDateValid && datesRepDistinctDays) {
-      attrs['data-date'] = dateEnv.formatIso(dateMarker, { omitTime: true })
+    if (isDateValid && distinctDateStr) {
+      attrs['data-date'] = distinctDateStr
     }
 
     if (props.colSpan > 1) {
@@ -72,7 +72,7 @@ export default class TableDateCell extends BaseComponent<TableDateCellProps> {
         {isDateValid &&
           <GotoAnchor
             navLinks={options.navLinks}
-            gotoOptions={{ date: dateMarker, forceOff: isDateValid && (!datesRepDistinctDays || props.colCnt === 1) }}
+            gotoOptions={{ date: dateMarker, forceOff: isDateValid && (!distinctDateStr || props.colCnt === 1) }}
             htmlContent={innerHtml}
           >{innerText}</GotoAnchor>
         }

+ 0 - 6
packages/core/src/reducers/eventStore.ts

@@ -79,12 +79,6 @@ export default function(eventStore: EventStore, action: Action, eventSources: Ev
     case 'REMOVE_ALL_EVENTS':
       return createEmptyEventStore()
 
-    case 'RESET_EVENTS':
-      return { // returns a new object with the same contents
-        defs: eventStore.defs,
-        instances: eventStore.instances
-      }
-
     default:
       return eventStore
   }

+ 1 - 2
packages/core/src/reducers/types.ts

@@ -62,5 +62,4 @@ export type Action =
   { type: 'MUTATE_EVENTS', instanceId: string, mutation: EventMutation, fromApi?: boolean } |
   { type: 'REMOVE_EVENT_DEF', defId: string } |
   { type: 'REMOVE_EVENT_INSTANCES', instances: EventInstanceHash } |
-  { type: 'REMOVE_ALL_EVENTS' } |
-  { type: 'RESET_EVENTS' }
+  { type: 'REMOVE_ALL_EVENTS' }