Преглед изворни кода

strip out a bunch of stuff

Adam Shaw пре 7 година
родитељ
комит
ab85918f09

+ 0 - 4
src/Calendar.ts

@@ -5,7 +5,6 @@ import { capitaliseFirstLetter, debounce } from './util/misc'
 import { globalDefaults, rtlDefaults } from './options'
 import GlobalEmitter from './common/GlobalEmitter'
 import { default as EmitterMixin, EmitterInterface } from './common/EmitterMixin'
-import { default as ListenerMixin, ListenerInterface } from './common/ListenerMixin'
 import Toolbar from './Toolbar'
 import OptionsManager from './OptionsManager'
 import ViewSpecManager from './ViewSpecManager'
@@ -43,8 +42,6 @@ export default class Calendar {
   trigger: EmitterInterface['trigger']
   triggerWith: EmitterInterface['triggerWith']
   hasHandlers: EmitterInterface['hasHandlers']
-  listenTo: ListenerInterface['listenTo']
-  stopListeningTo: ListenerInterface['stopListeningTo']
 
   buildDateEnv: any
   buildTheme: any
@@ -1066,7 +1063,6 @@ export default class Calendar {
 
 EmitterMixin.mixIntoObj(Calendar) // for global registry
 EmitterMixin.mixInto(Calendar)
-ListenerMixin.mixInto(Calendar)
 
 
 

+ 0 - 23
src/common/Class.ts

@@ -1,23 +0,0 @@
-import { copyOwnProps } from '../util/object'
-
-
-// Class that all other classes will inherit from
-export default class Class {
-
-  // Called on a class to create a subclass.
-  // LIMITATION: cannot provide a constructor!
-  static extend(members): any {
-    class SubClass extends this {}
-
-    copyOwnProps(members, SubClass.prototype)
-
-    return SubClass
-  }
-
-
-  // Adds new member variables/methods to the class's prototype.
-  // Can be called with another class, or a plain object hash containing new members.
-  static mixin(members) {
-    copyOwnProps(members, this.prototype)
-  }
-}

+ 12 - 16
src/common/GlobalEmitter.ts

@@ -1,6 +1,5 @@
 import * as exportHooks from '../exports'
 import { default as EmitterMixin, EmitterInterface } from './EmitterMixin'
-import { default as ListenerMixin, ListenerInterface } from './ListenerMixin'
 
 (exportHooks as any).touchMouseIgnoreWait = 500
 
@@ -24,8 +23,6 @@ export default class GlobalEmitter {
   trigger: EmitterInterface['trigger']
   triggerWith: EmitterInterface['triggerWith']
   hasHandlers: EmitterInterface['hasHandlers']
-  listenTo: ListenerInterface['listenTo']
-  stopListeningTo: ListenerInterface['stopListeningTo']
 
   isTouching: boolean = false
   mouseIgnoreDepth: number = 0
@@ -62,17 +59,17 @@ export default class GlobalEmitter {
 
 
   bind() {
-    this.listenTo(document, {
-      touchstart: this.handleTouchStart,
-      touchcancel: this.handleTouchCancel,
-      touchend: this.handleTouchEnd,
-      mousedown: this.handleMouseDown,
-      mousemove: this.handleMouseMove,
-      mouseup: this.handleMouseUp,
-      click: this.handleClick,
-      selectstart: this.handleSelectStart,
-      contextmenu: this.handleContextMenu
-    })
+    // this.listenTo(document, {
+    //   touchstart: this.handleTouchStart,
+    //   touchcancel: this.handleTouchCancel,
+    //   touchend: this.handleTouchEnd,
+    //   mousedown: this.handleMouseDown,
+    //   mousemove: this.handleMouseMove,
+    //   mouseup: this.handleMouseUp,
+    //   click: this.handleClick,
+    //   selectstart: this.handleSelectStart,
+    //   contextmenu: this.handleContextMenu
+    // })
 
     // because we need to call preventDefault
     // because https://www.chromestatus.com/features/5093566007214080
@@ -94,7 +91,7 @@ export default class GlobalEmitter {
   }
 
   unbind() {
-    this.stopListeningTo(document)
+    // this.stopListeningTo(document)
 
     window.removeEventListener(
       'touchmove',
@@ -218,5 +215,4 @@ export default class GlobalEmitter {
 
 }
 
-ListenerMixin.mixInto(GlobalEmitter)
 EmitterMixin.mixInto(GlobalEmitter)

+ 0 - 82
src/common/ListenerMixin.ts

@@ -1,82 +0,0 @@
-/*
-Utility methods for easily listening to events on another object,
-and more importantly, easily unlistening from them.
-
-USAGE:
-  import { default as ListenerMixin, ListenerInterface } from './ListenerMixin'
-in class:
-  listenTo: ListenerInterface['listenTo']
-  stopListeningTo: ListenerInterface['stopListeningTo']
-after class:
-  ListenerMixin.mixInto(TheClass)
-*/
-
-import Mixin from './Mixin'
-
-export interface ListenerInterface {
-  listenTo(other, arg, callback?)
-  stopListeningTo(other, eventName?)
-}
-
-export default class ListenerMixin extends Mixin implements ListenerInterface {
-
-  _listeners: any // array of [ otherObject, eventName, callbackFunc ]
-
-  /*
-  Given an `other` object that has on/off or addEventListener/removeEventListener methods, bind the given `callback` to an event by the given name.
-  The `callback` will be called with the `this` context of the object that .listenTo is being called on.
-  Can be called:
-    .listenTo(other, eventName, callback)
-  OR
-    .listenTo(other, {
-      eventName1: callback1,
-      eventName2: callback2
-    })
-  */
-  listenTo(other, arg, callback?) {
-    if (typeof arg === 'object' && arg) { // given dictionary of callbacks (non-null)
-      for (let eventName in arg) {
-        if (arg.hasOwnProperty(eventName)) {
-          this.listenTo(other, eventName, arg[eventName])
-        }
-      }
-    } else if (typeof arg === 'string' && callback) {
-      callback = callback.bind(this) // always use `this` context)
-
-      if (other.addEventListener) {
-        other.addEventListener(arg, callback)
-      } else {
-        other.on(arg, callback)
-      }
-
-      (this._listeners || (this._listeners = []))
-        .push([ other, arg, callback ])
-    }
-  }
-
-  /*
-  Causes the current object to stop listening to events on the `other` object.
-  `eventName` is optional. If omitted, will stop listening to ALL events on `other`.
-  */
-  stopListeningTo(other, eventName?) {
-    if (this._listeners) {
-      this._listeners = this._listeners.filter(function(listener) {
-        if (
-          listener[0] === other &&
-          (!eventName || eventName === listener[1])
-        ) {
-          if (other.removeEventListener) {
-            other.removeEventListener(listener[1], listener[2])
-          } else {
-            other.off(listener[1], listener[2])
-          }
-
-          return false // remove from array
-        } else {
-          return true // keep in array
-        }
-      })
-    }
-  }
-
-}

+ 6 - 12
src/common/MouseFollower.ts

@@ -5,7 +5,6 @@ import {
   whenTransitionDone
 } from '../util/dom-event'
 import { removeElement, applyStyle } from '../util/dom-manip'
-import { default as ListenerMixin, ListenerInterface } from './ListenerMixin'
 
 export interface MouseFollowerOptions {
   parentEl?: HTMLElement
@@ -20,9 +19,6 @@ export interface MouseFollowerOptions {
 
 export default class MouseFollower {
 
-  listenTo: ListenerInterface['listenTo']
-  stopListeningTo: ListenerInterface['stopListeningTo']
-
   options: MouseFollowerOptions
 
   sourceEl: HTMLElement // the element that will be cloned and made to look like it is dragging
@@ -67,11 +63,11 @@ export default class MouseFollower {
         this.updatePosition()
       }
 
-      if (getEvIsTouch(ev)) {
-        this.listenTo(document, 'touchmove', this.handleMove)
-      } else {
-        this.listenTo(document, 'mousemove', this.handleMove)
-      }
+      // if (getEvIsTouch(ev)) {
+      //   this.listenTo(document, 'touchmove', this.handleMove)
+      // } else {
+      //   this.listenTo(document, 'mousemove', this.handleMove)
+      // }
     }
   }
 
@@ -96,7 +92,7 @@ export default class MouseFollower {
     if (this.isFollowing && !this.isAnimating) { // disallow more than one stop animation at a time
       this.isFollowing = false
 
-      this.stopListeningTo(document)
+      // this.stopListeningTo(document)
 
       if (shouldRevert && revertDuration && !this.isHidden) { // do a revert animation?
         this.isAnimating = true
@@ -218,5 +214,3 @@ export default class MouseFollower {
   }
 
 }
-
-ListenerMixin.mixInto(MouseFollower)

+ 0 - 108
src/common/ParsableModelMixin.ts

@@ -1,108 +0,0 @@
-/*
-USAGE:
-  import { default as ParsableModelMixin, ParsableModelInterface } from './ParsableModelMixin'
-in class:
-  applyProps: ParsableModelInterface['applyProps']
-  applyManualStandardProps: ParsableModelInterface['applyManualStandardProps']
-  applyMiscProps: ParsableModelInterface['applyMiscProps']
-  isStandardProp: ParsableModelInterface['isStandardProp']
-  static defineStandardProps = ParsableModelMixin.defineStandardProps
-  static copyVerbatimStandardProps = ParsableModelMixin.copyVerbatimStandardProps
-after class:
-  ParsableModelMixin.mixInto(TheClass)
-*/
-
-import { copyOwnProps } from '../util/object'
-import Mixin from './Mixin'
-
-export interface ParsableModelInterface {
-  applyProps(rawProps)
-  applyManualStandardProps(rawProps)
-  applyMiscProps(rawProps)
-  isStandardProp(propName)
-}
-
-export default class ParsableModelMixin extends Mixin implements ParsableModelInterface {
-
-  standardPropMap: any
-
-
-  static defineStandardProps(propDefs) {
-    let proto = this.prototype
-
-    if (!proto.hasOwnProperty('standardPropMap')) {
-      proto.standardPropMap = Object.create(proto.standardPropMap)
-    }
-
-    copyOwnProps(propDefs, proto.standardPropMap)
-  }
-
-
-  static copyVerbatimStandardProps(src, dest) {
-    let map = this.prototype.standardPropMap
-    let propName
-
-    for (propName in map) {
-      if (
-        src[propName] != null && // in the src object?
-        map[propName] === true // false means "copy verbatim"
-      ) {
-        dest[propName] = src[propName]
-      }
-    }
-  }
-
-
-  /*
-  Returns true/false for success.
-  Meant to be only called ONCE, at object creation.
-  */
-  applyProps(rawProps) {
-    let standardPropMap = this.standardPropMap
-    let manualProps = {}
-    let miscProps = {}
-    let propName
-
-    for (propName in rawProps) {
-      if (standardPropMap[propName] === true) { // copy verbatim
-        this[propName] = rawProps[propName]
-      } else if (standardPropMap[propName] === false) {
-        manualProps[propName] = rawProps[propName]
-      } else {
-        miscProps[propName] = rawProps[propName]
-      }
-    }
-
-    this.applyMiscProps(miscProps)
-
-    return this.applyManualStandardProps(manualProps)
-  }
-
-
-  /*
-  If subclasses override, they must call this supermethod and return the boolean response.
-  Meant to be only called ONCE, at object creation.
-  */
-  applyManualStandardProps(rawProps) {
-    return true
-  }
-
-
-  /*
-  Can be called even after initial object creation.
-  */
-  applyMiscProps(rawProps) {
-    // subclasses can implement
-  }
-
-
-  /*
-  TODO: why is this a method when defineStandardProps is static
-  */
-  isStandardProp(propName) {
-    return propName in this.standardPropMap
-  }
-
-}
-
-ParsableModelMixin.prototype.standardPropMap = {} // will be cloned by defineStandardProps

+ 3 - 9
src/common/Popover.ts

@@ -16,7 +16,6 @@ Options:
 import { ElementContent, removeElement, createElement, applyStyle } from '../util/dom-manip'
 import { listenBySelector } from '../util/dom-event'
 import { getScrollParent } from '../util/dom-geom'
-import { default as ListenerMixin, ListenerInterface } from './ListenerMixin'
 
 export interface PopoverOptions {
   className?: string
@@ -31,9 +30,6 @@ export interface PopoverOptions {
 
 export default class Popover {
 
-  listenTo: ListenerInterface['listenTo']
-  stopListeningTo: ListenerInterface['stopListeningTo']
-
   isHidden: boolean = true
   options: PopoverOptions
   el: HTMLElement // the container element for the popover. generated by this object
@@ -88,13 +84,13 @@ export default class Popover {
     })
 
     if (options.autoHide) {
-      this.listenTo(document, 'mousedown', this.documentMousedown)
+      document.addEventListener('mousedown', this.documentMousedown)
     }
   }
 
 
   // Triggered when the user clicks *anywhere* in the document, for the autoHide feature
-  documentMousedown(ev) {
+  documentMousedown = (ev) => {
     // only hide the popover if the click happened outside the popover
     if (this.el && !this.el.contains(ev.target)) {
       this.hide()
@@ -111,7 +107,7 @@ export default class Popover {
       this.el = null
     }
 
-    this.stopListeningTo(document, 'mousedown')
+    document.removeEventListener('mousedown', this.documentMousedown)
   }
 
 
@@ -171,5 +167,3 @@ export default class Popover {
   }
 
 }
-
-ListenerMixin.mixInto(Popover)

+ 0 - 53
src/common/RenderQueue.ts

@@ -1,53 +0,0 @@
-import TaskQueue from './TaskQueue'
-
-
-export default class RenderQueue extends TaskQueue {
-
-  waitMs: any
-  waitId: any
-
-
-  constructor(waitMs) {
-    super()
-    this.waitMs = waitMs
-  }
-
-
-  queue(taskFunc) {
-
-    this.q.push(taskFunc)
-
-    if (this.waitMs != null) {
-      if (this.waitId != null) {
-        this.delayWait()
-      } else {
-        this.startWait()
-      }
-    } else {
-      this.tryStart()
-    }
-  }
-
-
-  delayWait() {
-    clearTimeout(this.waitId)
-    this.startWait()
-  }
-
-
-  startWait() {
-    this.waitId = setTimeout(() => {
-      this.waitId = null
-      this.tryStart()
-    }, this.waitMs)
-  }
-
-
-  clearWait() {
-    if (this.waitId != null) {
-      clearTimeout(this.waitId)
-      this.waitId = null
-    }
-  }
-
-}

+ 1 - 3
src/common/Scroller.ts

@@ -1,11 +1,10 @@
 import { computeEdges } from '../util/dom-geom'
 import { removeElement, createElement, applyStyle, applyStyleProp } from '../util/dom-manip'
-import Class from '../common/Class'
 
 /*
 Embodies a div that has potential scrollbars
 */
-export default class Scroller extends Class {
+export default class Scroller {
 
   el: HTMLElement // the guaranteed outer element
   scrollEl: HTMLElement // the element with the scrollbars
@@ -14,7 +13,6 @@ export default class Scroller extends Class {
 
 
   constructor(options?) {
-    super()
     options = options || {}
     this.overflowX = options.overflowX || options.overflow || 'auto'
     this.overflowY = options.overflowY || options.overflow || 'auto'

+ 0 - 85
src/common/TaskQueue.ts

@@ -1,85 +0,0 @@
-import { default as EmitterMixin, EmitterInterface } from './EmitterMixin'
-
-export default class TaskQueue {
-
-  on: EmitterInterface['on']
-  one: EmitterInterface['one']
-  off: EmitterInterface['off']
-  trigger: EmitterInterface['trigger']
-  triggerWith: EmitterInterface['triggerWith']
-  hasHandlers: EmitterInterface['hasHandlers']
-
-  q: any = []
-  isPaused: boolean = false
-  isRunning: boolean = false
-
-
-  queue(...args) {
-    this.q.push.apply(this.q, args) // append
-    this.tryStart()
-  }
-
-
-  pause() {
-    this.isPaused = true
-  }
-
-
-  resume() {
-    this.isPaused = false
-    this.tryStart()
-  }
-
-
-  getIsIdle() {
-    return !this.isRunning && !this.isPaused
-  }
-
-
-  tryStart() {
-    if (!this.isRunning && this.canRunNext()) {
-      this.isRunning = true
-      this.trigger('start')
-      this.runRemaining()
-    }
-  }
-
-
-  canRunNext() {
-    return !this.isPaused && this.q.length
-  }
-
-
-  runRemaining() { // assumes at least one task in queue. does not check canRunNext for first task.
-    let task
-    let res
-
-    do {
-      task = this.q.shift() // always freshly reference q. might have been reassigned.
-      res = this.runTask(task)
-
-      if (res && res.then) {
-        res.then(() => {
-          if (this.canRunNext()) {
-            this.runRemaining()
-          }
-        })
-        return // prevent marking as stopped
-      }
-    } while (this.canRunNext())
-
-    this.trigger('stop') // not really a 'stop' ... more of a 'drained'
-    this.isRunning = false
-
-    // if 'stop' handler added more tasks.... TODO: write test for this
-    this.tryStart()
-  }
-
-
-  runTask(task) {
-    return task() // task *is* the function, but subclasses can change the format of a task
-  }
-
-}
-
-EmitterMixin.mixInto(TaskQueue)

+ 0 - 4
src/exports.ts

@@ -72,14 +72,10 @@ export {
 } from './util/dom-geom'
 
 export { default as EmitterMixin, EmitterInterface } from './common/EmitterMixin'
-export { default as ListenerMixin, ListenerInterface } from './common/ListenerMixin'
 export { default as UnzonedRange } from './models/UnzonedRange'
 export { defineThemeSystem } from './theme/ThemeRegistry'
-export { default as Class } from './common/Class'
 export { default as Mixin } from './common/Mixin'
 export { default as CoordCache } from './common/CoordCache'
-export { default as TaskQueue } from './common/TaskQueue'
-export { default as RenderQueue } from './common/RenderQueue'
 export { default as Scroller } from './common/Scroller'
 export { default as Theme } from './theme/Theme'
 export { default as DateComponent } from './component/DateComponent'

+ 0 - 6
src/models/UnzonedRange.ts

@@ -93,12 +93,6 @@ export default class UnzonedRange {
   }
 
 
-  containsRange(innerRange: UnzonedRange) {
-    return (this.start == null || (innerRange.start != null && innerRange.start >= this.start)) &&
-      (this.end == null || (innerRange.end != null && innerRange.end <= this.end))
-  }
-
-
   // `date` can be a Date, or a millisecond time.
   containsDate(date: Date) {
     return (this.start == null || date >= this.start) &&