Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add custom debug-block #85

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

Ability to add custom debug-block #85

ItsAsbreuk opened this issue Jun 6, 2013 · 3 comments

Comments

@ItsAsbreuk
Copy link

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.

@ItsAsbreuk
Copy link
Author

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

@ItsAsbreuk
Copy link
Author

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
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants