adamschwartz / log

Console.log with style.
https://adamschwartz.co/log
MIT License
3.01k stars 140 forks source link

Offer a way to include the library into an arbitrary namespace #46

Open rickhallett opened 6 years ago

rickhallett commented 6 years ago

PR based on issue #46

Changes suggested:

window.log = 'original reference to another library named AnotherLog';

// log library is loaded into the window object, which over-rides the window.log reference

// the new feature is called which returns the original value of window.log, and stores the new library in another variable on the window object.

var logWithStyle = log.restorePreviousLogRef();
logWithStyle('*this is in italics*');
adamschwartz commented 6 years ago

Thanks! This is great.

We’ll want to make sure we make these changes in the source log.coffee file instead of log.js.

I’d also like to improve on the method name restorePreviousLogRef, although I think that’s a good start. Here are a few candidates:

Of all of these, I think I’m most a fan of log.export, since it mirrors the behavior you get when you use the library with AMD or another supported dependency management system (and "exports" is the terminology there).

All of this being said, as I’m reminded that we do support RequireJS and AMD (which allow you to bring in log into your own namespace) it makes me wonder if this is even needed. I’m still interested in pursuing this PR though. I’d be interested to see what it looks like before deciding.

rickhallett commented 6 years ago

Hi Adam, thanks for the feedback. Do you mean making the changes solely in log.coffee, or making them in both?

I like log.export too, but export is often a reserved keyword, according to my linter. How about exportAndRestore? I've made a commit with these changes to the coffee.log file, but relied heavily on a converter available at http://js2.coffee/. I have removed what seems to be more obviously superfluous and synchronised comments with your original work. As for a more detailed evaluation of the the code, I would have to defer to your expertise.

adamschwartz commented 6 years ago

You’ll want to make changes to log.coffee and then run grunt to compiled them