An open API service indexing awesome lists of open source software.

https://github.com/bhuga/backbone-stacktrace

Stack Traces for triggers from Backbone Events
https://github.com/bhuga/backbone-stacktrace

Last synced: about 1 month ago
JSON representation

Stack Traces for triggers from Backbone Events

Awesome Lists containing this project

README

        

Stack Traces for Backbone.Events triggers
========================================

A quick little snippet of Javascript to debug Backbone.Event.trigger stack
traces. On trigger loops, it provides a much easier to read stack trace of
calls to `trigger` as opposed to every line of JavaScript.

## Usage

Just use backbone events as normal. When you see a loop, things will be better.

item.trigger_infinite = function() {
this.trigger 'infinite'
}
item.on('infinite', function() {
this.trigger_infinite()
})
item.trigger('infinite')

Instead of a browser using 100% of your processor, you'll see this in your
console:

.... snip ....
[object Object].trigger_infinite (file://localhost/<...>/spec/spec/Backbone.StackTraceSpec.js:40:21) 126
[object Object].trigger_infinite (file://localhost/<...>/spec/spec/Backbone.StackTraceSpec.js:40:21) 127
Backbone.StackTrace: stack too deep (128)

You can set the max stack depth like so:

window.Backbone.StackTrace.maxDepth = 256;

If you want to see the stack trace working for everything, not just loops, do this:

window.Backbone.StackTrace.verbose = true;

#### Known Issues

I'm not sure how to fake a thread-local variable in JavaScript, so things
working asynchronously will clobber each other.

## Installation

To use the stack tracer, include it after backbone. It has a single dependency,
a stack tracer, available from
. A copy of the stack tracer
is also available in the spec directory if you're lazy.

It's not recommended for production use. Shoot, I'm too lazy to even minify
this stuff.



That's it, you're done.

#### Paperwork

This is unencumbered code entered into the public domain, suitable for
copy-pasting into some other project of your own. See the attached UNLICENSE
file for more information.

Use the github page to file issues or pull requests.

Open spec/SpecRunner.html to run the tests, such as they are.