]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/event-kit/node_modules/grim/lib/grim.js
eee1d91cffb8fbd5bd003bd9db1d378f3992e3cc
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / event-kit / node_modules / grim / lib / grim.js
1 (function() {
2 var Deprecation, Emitter, grim, _;
3
4 _ = require('underscore-plus');
5
6 Emitter = require('emissary').Emitter;
7
8 Deprecation = require('./deprecation');
9
10 if (global.__grim__ == null) {
11 grim = global.__grim__ = {
12 grimDeprecations: [],
13 maxDeprecationCallCount: function() {
14 return 250;
15 },
16 getDeprecations: function() {
17 return _.clone(grim.grimDeprecations);
18 },
19 getDeprecationsLength: function() {
20 return grim.grimDeprecations.length;
21 },
22 clearDeprecations: function() {
23 return grim.grimDeprecations = [];
24 },
25 logDeprecations: function() {
26 var deprecation, deprecations, _i, _len, _results;
27 deprecations = grim.getDeprecations();
28 deprecations.sort(function(a, b) {
29 return b.getCallCount() - a.getCallCount();
30 });
31 console.warn("\nCalls to deprecated functions\n-----------------------------");
32 _results = [];
33 for (_i = 0, _len = deprecations.length; _i < _len; _i++) {
34 deprecation = deprecations[_i];
35 _results.push(console.warn("(" + (deprecation.getCallCount()) + ") " + (deprecation.getOriginName()) + " : " + (deprecation.getMessage()), deprecation));
36 }
37 return _results;
38 },
39 deprecate: function(message) {
40 var deprecation, deprecations, methodName, stack;
41 stack = Deprecation.generateStack().slice(1);
42 methodName = Deprecation.getFunctionNameFromCallsite(stack[0]);
43 deprecations = grim.grimDeprecations;
44 if (!(deprecation = _.find(deprecations, function(d) {
45 return d.getOriginName() === methodName;
46 }))) {
47 deprecation = new Deprecation(message);
48 grim.grimDeprecations.push(deprecation);
49 }
50 if (deprecation.getCallCount() < grim.maxDeprecationCallCount()) {
51 deprecation.addStack(stack);
52 return grim.emit("updated", deprecation);
53 }
54 }
55 };
56 Emitter.extend(grim);
57 }
58
59 module.exports = global.__grim__;
60
61 }).call(this);