import { StatusEnum } from '../model/constants' ; declare const history ; declare const window ; export function find ( arr , func ) { for ( let i = 0 ; i < arr . length ; i ++ ) { if ( func ( arr [ i ] ) ) { return arr [ i ] ; } } return null ; } export function mooaLog ( ... args ) { if ( window [ 'mooa' ] && window [ 'mooa' ] [ 'debug' ] ) { console . log ( args ) ; } } function MooaCustomEvent ( event , params ) { params = params || { bubbles : false , cancelable : false , detail : undefined } ; let evt = document . createEvent ( 'CustomEvent' ) ; evt . initCustomEvent ( event , params . bubbles , params . cancelable , params . detail ) ; return evt ; } export function customEvent ( eventName , eventArgs ? ) { if ( typeof window . CustomEvent !== 'function' ) { MooaCustomEvent . prototype = window . Event . prototype ; window . CustomEvent = MooaCustomEvent ; } window . dispatchEvent ( new CustomEvent ( eventName , { detail : eventArgs } ) ) ; } export function navigateAppByName ( opts ) { let navigateToApp ; window . apps . map ( ( app ) => { app . status = StatusEnum . MOUNTED ; if ( app . name === opts . appName ) { app . status = StatusEnum . NOT_LOADED ; navigateToApp = app ; return app ; } } ) ; if ( navigateToApp ) { let prefix = navigateToApp . appConfig . prefix ; history . pushState ( null , '' , prefix + '/' + opts . router ) ; return window . mooa . instance . reRouter ( ) ; } } export function hashCode ( str ) { let hash = 0 ; if ( str . length === 0 ) { return hash . toString ( ) ; } for ( let i = 0 ; i < str . length ; i ++ ) { hash = ( hash << 5 ) - hash + str . charCodeAt ( i ) ; hash = hash & hash ; hash = hash >>> 1 ; } return hash . toString ( ) ; }