debug.js.coffee 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. return unless console?.time and console.groupCollapsed
  2. #
  3. # App
  4. #
  5. _init = app.init
  6. app.init = ->
  7. console.time 'Init'
  8. _init.call(app)
  9. console.timeEnd 'Init'
  10. console.time 'Load'
  11. _start = app.start
  12. app.start = ->
  13. console.timeEnd 'Load'
  14. console.time 'Start'
  15. _start.call(app, arguments...)
  16. console.timeEnd 'Start'
  17. #
  18. # Searcher
  19. #
  20. _super = app.Searcher
  21. _proto = app.Searcher.prototype
  22. app.Searcher = ->
  23. _super.apply @, arguments
  24. _setup = @setup.bind(@)
  25. @setup = ->
  26. console.groupCollapsed "Search: #{@query}"
  27. console.time 'Total'
  28. _setup()
  29. _match = @match.bind(@)
  30. @match = =>
  31. console.timeEnd @matcher.name if @matcher
  32. _match()
  33. _setupMatcher = @setupMatcher.bind(@)
  34. @setupMatcher = ->
  35. console.time @matcher.name
  36. _setupMatcher()
  37. _end = @end.bind(@)
  38. @end = ->
  39. console.log "Results: #{@totalResults}"
  40. console.timeEnd 'Total'
  41. console.groupEnd()
  42. _end()
  43. _kill = @kill.bind(@)
  44. @kill = ->
  45. if @timeout
  46. console.timeEnd @matcher.name if @matcher
  47. console.groupEnd()
  48. console.timeEnd 'Total'
  49. console.warn 'Killed'
  50. _kill()
  51. return
  52. $.extend(app.Searcher, _super)
  53. _proto.constructor = app.Searcher
  54. app.Searcher.prototype = _proto
  55. #
  56. # View tree
  57. #
  58. @viewTree = (view = app.document, level = 0, visited = []) ->
  59. return if visited.indexOf(view) >= 0
  60. visited.push(view)
  61. console.log "%c #{Array(level + 1).join(' ')}#{view.constructor.name}: #{!!view.activated}",
  62. 'color:' + (view.activated and 'green' or 'red')
  63. for own key, value of view when key isnt 'view' and value
  64. if typeof value is 'object' and value.setupElement
  65. @viewTree(value, level + 1, visited)
  66. else if value.constructor.toString().match(/Object\(\)/)
  67. @viewTree(v, level + 1, visited) for own k, v of value when v and typeof v is 'object' and v.setupElement
  68. return