debug.js.coffee 1.9 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. if @matcher
  32. console.timeEnd @matcher.name
  33. if @matcher.name is 'exactMatch'
  34. for entries, score in @scoreMap by -1 when entries
  35. console.log '' + score + ': ' + entries.map((entry) -> entry.text).join("\n ")
  36. _match()
  37. _setupMatcher = @setupMatcher.bind(@)
  38. @setupMatcher = ->
  39. console.time @matcher.name
  40. _setupMatcher()
  41. _end = @end.bind(@)
  42. @end = ->
  43. console.log "Results: #{@totalResults}"
  44. console.groupEnd()
  45. console.timeEnd 'Total'
  46. _end()
  47. _kill = @kill.bind(@)
  48. @kill = ->
  49. if @timeout
  50. console.timeEnd @matcher.name if @matcher
  51. console.groupEnd()
  52. console.timeEnd 'Total'
  53. console.warn 'Killed'
  54. _kill()
  55. return
  56. _proto.constructor = app.Searcher
  57. app.Searcher.prototype = _proto
  58. #
  59. # View tree
  60. #
  61. @viewTree = (view = app.document, level = 0) ->
  62. console.log "%c #{Array(level + 1).join(' ')}#{view.constructor.name}: #{view.activated}",
  63. 'color:' + (view.activated and 'green' or 'red')
  64. for key, value of view when key isnt 'view' and value
  65. if typeof value is 'object' and value.setupElement
  66. @viewTree(value, level + 1)
  67. else if value.constructor.toString().match(/Object\(\)/)
  68. @viewTree(v, level + 1) for k, v of value when value and typeof value is 'object' and value.setupElement
  69. return