瀏覽代碼

switch meaning of view/renderedView

Adam Shaw 7 年之前
父節點
當前提交
fe731fd2f4
共有 2 個文件被更改,包括 51 次插入54 次删除
  1. 39 42
      src/Calendar.ts
  2. 12 12
      src/reducers/main.ts

+ 39 - 42
src/Calendar.ts

@@ -67,8 +67,8 @@ export default class Calendar {
   isSkeletonRendered: boolean = false
 
   viewsByType: { [viewName: string]: View } // holds all instantiated view instances, current or not
-  view: View // currently rendered View object
-  latestView: View // most up-to-date view, but not necessarily rendered yet. the reducer works with this one
+  view: View // the latest view, internal state, regardless of whether rendered or not
+  renderedView: View // the view that is currently RENDERED, though it might not be most recent from internal state
   header: Toolbar
   footer: Toolbar
 
@@ -156,11 +156,11 @@ export default class Calendar {
 
 
   _destroy() {
-    this.latestView = null
+    this.view = null
 
-    if (this.view) {
-      this.view.removeElement()
-      this.view = null
+    if (this.renderedView) {
+      this.renderedView.removeElement()
+      this.renderedView = null
     }
 
     if (this.header) {
@@ -247,7 +247,7 @@ export default class Calendar {
       let viewType = gotoOptions.type
 
       // property like "navLinkDayClick". might be a string or a function
-      let customAction = this.view.opt('navLink' + capitaliseFirstLetter(viewType) + 'Click')
+      let customAction = this.renderedView.opt('navLink' + capitaliseFirstLetter(viewType) + 'Click')
 
       if (typeof customAction === 'function') {
         customAction(date, ev)
@@ -483,38 +483,38 @@ export default class Calendar {
 
 
   renderView(forces: RenderForceFlags) {
-    let { state, view } = this
+    let { state, renderedView } = this
 
-    if (view !== this.latestView) {
-      if (view) {
-        view.removeElement()
+    if (renderedView !== this.view) {
+      if (renderedView) {
+        renderedView.removeElement()
       }
-      view = this.view = this.latestView
+      renderedView = this.renderedView = this.view
     }
 
-    if (!view.el) {
-      view.setElement(
-        createElement('div', { className: 'fc-view fc-' + view.type + '-view' })
+    if (!renderedView.el) {
+      renderedView.setElement(
+        createElement('div', { className: 'fc-view fc-' + renderedView.type + '-view' })
       )
     }
 
-    if (!view.el.parentNode) {
-      this.contentEl.appendChild(view.el)
+    if (!renderedView.el.parentNode) {
+      this.contentEl.appendChild(renderedView.el)
     } else {
-      view.addScroll(view.queryScroll())
+      renderedView.addScroll(renderedView.queryScroll())
     }
 
-    view.render({
+    renderedView.render({
       dateProfile: state.dateProfile,
       eventStore: state.eventStore,
       selection: state.selection,
       dragState: state.dragState,
       eventResizeState: state.eventResizeState,
-      businessHoursDef: view.opt('businessHours')
+      businessHoursDef: renderedView.opt('businessHours')
     }, forces)
 
     if (this.updateViewSize()) { // success? // TODO: respect isSizeDirty
-      view.popScroll()
+      renderedView.popScroll()
     }
   }
 
@@ -686,19 +686,19 @@ export default class Calendar {
 
 
   updateViewSize(isResize: boolean = false) {
-    let view = this.view
+    let { renderedView } = this
     let scroll
 
-    if (!this.ignoreUpdateViewSize && view) {
+    if (!this.ignoreUpdateViewSize && renderedView) {
 
       if (isResize) {
         this.calcSize()
-        scroll = view.queryScroll()
+        scroll = renderedView.queryScroll()
       }
 
       this.ignoreUpdateViewSize++
 
-      view.updateSize(
+      renderedView.updateSize(
         this.getSuggestedViewHeight(),
         this.isHeightAuto(),
         isResize
@@ -707,7 +707,7 @@ export default class Calendar {
       this.ignoreUpdateViewSize--
 
       if (isResize) {
-        view.applyScroll(scroll)
+        renderedView.applyScroll(scroll)
       }
 
       return true // signal success
@@ -750,11 +750,11 @@ export default class Calendar {
       // the purpose: so we don't process jqui "resize" events that have bubbled up
       // cast to any because .target, which is Element, can't be compared to window for some reason.
       (ev as any).target === window &&
-      this.view &&
-      this.view.isDatesRendered
+      this.renderedView &&
+      this.renderedView.isDatesRendered
     ) {
       if (this.updateViewSize(true)) { // isResize=true, returns true on success
-        this.publiclyTrigger('windowResize', [ this.view ])
+        this.publiclyTrigger('windowResize', [ this.renderedView ])
       }
     }
   }
@@ -791,7 +791,7 @@ export default class Calendar {
     let footerLayout = this.opt('footer')
     let now = this.getNow()
     let dateProfile = this.state.dateProfile
-    let view = this.latestView
+    let view = this.view // use the view that intends to be rendered
     let todayInfo = view.dateProfileGenerator.build(now)
     let prevInfo = view.dateProfileGenerator.buildPrev(dateProfile)
     let nextInfo = view.dateProfileGenerator.buildNext(dateProfile)
@@ -874,16 +874,13 @@ export default class Calendar {
 
     let selection = parseSelection(selectionInput, this.dateEnv)
 
-    if (selection) {
-      this.view.select(selection)
-    }
+    // TODO: use dispatch
+    console.log(selection)
   }
 
 
   unselect() { // safe to be called before renderView
-    if (this.view) {
-      this.view.unselect()
-    }
+    // TODO: use dispatch
   }
 
 
@@ -892,22 +889,22 @@ export default class Calendar {
 
 
   handlExternalDragStart(ev, el, skipBinding) {
-    if (this.view) {
-      this.view.handlExternalDragStart(ev, el, skipBinding)
+    if (this.renderedView) {
+      this.renderedView.handlExternalDragStart(ev, el, skipBinding)
     }
   }
 
 
   handleExternalDragMove(ev) {
-    if (this.view) {
-      this.view.handleExternalDragMove(ev)
+    if (this.renderedView) {
+      this.renderedView.handleExternalDragMove(ev)
     }
   }
 
 
   handleExternalDragStop(ev) {
-    if (this.view) {
-      this.view.handleExternalDragStop(ev)
+    if (this.renderedView) {
+      this.renderedView.handleExternalDragStop(ev)
     }
   }
 

+ 12 - 12
src/reducers/main.ts

@@ -26,12 +26,12 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
   switch(action.type) {
 
     case 'SET_VIEW_TYPE':
-      if (!calendar.latestView || calendar.latestView.type !== action.viewType) {
-        let latestView = calendar.getViewByType(action.viewType)
-        calendar.latestView = latestView
+      if (!calendar.view || calendar.view.type !== action.viewType) {
+        let view = calendar.getViewByType(action.viewType)
+        calendar.view = view
         calendar.dispatch({
           type: 'SET_DATE_PROFILE',
-          dateProfile: latestView.computeDateProfile(
+          dateProfile: view.computeDateProfile(
             action.dateMarker || state.currentDate
           )
         })
@@ -42,35 +42,35 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
       if (action.dateProfile.isValid) {
         newState.dateProfile = action.dateProfile
         newState.currentDate = action.dateProfile.date // might have been constrained by view dates
-        calendar.latestView.updateMiscDateProps(action.dateProfile)
+        calendar.view.updateMiscDateProps(action.dateProfile)
       }
       break
 
     case 'NAVIGATE_PREV':
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
-        dateProfile: calendar.latestView.dateProfileGenerator.buildPrev(newState.dateProfile)
+        dateProfile: calendar.view.dateProfileGenerator.buildPrev(newState.dateProfile)
       })
       break
 
     case 'NAVIGATE_NEXT':
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
-        dateProfile: calendar.latestView.dateProfileGenerator.buildNext(newState.dateProfile)
+        dateProfile: calendar.view.dateProfileGenerator.buildNext(newState.dateProfile)
       })
       break
 
     case 'NAVIGATE_TODAY':
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
-        dateProfile: calendar.latestView.computeDateProfile(calendar.getNow())
+        dateProfile: calendar.view.computeDateProfile(calendar.getNow())
       })
       break
 
     case 'NAVIGATE_PREV_YEAR':
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
-        dateProfile: calendar.latestView.computeDateProfile(
+        dateProfile: calendar.view.computeDateProfile(
           calendar.dateEnv.addYears(newState.currentDate, -1)
         )
       })
@@ -79,7 +79,7 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
     case 'NAVIGATE_NEXT_YEAR':
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
-        dateProfile: calendar.latestView.computeDateProfile(
+        dateProfile: calendar.view.computeDateProfile(
           calendar.dateEnv.addYears(newState.currentDate, 1)
         )
       })
@@ -88,14 +88,14 @@ export function reduce(state: CalendarState, action: any, calendar: Calendar): C
     case 'NAVIGATE_DATE':
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
-        dateProfile: calendar.latestView.computeDateProfile(action.dateMarker)
+        dateProfile: calendar.view.computeDateProfile(action.dateMarker)
       })
       break
 
     case 'NAVIGATE_DELTA':
       calendar.dispatch({
         type: 'SET_DATE_PROFILE',
-        dateProfile: calendar.latestView.computeDateProfile(
+        dateProfile: calendar.view.computeDateProfile(
           calendar.dateEnv.add(newState.currentDate, action.delta)
         )
       })