Ver Fonte

add a bunch of types

Adam Shaw há 7 anos atrás
pai
commit
77cc9e490c

+ 18 - 3
src/DateProfileGenerator.ts

@@ -3,6 +3,21 @@ import { computeGreatestUnit, computeDurationGreatestUnit } from './util/date'
 import UnzonedRange from './models/UnzonedRange'
 
 
+export interface DateProfile {
+  validUnzonedRange: UnzonedRange
+  currentUnzonedRange: UnzonedRange
+  currentRangeUnit: string
+  isRangeAllDay: boolean
+  activeUnzonedRange: UnzonedRange
+  renderUnzonedRange: UnzonedRange
+  minTime: moment.Duration
+  maxTime: moment.Duration
+  isValid: boolean
+  date: moment.Moment
+  dateIncrement: moment.Duration
+}
+
+
 export default class DateProfileGenerator {
 
   _view: any // discourage
@@ -33,7 +48,7 @@ export default class DateProfileGenerator {
 
 
   // Builds a structure with info about what the dates/ranges will be for the "prev" view.
-  buildPrev(currentDateProfile) {
+  buildPrev(currentDateProfile): DateProfile {
     let prevDate = currentDateProfile.date.clone()
       .startOf(currentDateProfile.currentRangeUnit)
       .subtract(currentDateProfile.dateIncrement)
@@ -43,7 +58,7 @@ export default class DateProfileGenerator {
 
 
   // Builds a structure with info about what the dates/ranges will be for the "next" view.
-  buildNext(currentDateProfile) {
+  buildNext(currentDateProfile): DateProfile {
     let nextDate = currentDateProfile.date.clone()
       .startOf(currentDateProfile.currentRangeUnit)
       .add(currentDateProfile.dateIncrement)
@@ -55,7 +70,7 @@ export default class DateProfileGenerator {
   // Builds a structure holding dates/ranges for rendering around the given date.
   // Optional direction param indicates whether the date is being incremented/decremented
   // from its previous value. decremented = -1, incremented = 1 (default).
-  build(date, direction, forceToValid= false) {
+  build(date, direction?, forceToValid = false): DateProfile {
     let isDateAllDay = !date.hasTime()
     let validUnzonedRange
     let minTime = null

+ 2 - 2
src/View.ts

@@ -45,7 +45,7 @@ export default abstract class View extends InteractiveDateComponent {
   nowIndicatorIntervalID: any // "
 
   dateProfileGeneratorClass: any // initialized after class
-  dateProfileGenerator: any
+  dateProfileGenerator: DateProfileGenerator
 
   // whether minTime/maxTime will affect the activeUnzonedRange. Views must opt-in.
   // initialized after class
@@ -202,7 +202,7 @@ export default abstract class View extends InteractiveDateComponent {
   // -----------------------------------------------------------------------------------------------------------------
 
 
-  setDate(date) {
+  setDate(date: moment.Moment) {
     let currentDateProfile = this.get('dateProfile')
     let newDateProfile = this.dateProfileGenerator.build(date, undefined, true) // forceToValid=true
 

+ 4 - 3
src/component/DateComponent.ts

@@ -6,6 +6,7 @@ import { formatRange } from '../date-formatting'
 import Component from './Component'
 import { eventRangeToEventFootprint } from '../models/event/util'
 import EventFootprint from '../models/event/EventFootprint'
+import { DateProfile } from '../DateProfileGenerator'
 
 
 export default abstract class DateComponent extends Component {
@@ -666,7 +667,7 @@ export default abstract class DateComponent extends Component {
   }
 
 
-  _getDateProfile() {
+  _getDateProfile(): DateProfile {
     return this._getView().get('dateProfile')
   }
 
@@ -760,7 +761,7 @@ export default abstract class DateComponent extends Component {
   // Utility for formatting a range. Accepts a range object, formatting string, and optional separator.
   // Displays all-day ranges naturally, with an inclusive end. Takes the current isRTL into account.
   // The timezones of the dates within `range` will be respected.
-  formatRange(range, isAllDay, formatStr, separator) {
+  formatRange(range: { start: moment.Moment, end: moment.Moment }, isAllDay, formatStr, separator) {
     let end = range.end
 
     if (isAllDay) {
@@ -780,7 +781,7 @@ export default abstract class DateComponent extends Component {
 
   // Returns the date range of the full days the given range visually appears to occupy.
   // Returns a plain object with start/end, NOT an UnzonedRange!
-  computeDayRange(unzonedRange) {
+  computeDayRange(unzonedRange): { start: moment.Moment, end: moment.Moment } {
     let calendar = this._getCalendar()
     let startDay = calendar.msToUtcMoment(unzonedRange.startMs, true) // the beginning of the day the range starts
     let end = calendar.msToUtcMoment(unzonedRange.endMs)

+ 2 - 1
src/date-formatting.ts

@@ -1,3 +1,4 @@
+import { Moment } from 'moment'
 import {
   default as momentExt,
   newMomentProto,
@@ -127,7 +128,7 @@ Using a formatting string meant for a single date, generate a range string, like
 If the dates are the same as far as the format string is concerned, just return a single
 rendering of one date, without any separator.
 */
-export function formatRange(date1, date2, formatStr, separator, isRTL) {
+export function formatRange(date1: Moment, date2: Moment, formatStr, separator, isRTL) {
   let localeData
 
   date1 = momentExt.parseZone(date1)

+ 3 - 2
src/models/event/EventDateProfile.ts

@@ -1,3 +1,4 @@
+import { Moment } from 'moment'
 import UnzonedRange from '../UnzonedRange'
 
 /*
@@ -5,8 +6,8 @@ Meant to be immutable
 */
 export default class EventDateProfile {
 
-  start: any
-  end: any
+  start: Moment
+  end: Moment
   unzonedRange: any
 
 

+ 6 - 3
src/models/event/EventRange.ts

@@ -1,9 +1,12 @@
+import UnzonedRange from '../../models/UnzonedRange'
+import EventDef from '../../models/event/EventDef'
+import EventInstance from '../../models/event/EventInstance'
 
 export default class EventRange {
 
-  unzonedRange: any
-  eventDef: any
-  eventInstance: any // optional
+  unzonedRange: UnzonedRange
+  eventDef: EventDef
+  eventInstance: EventInstance // optional
 
 
   constructor(unzonedRange, eventDef, eventInstance?) {