debug.js.coffee 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. _start.call(app, arguments...)
  14. console.timeEnd 'Load'
  15. _super = app.Searcher
  16. _proto = app.Searcher.prototype
  17. #
  18. # Searcher
  19. #
  20. app.Searcher = ->
  21. _super.apply @, arguments
  22. _setup = @setup.bind(@)
  23. @setup = ->
  24. console.groupCollapsed "Search: #{@query}"
  25. console.time 'Total'
  26. _setup()
  27. _match = @match.bind(@)
  28. @match = =>
  29. if @matcher
  30. console.timeEnd @matcher.name
  31. if @matcher.name is 'exactMatch'
  32. for entries, score in @scoreMap by -1 when entries
  33. console.log '' + score + ': ' + entries.map((entry) -> entry.text).join("\n ")
  34. _match()
  35. _setupMatcher = @setupMatcher.bind(@)
  36. @setupMatcher = ->
  37. console.time @matcher.name
  38. _setupMatcher()
  39. _end = @end.bind(@)
  40. @end = ->
  41. console.log "Results: #{@totalResults}"
  42. console.groupEnd()
  43. console.timeEnd 'Total'
  44. _end()
  45. _kill = @kill.bind(@)
  46. @kill = ->
  47. if @timeout
  48. console.timeEnd @matcher.name if @matcher
  49. console.groupEnd()
  50. console.timeEnd 'Total'
  51. console.warn 'Killed'
  52. _kill()
  53. return
  54. _proto.constructor = app.Searcher
  55. app.Searcher.prototype = _proto
  56. #
  57. # View tree
  58. #
  59. @viewTree = (view = app.document, level = 0) ->
  60. console.log "%c #{Array(level + 1).join(' ')}#{view.constructor.name}: #{view.activated}",
  61. 'color:' + (view.activated and 'green' or 'red')
  62. for key, value of view when key isnt 'view' and value
  63. if typeof value is 'object' and value.setupElement
  64. @viewTree(value, level + 1)
  65. else if value.constructor.toString().match(/Object\(\)/)
  66. @viewTree(v, level + 1) for k, v of value when value and typeof value is 'object' and value.setupElement
  67. return