src/CalendarDays.js
function updateDays(state, forceCreation) {
  const { dayCount, dayRole, locale, showCompleteWeeks, startDate } = state;
  const workingStartDate = showCompleteWeeks ?
    calendar.firstDateOfWeek(startDate, locale) :
    calendar.midnightOnDate(startDate);
  let workingDayCount;
  if (showCompleteWeeks) {
    const endDate = calendar.offsetDateByDays(startDate, dayCount - 1);
    const workingEndDate = calendar.lastDateOfWeek(endDate, locale);
    workingDayCount = calendar.daysBetweenDates(workingStartDate, workingEndDate) + 1;
  } else {
    workingDayCount = dayCount;
  }

  let days = state.days ? state.days.slice() : [];

  let date = workingStartDate;
  for (let i = 0; i < workingDayCount; i++) {
    const createNewElement = forceCreation || i >= days.length;
    const day = createNewElement ?
      template.createElement(dayRole) :
      days[i];
    day.date = new Date(date.getTime());
    day.locale = locale;
    day.style.gridColumnStart = '';
    if (createNewElement) {
      days[i] = day;
    }
    date = calendar.offsetDateByDays(date, 1);
  }

  if (workingDayCount < days.length) {
    // Trim days which are no longer needed.
    days = days.slice(0, workingDayCount);
  }

  const firstDay = days[0];
  if (firstDay && !showCompleteWeeks) {
    // Set the grid-column on the first day. This will cause all the subsequent
    // days to line up in the calendar grid.
    const dayOfWeek = calendar.daysSinceFirstDayOfWeek(firstDay.date, state.locale);
    firstDay.style.gridColumnStart = dayOfWeek + 1;
  }

  Object.freeze(days);
  return days;
}
function updateDays(state, forceCreation) {
  const { dayCount, dayRole, locale, showCompleteWeeks, startDate } = state;
  const workingStartDate = showCompleteWeeks ?
    calendar.firstDateOfWeek(startDate, locale) :
    calendar.midnightOnDate(startDate);
  let workingDayCount;
  if (showCompleteWeeks) {
    const endDate = calendar.offsetDateByDays(startDate, dayCount - 1);
    const workingEndDate = calendar.lastDateOfWeek(endDate, locale);
    workingDayCount = calendar.daysBetweenDates(workingStartDate, workingEndDate) + 1;
  } else {
    workingDayCount = dayCount;
  }

  let days = state.days ? state.days.slice() : [];

  let date = workingStartDate;
  for (let i = 0; i < workingDayCount; i++) {
    const createNewElement = forceCreation || i >= days.length;
    const day = createNewElement ?
      template.createElement(dayRole) :
      days[i];
    day.date = new Date(date.getTime());
    day.locale = locale;
    day.style.gridColumnStart = '';
    if (createNewElement) {
      days[i] = day;
    }
    date = calendar.offsetDateByDays(date, 1);
  }

  if (workingDayCount < days.length) {
    // Trim days which are no longer needed.
    days = days.slice(0, workingDayCount);
  }

  const firstDay = days[0];
  if (firstDay && !showCompleteWeeks) {
    // Set the grid-column on the first day. This will cause all the subsequent
    // days to line up in the calendar grid.
    const dayOfWeek = calendar.daysSinceFirstDayOfWeek(firstDay.date, state.locale);
    firstDay.style.gridColumnStart = dayOfWeek + 1;
  }

  Object.freeze(days);
  return days;
}
function updateDays ( state , forceCreation ) { const { dayCount , dayRole , locale , showCompleteWeeks , startDate } = state ; const workingStartDate = showCompleteWeeks ? calendar . firstDateOfWeek ( startDate , locale ) : calendar . midnightOnDate ( startDate ) ; let workingDayCount ; if ( showCompleteWeeks ) { const endDate = calendar . offsetDateByDays ( startDate , dayCount - 1 ) ; const workingEndDate = calendar . lastDateOfWeek ( endDate , locale ) ; workingDayCount = calendar . daysBetweenDates ( workingStartDate , workingEndDate ) + 1 ; } else { workingDayCount = dayCount ; } let days = state . days ? state . days . slice ( ) : [ ] ; let date = workingStartDate ; for ( let i = 0 ; i < workingDayCount ; i ++ ) { const createNewElement = forceCreation || i >= days . length ; const day = createNewElement ? template . createElement ( dayRole ) : days [ i ] ; day . date = new Date ( date . getTime ( ) ) ; day . locale = locale ; day . style . gridColumnStart = '' ; if ( createNewElement ) { days [ i ] = day ; } date = calendar . offsetDateByDays ( date , 1 ) ; } if ( workingDayCount < days . length ) { // Trim days which are no longer needed. days = days . slice ( 0 , workingDayCount ) ; } const firstDay = days [ 0 ] ; if ( firstDay && ! showCompleteWeeks ) { // Set the grid-column on the first day. This will cause all the subsequent // days to line up in the calendar grid. const dayOfWeek = calendar . daysSinceFirstDayOfWeek ( firstDay . date , state . locale ) ; firstDay . style . gridColumnStart = dayOfWeek + 1 ; } Object . freeze ( days ) ; return days ; }
Create days as necessary for the given state. Reuse existing day elements to the degree possible.
Create days as necessary for the given state . Reuse existing day elements to the degree possible .