From 9a1b7d70ebe074d808014ed62e1f8156b681dc58 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Fri, 27 Jan 2023 01:09:52 -0500 Subject: [PATCH] better way of doing resetOptions --- lib/src/full-calendar.component.ts | 19 +++++++------------ lib/src/utils/obj.ts | 12 ------------ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/lib/src/full-calendar.component.ts b/lib/src/full-calendar.component.ts index bba9e5f..187a6d0 100644 --- a/lib/src/full-calendar.component.ts +++ b/lib/src/full-calendar.component.ts @@ -15,7 +15,7 @@ import { Calendar, CalendarOptions } from '@fullcalendar/core'; import { CustomRendering, CustomRenderingStore } from '@fullcalendar/core/internal'; import { OPTION_INPUT_NAMES, OPTION_IS_DEEP } from './options'; import { CalendarOption, CalendarTemplateRef } from './private-types'; -import { deepCopy, shallowCopy, mapHash } from './utils/obj'; +import { deepCopy, mapHash } from './utils/obj'; import { deepEqual } from './utils/fast-deep-equal'; @Component({ @@ -110,7 +110,7 @@ export class FullCalendarComponent implements AfterViewInit, DoCheck, AfterConte ...this.buildInputOptions(), }; const newProcessedOptions: Record = {}; - let anyChanges = false; + const changedOptionNames: string[] = [] // detect adds and updates (and update snapshot) for (const optionName in newOptions) { @@ -120,17 +120,12 @@ export class FullCalendarComponent implements AfterViewInit, DoCheck, AfterConte if (deepChangeDetection && OPTION_IS_DEEP[optionName]) { if (!deepEqual(optionSnapshot[optionName], optionVal)) { optionSnapshot[optionName] = deepCopy(optionVal); - anyChanges = true; - - // trick FC into knowing about a nested change. - // TODO: future versions won't need this. - // can't use the previously-made deep copy because it blows away prototype-association. - optionVal = shallowCopy(optionVal); + changedOptionNames.push(optionName); } } else { if (optionSnapshot[optionName] !== optionVal) { optionSnapshot[optionName] = optionVal; - anyChanges = true; + changedOptionNames.push(optionName); } } @@ -144,16 +139,16 @@ export class FullCalendarComponent implements AfterViewInit, DoCheck, AfterConte for (const optionName of oldOptionNames) { if (!(optionName in newOptions)) { // doesn't exist in new options? delete optionSnapshot[optionName]; - anyChanges = true; + changedOptionNames.push(optionName); } } - if (anyChanges) { + if (changedOptionNames.length) { this.calendar.pauseRendering(); this.calendar.resetOptions({ ...newProcessedOptions, ...this.buildExtraOptions(), - }); + }, changedOptionNames); } } } diff --git a/lib/src/utils/obj.ts b/lib/src/utils/obj.ts index 58f758e..ee8e286 100644 --- a/lib/src/utils/obj.ts +++ b/lib/src/utils/obj.ts @@ -22,18 +22,6 @@ export function deepCopy(input: any): any { } -export function shallowCopy(val: any): any { - if (typeof val === 'object') { - if (Array.isArray(val)) { - val = Array.prototype.slice.call(val); - } else if (val) { // non-null - val = { ...val }; - } - } - return val; -} - - export function mapHash(input: any, func: any): any { const output: { [key: string]: any } = {};