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

change how eventui is passed around during validation

Adam Shaw 7 лет назад
Родитель
Сommit
d5fb1c1293

+ 1 - 9
src/Calendar.ts

@@ -30,7 +30,6 @@ import EventDragging from './interactions/EventDragging'
 import { buildViewSpecs, ViewSpecHash, ViewSpec } from './structs/view-spec'
 import { PluginSystem, PluginDef } from './plugin-system'
 import CalendarComponent from './CalendarComponent'
-import { compileEventUis } from './component/event-rendering'
 
 
 export interface DateClickApi extends DatePointApi {
@@ -69,9 +68,7 @@ export default class Calendar {
   private buildEventUiBySource = memoizeOutput(buildEventUiBySource, isPropsEqual)
   private buildEventUiBases = memoize(buildEventUiBases)
 
-  // strictly for constraint system
-  eventUiBases: EventUiHash
-  renderableEventUis: EventUiHash
+  eventUiBases: EventUiHash // solely for validation system
 
   optionsManager: OptionsManager
   viewSpecs: ViewSpecHash
@@ -411,11 +408,6 @@ export default class Calendar {
     let eventUiBySource = this.buildEventUiBySource(state.eventSources)
     let eventUiBases = this.eventUiBases = this.buildEventUiBases(renderableEventStore.defs, eventUiSingleBase, eventUiBySource)
 
-    this.renderableEventUis = compileEventUis(
-      renderableEventStore.defs,
-      eventUiBases
-    )
-
     if (needsFull || !component) {
 
       if (component) {

+ 1 - 1
src/component/DateComponent.ts

@@ -155,7 +155,7 @@ export default class DateComponent<PropsType> extends Component<PropsType> {
       }
     }
 
-    return isEventsValid(eventStore, calendar.renderableEventUis, calendar)
+    return isEventsValid(eventStore, calendar)
   }
 
   isSelectionValid(selection: DateSpan): boolean {

+ 1 - 6
src/interactions-external/ExternalElementDragging.ts

@@ -13,7 +13,6 @@ import EventApi from '../api/EventApi'
 import { elementMatches } from '../util/dom-manip'
 import { enableCursor, disableCursor } from '../util/misc'
 import { isEventsValid, isSelectionValid, eventToDateSpan } from '../validation'
-import { compileEventUis } from '../component/event-rendering'
 
 export type DragMetaGenerator = DragMetaInput | ((el: HTMLElement) => DragMetaInput)
 
@@ -74,12 +73,8 @@ export default class ExternalElementDragging {
         // TODO: fix inefficiency of calling eventTupleToStore again, and eventToDateSpan
         if (this.dragMeta.create) {
           let droppableEventStore = eventTupleToStore(droppableEvent)
-          let droppableEventUis = compileEventUis(
-            droppableEventStore.defs,
-            receivingCalendar.eventUiBases
-          )
 
-          isInvalid = !isEventsValid(droppableEventStore, droppableEventUis, receivingCalendar)
+          isInvalid = !isEventsValid(droppableEventStore, receivingCalendar)
 
         } else { // treat non-event-creating drags as selection validation
           isInvalid = !isSelectionValid(eventToDateSpan(droppableEvent.def, droppableEvent.instance), receivingCalendar)

+ 6 - 2
src/validation.ts

@@ -5,6 +5,7 @@ import { EventInstance, EventDef, EventTuple, parseEvent } from './structs/event
 import { rangeContainsRange, rangesIntersect } from './datelib/date-range'
 import EventApi from './api/EventApi'
 import { EventUiHash } from './component/event-ui'
+import { compileEventUis } from './component/event-rendering';
 
 // TODO: rename to "criteria" ?
 export type ConstraintInput = 'businessHours' | string | OpenDateSpanInput | { [timeOrRecurringProp: string]: any }
@@ -20,7 +21,9 @@ interface ValidationEntity {
   allows: Allow[]
 }
 
-export function isEventsValid(eventStore: EventStore, eventUis: EventUiHash, calendar: Calendar): boolean {
+export function isEventsValid(eventStore: EventStore, calendar: Calendar): boolean {
+  let eventUis = compileEventUis(eventStore.defs, calendar.eventUiBases)
+
   return isEntitiesValid(
     eventStoreToEntities(eventStore, eventUis),
     calendar
@@ -57,7 +60,8 @@ function isEntitiesValid(entities: ValidationEntity[], calendar: Calendar): bool
   }
 
   // is this efficient?
-  let eventEntities = eventStoreToEntities(calendar.state.eventStore, calendar.renderableEventUis)
+  let eventUis = compileEventUis(calendar.renderableEventStore.defs, calendar.eventUiBases)
+  let eventEntities = eventStoreToEntities(calendar.state.eventStore, eventUis)
 
   for (let subjectEntity of entities) {
     for (let eventEntity of eventEntities) {