Git Product home page Git Product logo

backbone-stacktrace's Introduction

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 https://github.com/eriwen/javascript-stacktrace. 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.

<script src=backbone-min.js></script>
<script src="stacktrace.js"></script>
<script src=Backbone.StackTrace.js></script>

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.

backbone-stacktrace's People

Contributors

bhuga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

levi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.