Merge pull request #23 from moonship-fe/main

fix: optimization calendar render performance
This commit is contained in:
MaTeMaTuK 2021-10-23 14:38:22 +03:00 committed by GitHub
commit 60f586a9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import React, { ReactChild } from "react";
import { ViewMode } from "../../types/public-types"; import { ViewMode } from "../../types/public-types";
import { TopPartOfCalendar } from "./top-part-of-calendar"; import { TopPartOfCalendar } from "./top-part-of-calendar";
import { import {
getCachedDateTimeFormat,
getDaysInMonth, getDaysInMonth,
getLocaleMonth, getLocaleMonth,
getWeekNumberISO8601, getWeekNumberISO8601,
@ -177,7 +178,7 @@ export const Calendar: React.FC<CalendarProps> = ({
const dates = dateSetup.dates; const dates = dateSetup.dates;
for (let i = 0; i < dates.length; i++) { for (let i = 0; i < dates.length; i++) {
const date = dates[i]; const date = dates[i];
const bottomValue = Intl.DateTimeFormat(locale, { const bottomValue = getCachedDateTimeFormat(locale, {
hour: "numeric", hour: "numeric",
}).format(date); }).format(date);

View File

@ -12,7 +12,7 @@ type DateHelperScales =
| "millisecond"; | "millisecond";
const intlDTCache = {}; const intlDTCache = {};
const getCachedDateTimeFormat = ( export const getCachedDateTimeFormat = (
locString: string | string[], locString: string | string[],
opts: DateTimeFormatOptions = {} opts: DateTimeFormatOptions = {}
): DateTimeFormat => { ): DateTimeFormat => {
@ -25,6 +25,7 @@ const getCachedDateTimeFormat = (
return dtf; return dtf;
}; };
export const addToDate = ( export const addToDate = (
date: Date, date: Date,
quantity: number, quantity: number,
@ -189,3 +190,4 @@ export const getWeekNumberISO8601 = (date: Date) => {
export const getDaysInMonth = (month: number, year: number) => { export const getDaysInMonth = (month: number, year: number) => {
return new Date(year, month + 1, 0).getDate(); return new Date(year, month + 1, 0).getDate();
}; };