2
0
Adam Shaw 8 жил өмнө
parent
commit
302af0beb9

+ 1 - 1
src/ViewSpecManager.ts

@@ -1,6 +1,6 @@
 import * as moment from 'moment'
 import { viewHash } from './ViewRegistry'
-import { mergeProps } from './util'
+import { mergeProps } from './util/object'
 import { unitsDesc, computeDurationGreatestUnit } from './util/date'
 import { mergeOptions, globalDefaults } from './options'
 import { populateInstanceComputableOptions } from './locale'

+ 1 - 1
src/agenda/AgendaView.ts

@@ -5,8 +5,8 @@ import {
   compensateScroll,
   subtractInnerElHeight,
   htmlEscape,
-  copyOwnProps
 } from '../util'
+import { copyOwnProps } from '../util/object'
 import { findElements, createElement } from '../util/dom'
 import Scroller from '../common/Scroller'
 import View from '../View'

+ 1 - 1
src/common/Class.ts

@@ -1,4 +1,4 @@
-import { copyOwnProps } from '../util'
+import { copyOwnProps } from '../util/object'
 
 
 // Class that all other classes will inherit from

+ 1 - 1
src/common/ParsableModelMixin.ts

@@ -12,7 +12,7 @@ after class:
   ParsableModelMixin.mixInto(TheClass)
 */
 
-import { copyOwnProps } from '../util'
+import { copyOwnProps } from '../util/object'
 import Mixin from './Mixin'
 
 export interface ParsableModelInterface {

+ 2 - 2
src/models/EventPeriod.ts

@@ -1,6 +1,6 @@
 import * as moment from 'moment'
 import { removeExact, removeMatching } from '../util'
-import { isEmpty } from '../util/object'
+import { isEmptyObject } from '../util/object'
 import { default as EmitterMixin, EmitterInterface } from '../common/EmitterMixin'
 import UnzonedRange from './UnzonedRange'
 import EventInstanceGroup from './event/EventInstanceGroup'
@@ -191,7 +191,7 @@ export default class EventPeriod {
 
 
   removeAllEventDefs() {
-    let hasEventDefs = !isEmpty(this.eventDefsByUid)
+    let hasEventDefs = !isEmptyObject(this.eventDefsByUid)
 
     this.eventDefsByUid = {}
     this.eventDefsById = {}

+ 1 - 1
src/options.ts

@@ -1,4 +1,4 @@
-import { mergeProps } from './util'
+import { mergeProps } from './util/object'
 
 
 export const globalDefaults = {

+ 0 - 66
src/util.ts

@@ -288,72 +288,6 @@ export function warn(...args) {
 /* General Utilities
 ----------------------------------------------------------------------------------------------------------------------*/
 
-const hasOwnPropMethod = {}.hasOwnProperty
-
-
-// Merges an array of objects into a single object.
-// The second argument allows for an array of property names who's object values will be merged together.
-export function mergeProps(propObjs, complexProps?) {
-  let dest = {}
-  let i
-  let name
-  let complexObjs
-  let j
-  let val
-  let props
-
-  if (complexProps) {
-    for (i = 0; i < complexProps.length; i++) {
-      name = complexProps[i]
-      complexObjs = []
-
-      // collect the trailing object values, stopping when a non-object is discovered
-      for (j = propObjs.length - 1; j >= 0; j--) {
-        val = propObjs[j][name]
-
-        if (typeof val === 'object' && val) { // non-null object
-          complexObjs.unshift(val)
-        } else if (val !== undefined) {
-          dest[name] = val // if there were no objects, this value will be used
-          break
-        }
-      }
-
-      // if the trailing values were objects, use the merged value
-      if (complexObjs.length) {
-        dest[name] = mergeProps(complexObjs)
-      }
-    }
-  }
-
-  // copy values into the destination, going from last to first
-  for (i = propObjs.length - 1; i >= 0; i--) {
-    props = propObjs[i]
-
-    for (name in props) {
-      if (!(name in dest)) { // if already assigned by previous props or complex props, don't reassign
-        dest[name] = props[name]
-      }
-    }
-  }
-
-  return dest
-}
-
-
-export function copyOwnProps(src, dest) {
-  for (let name in src) {
-    if (hasOwnProp(src, name)) {
-      dest[name] = src[name]
-    }
-  }
-}
-
-
-export function hasOwnProp(obj, name) {
-  return hasOwnPropMethod.call(obj, name)
-}
-
 
 export function applyAll(functions, thisObj, args) {
   if (typeof functions === 'function') { // supplied a single function

+ 69 - 1
src/util/object.ts

@@ -1,4 +1,7 @@
 
+const hasOwnPropMethod = {}.hasOwnProperty
+
+
 export function assignTo(target, ...sources) {
   for (let i = 0; i < sources.length; i++) {
     let source = sources[i]
@@ -14,9 +17,74 @@ export function assignTo(target, ...sources) {
   return target
 }
 
-export function isEmpty(obj) {
+
+export function isEmptyObject(obj) {
   for (let _key in obj) {
     return false
   }
   return true
 }
+
+
+export function copyOwnProps(src, dest) {
+  for (let name in src) {
+    if (hasOwnProp(src, name)) {
+      dest[name] = src[name]
+    }
+  }
+}
+
+
+function hasOwnProp(obj, name) {
+  return hasOwnPropMethod.call(obj, name)
+}
+
+
+// Merges an array of objects into a single object.
+// The second argument allows for an array of property names who's object values will be merged together.
+export function mergeProps(propObjs, complexProps?) {
+  let dest = {}
+  let i
+  let name
+  let complexObjs
+  let j
+  let val
+  let props
+
+  if (complexProps) {
+    for (i = 0; i < complexProps.length; i++) {
+      name = complexProps[i]
+      complexObjs = []
+
+      // collect the trailing object values, stopping when a non-object is discovered
+      for (j = propObjs.length - 1; j >= 0; j--) {
+        val = propObjs[j][name]
+
+        if (typeof val === 'object' && val) { // non-null object
+          complexObjs.unshift(val)
+        } else if (val !== undefined) {
+          dest[name] = val // if there were no objects, this value will be used
+          break
+        }
+      }
+
+      // if the trailing values were objects, use the merged value
+      if (complexObjs.length) {
+        dest[name] = mergeProps(complexObjs)
+      }
+    }
+  }
+
+  // copy values into the destination, going from last to first
+  for (i = propObjs.length - 1; i >= 0; i--) {
+    props = propObjs[i]
+
+    for (name in props) {
+      if (!(name in dest)) { // if already assigned by previous props or complex props, don't reassign
+        dest[name] = props[name]
+      }
+    }
+  }
+
+  return dest
+}