Skip to content

Commit ede8166

Browse files
add logger.annotate for informational messages
we don't want to deprecate certain functions (yet?) but we can provide a helpful message saying that there is a clearer way to do this for #855
1 parent 26a1e08 commit ede8166

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/logger.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ dc.logger = (function () {
8383
};
8484

8585
/**
86-
* Use it to deprecate a function. It will return a wrapped version of the function, which will
87-
* will issue a warning when invoked. For each function, warning will be issued only once.
86+
* Used to deprecate a function. It will return a wrapped version of the function, which will
87+
* will issue a warning when invoked. The warning will be issued only once.
8888
*
8989
* @method deprecate
9090
* @memberof dc.logger
@@ -114,5 +114,40 @@ dc.logger = (function () {
114114
return deprecated;
115115
};
116116

117+
/**
118+
* Used to provide an informational message for a function. It will return a wrapped version of
119+
* the function, which will will issue a messsage with stack when invoked. The message will be
120+
* issued only once.
121+
*
122+
* @method annotate
123+
* @memberof dc.logger
124+
* @instance
125+
* @example
126+
* _chart.interpolate = dc.logger.annotate(function (interpolate) {
127+
* if (!arguments.length) {
128+
* return _interpolate;
129+
* }
130+
* _interpolate = interpolate;
131+
* return _chart;
132+
* }, 'dc.lineChart.interpolate has been annotated since version 3.0 use dc.lineChart.curve instead');
133+
* @param {Function} [fn]
134+
* @param {String} [msg]
135+
* @returns {Function}
136+
*/
137+
_logger.annotate = function (fn, msg) {
138+
// Allow logging of deprecation
139+
var warned = false;
140+
function annotated () {
141+
if (!warned) {
142+
console.groupCollapsed(msg);
143+
console.trace();
144+
console.groupEnd();
145+
warned = true;
146+
}
147+
return fn.apply(this, arguments);
148+
}
149+
return annotated;
150+
};
151+
117152
return _logger;
118153
})();

0 commit comments

Comments
 (0)