diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-12-22 10:18:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-22 10:18:38 +0100 |
commit | 194ebc3da9641ff96f083f9d8ab43c2d27944f9a (patch) | |
tree | c50988f32ccf18df93ae7ab40be78e9459642818 /lib/api/deprecate.js | |
parent | 64ccb6b00b4b63fa0e516d4e35351275b34f8c07 (diff) | |
parent | 16af264360e48e8a833e9efa9ab8d194574dbc70 (diff) | |
download | gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.zip gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.gz gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.bz2 |
Merge pull request #1543 from GitbookIO/dream
React for rendering website with plugins
Diffstat (limited to 'lib/api/deprecate.js')
-rw-r--r-- | lib/api/deprecate.js | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/lib/api/deprecate.js b/lib/api/deprecate.js deleted file mode 100644 index 7a93a91..0000000 --- a/lib/api/deprecate.js +++ /dev/null @@ -1,122 +0,0 @@ -var is = require('is'); -var objectPath = require('object-path'); - -var logged = {}; -var disabled = {}; - -/** - Log a deprecated notice - - @param {Book|Output} book - @param {String} key - @param {String} message -*/ -function logNotice(book, key, message) { - if (logged[key] || disabled[key]) return; - - logged[key] = true; - - var logger = book.getLogger(); - logger.warn.ln(message); -} - -/** - Deprecate a function - - @param {Book|Output} book - @param {String} key: unique identitifer for the deprecated - @param {Function} fn - @param {String} msg: message to print when called - @return {Function} -*/ -function deprecateMethod(book, key, fn, msg) { - return function() { - logNotice(book, key, msg); - - return fn.apply(this, arguments); - }; -} - -/** - Deprecate a property of an object - - @param {Book|Output} book - @param {String} key: unique identitifer for the deprecated - @param {Object} instance - @param {String|Function} property - @param {String} msg: message to print when called - @return {Function} -*/ -function deprecateField(book, key, instance, property, value, msg) { - var store = undefined; - - var prepare = function() { - if (!is.undefined(store)) return; - - if (is.fn(value)) store = value(); - else store = value; - }; - - var getter = function(){ - prepare(); - - logNotice(book, key, msg); - return store; - }; - var setter = function(v) { - prepare(); - - logNotice(book, key, msg); - store = v; - return store; - }; - - Object.defineProperty(instance, property, { - get: getter, - set: setter, - enumerable: true, - configurable: true - }); -} - -/** - Enable a deprecation - - @param {String} key: unique identitifer -*/ -function enableDeprecation(key) { - disabled[key] = false; -} - -/** - Disable a deprecation - - @param {String} key: unique identitifer -*/ -function disableDeprecation(key) { - disabled[key] = true; -} - -/** - Deprecate a method in favor of another one - - @param {Book} book - @param {String} key - @param {Object} instance - @param {String} oldName - @param {String} newName -*/ -function deprecateRenamedMethod(book, key, instance, oldName, newName, msg) { - msg = msg || ('"' + oldName + '" is deprecated, use "' + newName + '()" instead'); - var fn = objectPath.get(instance, newName); - - instance[oldName] = deprecateMethod(book, key, fn, msg); -} - -module.exports = { - method: deprecateMethod, - renamedMethod: deprecateRenamedMethod, - field: deprecateField, - enable: enableDeprecation, - disable: disableDeprecation -}; |