Parcourir la source

convert Object.assign to spread operator as much as possible

Adam Shaw il y a 7 ans
Parent
commit
e136cb9280

+ 1 - 1
src/Calendar.ts

@@ -569,7 +569,7 @@ export default class Calendar {
 
   _buildEventUiSingleBase(rawOpts) {
     if (rawOpts.editable) { // so 'editable' affected events
-      rawOpts = Object.assign({}, rawOpts, { eventEditable: true })
+      rawOpts = { ...rawOpts, eventEditable: true }
     }
     return processScopedUiProps('event', rawOpts, this)
   }

+ 12 - 14
src/agenda/AgendaView.ts

@@ -71,22 +71,20 @@ export default class AgendaView extends AbstractAgendaView {
       })
     }
 
-    this.simpleTimeGrid.receiveProps(
-      Object.assign({}, splitProps['timed'], {
-        dateProfile,
-        dayTable
-      })
-    )
+    this.simpleTimeGrid.receiveProps({
+      ...splitProps['timed'],
+      dateProfile,
+      dayTable
+    })
 
     if (this.simpleDayGrid) {
-      this.simpleDayGrid.receiveProps(
-        Object.assign({}, splitProps['allDay'], {
-          dateProfile,
-          dayTable,
-          nextDayThreshold: this.nextDayThreshold,
-          isRigid: false
-        })
-      )
+      this.simpleDayGrid.receiveProps({
+        ...splitProps['allDay'],
+        dateProfile,
+        dayTable,
+        nextDayThreshold: this.nextDayThreshold,
+        isRigid: false
+      })
     }
   }
 

+ 5 - 6
src/agenda/SimpleTimeGrid.ts

@@ -45,12 +45,11 @@ export default class SimpleTimeGrid extends DateComponent<SimpleTimeGridProps> {
     let { dateProfile, dayTable } = props
     let dayRanges = this.dayRanges = this.buildDayRanges(dayTable, dateProfile, this.dateEnv)
 
-    this.timeGrid.receiveProps(
-      Object.assign({}, this.slicer.sliceProps(props, dateProfile, null, this.timeGrid, dayRanges), {
-        dateProfile,
-        cells: dayTable.cells[0]
-      })
-    )
+    this.timeGrid.receiveProps({
+      ...this.slicer.sliceProps(props, dateProfile, null, this.timeGrid, dayRanges),
+      dateProfile,
+      cells: dayTable.cells[0]
+    })
   }
 
   renderNowIndicator(date: DateMarker) {

+ 6 - 7
src/basic/SimpleDayGrid.ts

@@ -43,13 +43,12 @@ export default class SimpleDayGrid extends DateComponent<SimpleDayGridProps> {
     let { dayGrid } = this
     let { dateProfile, dayTable } = props
 
-    dayGrid.receiveProps(
-      Object.assign({}, this.slicer.sliceProps(props, dateProfile, props.nextDayThreshold, dayGrid, dayTable), {
-        dateProfile,
-        cells: dayTable.cells,
-        isRigid: props.isRigid
-      })
-    )
+    dayGrid.receiveProps({
+      ...this.slicer.sliceProps(props, dateProfile, props.nextDayThreshold, dayGrid, dayTable),
+      dateProfile,
+      cells: dayTable.cells,
+      isRigid: props.isRigid
+    })
   }
 
   prepareHits() {

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

@@ -204,7 +204,7 @@ export default class ExternalElementDragging {
 export type ExternalDefTransform = (dateSpan: DateSpan, dragMeta: DragMeta) => any
 
 function computeEventForDateSpan(dateSpan: DateSpan, dragMeta: DragMeta, calendar: Calendar): EventTuple {
-  let defProps = Object.assign({}, dragMeta.leftoverProps)
+  let defProps = { ...dragMeta.leftoverProps }
 
   for (let transform of calendar.pluginSystem.hooks.externalDefTransforms) {
     Object.assign(defProps, transform(dateSpan, dragMeta))

+ 8 - 0
src/tslib-lite.js

@@ -16,3 +16,11 @@ exports.__extends = function (d, b) {
   function __() { this.constructor = d; }
   d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
 };
+
+exports.__assign = Object.assign || function (t) {
+  for (var s, i = 1, n = arguments.length; i < n; i++) {
+      s = arguments[i];
+      for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
+  }
+  return t;
+};

+ 10 - 9
src/validation.ts

@@ -32,15 +32,16 @@ export function isDateSelectionValid(dateSelection: DateSpan, calendar: Calendar
 function isNewPropsValid(newProps, calendar: Calendar) {
   let view = calendar.view
 
-  let props = Object.assign({}, {
+  let props = {
     businessHours: view ? view.props.businessHours : createEmptyEventStore(), // why? yuck
     dateSelection: '',
     eventStore: calendar.state.eventStore,
     eventUiBases: calendar.eventUiBases,
     eventSelection: '',
     eventDrag: null,
-    eventResize: null
-  }, newProps)
+    eventResize: null,
+    ...newProps
+  }
 
   return (calendar.pluginSystem.hooks.isPropsValid || isPropsValid)(props, calendar)
 }
@@ -130,11 +131,11 @@ function isInteractionPropsValid(state: SplittableProps, calendar: Calendar, dat
       let origDef = state.eventStore.defs[subjectDef.defId]
       let origInstance = state.eventStore.instances[subjectInstanceId]
 
-      let subjectDateSpan: DateSpan = Object.assign(
-        {},
-        dateSpanMeta,
-        { range: subjectInstance.range, allDay: subjectDef.allDay }
-      )
+      let subjectDateSpan: DateSpan = {
+        ...dateSpanMeta,
+        range: subjectInstance.range,
+        allDay: subjectDef.allDay
+      }
 
       if (!subjectAllow(
         calendar.buildDateSpanApi(subjectDateSpan),
@@ -197,7 +198,7 @@ function isDateSelectionPropsValid(state: SplittableProps, calendar: Calendar, d
   // allow (a function)
   for (let selectionAllow of selectionConfig.allows) {
 
-    let fullDateSpan = Object.assign({}, dateSpanMeta, selection)
+    let fullDateSpan = { ...dateSpanMeta, ...selection }
 
     if (!selectionAllow(
       calendar.buildDateSpanApi(fullDateSpan),