/**
 * 工具方法模块
 */ namespace drunk . util { export var global = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : { } ; var uniqueSymbol = typeof global . Symbol !== 'undefined' ? global . Symbol ( '__DRUNK_UID__' ) : '__DRUNK_UID__' ; var uidCounter = 0 ; param target export function uniqueId ( target ) { if ( typeof target [ uniqueSymbol ] === 'undefined' ) { Object . defineProperty ( target , uniqueSymbol , { value : uidCounter ++ } ) ; } return target [ uniqueSymbol ] ; } param target export function isPlainObjectOrObservableObject ( target ) { if ( ! target || typeof target !== 'object' ) { return false ; } let proto = Object . getPrototypeOf ( target ) ; return Object . prototype . toString . call ( target ) === '[object Object]' && ( proto === Object . prototype || proto === observable . ObservableObjectPrototype ) ; } param destination param . . sources return export function extend ( destination , ... sources ) { sources . forEach ( ( src ) => { if ( src ) { Object . keys ( src ) . forEach ( ( key ) => { ( < any > destination ) [ key ] = src [ key ] ; } ) ; } } ) ; return destination ; } param target export function deepClone ( target ) { if ( Array . isArray ( target ) ) { return target . map ( ( item ) => { return deepClone ( item ) ; } ) ; } if ( isPlainObjectOrObservableObject ( target ) ) { var ret = { } ; Object . keys ( target ) . forEach ( name => { ret [ name ] = deepClone ( target [ name ] ) ; } ) ; return ret ; } return target ; } param arrayLike return export function toArray ( arrayLike ) { return Array . prototype . slice . call ( arrayLike ) ; } param array param item export function addArrayItem ( array , item ) { if ( array . indexOf ( item ) < 0 ) { array . push ( item ) ; } } param array param item export function removeArrayItem ( array , item ) { var index = array . indexOf ( item ) ; if ( index > - 1 ) { array . splice ( index , 1 ) ; } } param str export function camelCase ( str ) { return str . replace ( /[-_](\w)/g , ( $0 , $1 ) => $1 . toUpperCase ( ) ) ; } function hasProxy ( target , property ) { var des = Object . getOwnPropertyDescriptor ( target , property ) ; if ( des && ( ( typeof des . get === 'function' && des . get === des . set ) || ! des . configurable ) ) { return true ; } var proto = target . __proto__ ; while ( proto ) { des = Object . getOwnPropertyDescriptor ( proto , property ) ; if ( des && ( ( typeof des . get === 'function' && des . get === des . set ) || ! des . configurable ) ) { Object . defineProperty ( target , property , des ) ; return true ; } proto = proto . __proto__ ; } return false ; } param target param property param source return export function createProxy ( target , property , source ) { if ( hasProxy ( target , property ) ) { return false ; } function proxyGetterSetter ( ) { if ( arguments . length === 0 ) { return source [ property ] ; } source [ property ] = arguments [ 0 ] ; } Object . defineProperty ( target , property , { enumerable : true , configurable : true , set : proxyGetterSetter , get : proxyGetterSetter } ) ; return true ; } export interface IAsyncJob { completed : boolean ; cancel ( ) : void ; } param work param context return export function execAsyncWork ( work , context ? ) { let timerId ; let job = { completed : false , cancel ( ) { if ( ! job . completed ) { clearTimeout ( timerId ) ; } context = work = null ; } } ; timerId = setTimeout ( ( ) => { work . call ( context ) ; job . completed = true ; context = work = null ; } , 0 ) ; return job ; } export function isObjectOrNotEqual ( a , b ) { return a !== b || ( typeof a === 'object' && a ) ; } var handleCounter = 1 ; var requestAnimationCallbackMap = { } ; var requestAnimationWorker ; export var requestAnimationFrame = global . requestAnimationFrame && global . requestAnimationFrame . bind ( global ) || function ( callback ) { let handle = handleCounter ++ ; requestAnimationCallbackMap [ handle ] = callback ; requestAnimationWorker = requestAnimationWorker || global . setTimeout ( function ( ) { let handlers = requestAnimationCallbackMap ; let now = Date . now ( ) ; requestAnimationCallbackMap = { } ; requestAnimationWorker = null ; Object . keys ( handlers ) . forEach ( id => handlers [ id ] ( now ) ) ; } , 16 ) ; return handle ; } ; export var cancelAnimationFrame = global . cancelAnimationFrame && global . cancelAnimationFrame . bind ( global ) || function ( handle ) { delete requestAnimationCallbackMap [ handle ] ; } ; }