Ability to add custom debug-block #85

Open
ItsAsbreuk opened this Issue Jun 6, 2013 · 3 comments

Comments

Projects
None yet
2 participants

It would be great add a feature by which we can add a custom debug-block which are removed from non-debug builds.

Inline code like /#DEBUG/ debug code goes here /#END_DEBUG/

It could be solved by adding a debug block regex by default for everyone, or by adding a way to configure a custom regex per module.

There might even be situations where you want some code only when not debugging and left away during debug.
For example: https://groups.google.com/forum/#!topic/yui-contrib/RQC3rTsG_xY

So, what about

/#IF_DEBUG/
debugcode goes here
/#ELSE_DEBUG/
no-debugcode goes here
/#END_DEBUG/

Marco

a simple usage of a debugblock would be when creating Promises. In this examples you need to clean more code than just Y.log().

var timeout, mybutton, promiseBtnclickOnTime;
timeout = 10000;
mybutton = Y.one('#mybutton');
promiseBtnclickOnTime = new Y.Promise(function (resolve, reject) {
    mybutton.on('click', function() {
        /*#IF_DEBUG*/
        if (promiseBtnclickOnTime.getStatus==='pending') {
            Y.log('button clicked on time');
        }
        /*#END_DEBUG*/
        // resolve() can be called even if the promise is rejected --> a promise cannot change it state
        resolve();
    });
    Y.later(timeout, null, function() {
        /*#IF_DEBUG*/
        if (promiseBtnclickOnTime.getStatus==='pending') {
            Y.log('button is not clicked on time');
        }
        /*#END_DEBUG*/
        // reject() can be called even if the promise is fulfilled --> a promise cannot change it state
        reject();
    });
});

tribis commented Jun 26, 2013

For this cases I do as I've seen done in the YUI code: use emtpy Y.log() on the line to be removed by non debug versions.

It means that:

mybutton.on('click', function() {
        /*#IF_DEBUG*/
        if (promiseBtnclickOnTime.getStatus==='pending') {
            Y.log('button clicked on time');
        }
        /*#END_DEBUG*/
        // resolve() can be called even if the promise is rejected --> a promise cannot change it state
        resolve();
    });

becomes

mybutton.on('click', function() {
     
        if (promiseBtnclickOnTime.getStatus==='pending') {  Y.log();//for debug
            Y.log('button clicked on time');
        }  Y.log();//for debug
        // resolve() can be called even if the promise is rejected --> a promise cannot change it state
        resolve();
    });

Not as clean but it gets the job done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment