import { Component , ComponentChildren } from '../vdom' ; import { CalendarDataManager } from '../reducers/CalendarDataManager' ; import { CalendarApi } from '../CalendarApi' ; import { CalendarData } from '../reducers/data-types' ; export interface CalendarDataProviderProps { optionOverrides : any ; calendarApi : CalendarApi ; children ? : ( data : CalendarData ) => ComponentChildren ; } export class CalendarDataProvider extends Component < CalendarDataProviderProps , CalendarData > { dataManager : CalendarDataManager ; constructor ( props ) { super ( props ) ; this . dataManager = new CalendarDataManager ( { optionOverrides : props . optionOverrides , calendarApi : props . calendarApi , onData : this . handleData , } ) ; } handleData = ( data ) => { if ( ! this . dataManager ) { this . state = data ; } else { this . setState ( data ) ; } } ; render ( ) { return this . props . children ( this . state ) ; } componentDidUpdate ( prevProps ) { let newOptionOverrides = this . props . optionOverrides ; if ( newOptionOverrides !== prevProps . optionOverrides ) { this . dataManager . resetOptions ( newOptionOverrides ) ; } } }