twigg-app 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/javascripts/_bootstrap.js +7 -0
- data/assets/javascripts/_jquery.js +19 -0
- data/assets/javascripts/_tables.js +3 -0
- data/assets/javascripts/_views.js +10 -0
- data/assets/javascripts/application.js +9 -0
- data/{public/application.js → assets/javascripts/views/_commit_set_bar_chart.js} +32 -34
- data/assets/javascripts/views/_russia.js +61 -0
- data/assets/javascripts/views/_tags.js +56 -0
- data/assets/javascripts/views/_tags_word_cloud.js +51 -0
- data/assets/stylesheets/_bootstrap_overrides.scss +15 -0
- data/assets/stylesheets/_footer.scss +28 -0
- data/assets/stylesheets/_global.scss +14 -0
- data/assets/stylesheets/_tables.scss +20 -0
- data/assets/stylesheets/application.scss +10 -0
- data/assets/stylesheets/d3/_bar_chart.scss +25 -0
- data/assets/stylesheets/d3/_bubble_chart.scss +22 -0
- data/lib/twigg-app/app/routes.rb +4 -0
- data/lib/twigg-app/app/server.rb +78 -21
- data/lib/twigg-app/app/version.rb +1 -1
- data/public/vendor/bootstrap/Gruntfile.js +32 -10
- data/public/vendor/bootstrap/README.md +2 -0
- data/public/vendor/bootstrap/_config.yml +5 -10
- data/public/vendor/bootstrap/_includes/footer.html +2 -1
- data/public/vendor/bootstrap/_includes/nav-components.html +33 -31
- data/public/vendor/bootstrap/_includes/nav-css.html +32 -22
- data/public/vendor/bootstrap/_includes/nav-getting-started.html +17 -1
- data/public/vendor/bootstrap/_includes/nav-javascript.html +1 -1
- data/public/vendor/bootstrap/_includes/nav-main.html +1 -1
- data/public/vendor/bootstrap/_includes/social-buttons.html +1 -1
- data/public/vendor/bootstrap/_layouts/default.html +18 -14
- data/public/vendor/bootstrap/_layouts/home.html +9 -6
- data/public/vendor/bootstrap/assets/css/docs.css +584 -396
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-114-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-144-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-57-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-72-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/favicon.png +0 -0
- data/public/vendor/bootstrap/assets/js/application.js +2 -1
- data/public/vendor/bootstrap/assets/js/customizer.js +160 -45
- data/public/vendor/bootstrap/assets/js/filesaver.js +169 -0
- data/public/vendor/bootstrap/assets/js/jquery.js +6 -5
- data/public/vendor/bootstrap/assets/js/raw-files.js +3 -0
- data/public/vendor/bootstrap/bower.json +1 -1
- data/public/vendor/bootstrap/components.html +787 -364
- data/public/vendor/bootstrap/composer.json +1 -1
- data/public/vendor/bootstrap/css.html +413 -248
- data/public/vendor/bootstrap/customize.html +413 -447
- data/public/vendor/bootstrap/dist/css/bootstrap-theme.css +384 -0
- data/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css +1 -0
- data/public/vendor/bootstrap/dist/css/bootstrap.css +3033 -1807
- data/public/vendor/bootstrap/dist/css/bootstrap.min.css +1 -1
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +228 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
- data/public/vendor/bootstrap/dist/js/bootstrap.js +18 -12
- data/public/vendor/bootstrap/dist/js/bootstrap.min.js +1 -1
- data/public/vendor/bootstrap/examples/carousel/carousel.css +128 -0
- data/public/vendor/bootstrap/examples/carousel/index.html +201 -0
- data/public/vendor/bootstrap/examples/grid/grid.css +28 -0
- data/public/vendor/bootstrap/examples/grid/index.html +119 -0
- data/public/vendor/bootstrap/examples/jumbotron/index.html +111 -0
- data/public/vendor/bootstrap/examples/jumbotron/jumbotron.css +5 -0
- data/public/vendor/bootstrap/examples/jumbotron-narrow/index.html +78 -0
- data/public/vendor/bootstrap/examples/jumbotron-narrow/jumbotron-narrow.css +79 -0
- data/public/vendor/bootstrap/examples/justified-nav/index.html +79 -0
- data/public/vendor/bootstrap/examples/justified-nav/justified-nav.css +88 -0
- data/public/vendor/bootstrap/examples/navbar/index.html +83 -0
- data/public/vendor/bootstrap/examples/navbar/navbar.css +7 -0
- data/public/vendor/bootstrap/examples/navbar-fixed-top/index.html +86 -0
- data/public/vendor/bootstrap/examples/navbar-fixed-top/navbar-fixed-top.css +4 -0
- data/public/vendor/bootstrap/examples/navbar-static-top/index.html +87 -0
- data/public/vendor/bootstrap/examples/navbar-static-top/navbar-static-top.css +7 -0
- data/public/vendor/bootstrap/examples/non-responsive/index.html +96 -0
- data/public/vendor/bootstrap/examples/non-responsive/non-responsive.css +117 -0
- data/public/vendor/bootstrap/examples/offcanvas/index.html +127 -0
- data/public/vendor/bootstrap/examples/offcanvas/offcanvas.css +48 -0
- data/public/vendor/bootstrap/examples/offcanvas/offcanvas.js +5 -0
- data/public/vendor/bootstrap/examples/screenshots/carousel.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/grid.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/jumbotron-narrow.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/jumbotron.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/justified-nav.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar-fixed.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar-static.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/non-responsive.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/offcanvas.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sign-in.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/starter-template.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sticky-footer-navbar.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sticky-footer.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/theme.jpg +0 -0
- data/public/vendor/bootstrap/examples/signin/index.html +46 -0
- data/public/vendor/bootstrap/examples/signin/signin.css +40 -0
- data/public/vendor/bootstrap/examples/starter-template/index.html +63 -0
- data/public/vendor/bootstrap/examples/starter-template/starter-template.css +7 -0
- data/public/vendor/bootstrap/examples/sticky-footer/index.html +51 -0
- data/public/vendor/bootstrap/examples/sticky-footer/sticky-footer.css +39 -0
- data/public/vendor/bootstrap/examples/sticky-footer-navbar/index.html +86 -0
- data/public/vendor/bootstrap/examples/sticky-footer-navbar/sticky-footer-navbar.css +46 -0
- data/public/vendor/bootstrap/examples/theme/index.html +387 -0
- data/public/vendor/bootstrap/examples/theme/theme.css +14 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +228 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- data/public/vendor/bootstrap/getting-started.html +513 -22
- data/public/vendor/bootstrap/index.html +3 -4
- data/public/vendor/bootstrap/javascript.html +123 -115
- data/public/vendor/bootstrap/js/dropdown.js +3 -3
- data/public/vendor/bootstrap/js/modal.js +5 -3
- data/public/vendor/bootstrap/js/tests/unit/modal.js +19 -0
- data/public/vendor/bootstrap/js/tests/vendor/jquery.js +6 -5
- data/public/vendor/bootstrap/js/tooltip.js +9 -5
- data/public/vendor/bootstrap/js/transition.js +1 -1
- data/public/vendor/bootstrap/less/alerts.less +7 -11
- data/public/vendor/bootstrap/less/bootstrap.less +17 -21
- data/public/vendor/bootstrap/less/button-groups.less +14 -10
- data/public/vendor/bootstrap/less/buttons.less +3 -2
- data/public/vendor/bootstrap/less/carousel.less +6 -1
- data/public/vendor/bootstrap/less/dropdowns.less +22 -5
- data/public/vendor/bootstrap/less/forms.less +36 -15
- data/public/vendor/bootstrap/less/glyphicons.less +232 -0
- data/public/vendor/bootstrap/less/grid.less +9 -3
- data/public/vendor/bootstrap/less/input-groups.less +1 -1
- data/public/vendor/bootstrap/less/jumbotron.less +16 -5
- data/public/vendor/bootstrap/less/labels.less +9 -5
- data/public/vendor/bootstrap/less/mixins.less +73 -43
- data/public/vendor/bootstrap/less/modals.less +8 -0
- data/public/vendor/bootstrap/less/navbar.less +251 -189
- data/public/vendor/bootstrap/less/navs.less +13 -12
- data/public/vendor/bootstrap/less/pager.less +1 -1
- data/public/vendor/bootstrap/less/pagination.less +20 -9
- data/public/vendor/bootstrap/less/panels.less +28 -8
- data/public/vendor/bootstrap/less/progress-bars.less +6 -10
- data/public/vendor/bootstrap/less/responsive-utilities.less +120 -49
- data/public/vendor/bootstrap/less/scaffolding.less +37 -18
- data/public/vendor/bootstrap/less/tables.less +84 -59
- data/public/vendor/bootstrap/less/theme.less +232 -0
- data/public/vendor/bootstrap/less/thumbnails.less +8 -19
- data/public/vendor/bootstrap/less/type.less +2 -2
- data/public/vendor/bootstrap/less/variables.less +63 -50
- data/public/vendor/bootstrap/package.json +2 -1
- data/public/vendor/components-backbone/LICENSE +22 -0
- data/public/vendor/components-backbone/README.md +10 -0
- data/public/vendor/components-backbone/backbone-min.js +4 -0
- data/public/vendor/components-backbone/backbone.js +1571 -0
- data/public/vendor/components-backbone/bower.json +17 -0
- data/public/vendor/components-backbone/component.json +21 -0
- data/public/vendor/components-backbone/composer.json +37 -0
- data/public/vendor/components-backbone/package.json +24 -0
- data/public/vendor/d3.layout.cloud.js +401 -0
- data/public/vendor/replacejs/CHANGELOG.md +4 -0
- data/public/vendor/replacejs/replace.js +21 -2
- data/public/vendor/underscore/CNAME +1 -0
- data/public/vendor/underscore/CONTRIBUTING.md +9 -0
- data/public/vendor/underscore/LICENSE +22 -0
- data/public/vendor/underscore/README.md +19 -0
- data/public/vendor/underscore/Rakefile +10 -0
- data/public/vendor/underscore/docs/docco.css +192 -0
- data/public/vendor/underscore/docs/favicon.ico +0 -0
- data/public/vendor/underscore/docs/images/background.png +0 -0
- data/public/vendor/underscore/docs/images/underscore.png +0 -0
- data/public/vendor/underscore/docs/underscore.html +823 -0
- data/public/vendor/underscore/favicon.ico +0 -0
- data/public/vendor/underscore/index.html +2467 -0
- data/public/vendor/underscore/index.js +1 -0
- data/public/vendor/underscore/package.json +16 -0
- data/public/vendor/underscore/test/arrays.js +200 -0
- data/public/vendor/underscore/test/chaining.js +59 -0
- data/public/vendor/underscore/test/collections.js +453 -0
- data/public/vendor/underscore/test/functions.js +265 -0
- data/public/vendor/underscore/test/index.html +44 -0
- data/public/vendor/underscore/test/objects.js +570 -0
- data/public/vendor/underscore/test/speed.js +75 -0
- data/public/vendor/underscore/test/utility.js +266 -0
- data/public/vendor/underscore/test/vendor/jquery.js +9404 -0
- data/public/vendor/underscore/test/vendor/jslitmus.js +670 -0
- data/public/vendor/underscore/test/vendor/qunit.css +235 -0
- data/public/vendor/underscore/test/vendor/qunit.js +1977 -0
- data/public/vendor/underscore/test/vendor/runner.js +98 -0
- data/public/vendor/underscore/underscore-min.js +1 -0
- data/public/vendor/underscore/underscore.js +1226 -0
- data/views/dashboard.haml +1 -1
- data/views/layout.haml +8 -4
- metadata +132 -25
- data/public/vendor/bootstrap/_layouts/customize.html +0 -52
- data/public/vendor/bootstrap/assets/js/jquery.bbq.min.js +0 -1287
- data/public/vendor/bootstrap-glyphicons/CHANGELOG.md +0 -3
- data/public/vendor/bootstrap-glyphicons/CNAME +0 -1
- data/public/vendor/bootstrap-glyphicons/CONTRIBUTING.md +0 -54
- data/public/vendor/bootstrap-glyphicons/LICENSE +0 -19
- data/public/vendor/bootstrap-glyphicons/README.md +0 -61
- data/public/vendor/bootstrap-glyphicons/_config.yml +0 -12
- data/public/vendor/bootstrap-glyphicons/composer.json +0 -9
- data/public/vendor/bootstrap-glyphicons/css/bootstrap-glyphicons.css +0 -2
- data/public/vendor/bootstrap-glyphicons/css/bootstrap.css +0 -9
- data/public/vendor/bootstrap-glyphicons/css/docs.css +0 -160
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.eot +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.otf +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.svg +0 -175
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.ttf +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.woff +0 -0
- data/public/vendor/bootstrap-glyphicons/index.html +0 -255
- data/public/vendor/bootstrap-glyphicons/less/bootstrap-glyphicons.less +0 -201
- data/public/vendor/bootstrap-glyphicons/package.json +0 -18
@@ -0,0 +1,265 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
module("Functions");
|
4
|
+
|
5
|
+
test("bind", function() {
|
6
|
+
var context = {name : 'moe'};
|
7
|
+
var func = function(arg) { return "name: " + (this.name || arg); };
|
8
|
+
var bound = _.bind(func, context);
|
9
|
+
equal(bound(), 'name: moe', 'can bind a function to a context');
|
10
|
+
|
11
|
+
bound = _(func).bind(context);
|
12
|
+
equal(bound(), 'name: moe', 'can do OO-style binding');
|
13
|
+
|
14
|
+
bound = _.bind(func, null, 'curly');
|
15
|
+
equal(bound(), 'name: curly', 'can bind without specifying a context');
|
16
|
+
|
17
|
+
func = function(salutation, name) { return salutation + ': ' + name; };
|
18
|
+
func = _.bind(func, this, 'hello');
|
19
|
+
equal(func('moe'), 'hello: moe', 'the function was partially applied in advance');
|
20
|
+
|
21
|
+
func = _.bind(func, this, 'curly');
|
22
|
+
equal(func(), 'hello: curly', 'the function was completely applied in advance');
|
23
|
+
|
24
|
+
func = function(salutation, firstname, lastname) { return salutation + ': ' + firstname + ' ' + lastname; };
|
25
|
+
func = _.bind(func, this, 'hello', 'moe', 'curly');
|
26
|
+
equal(func(), 'hello: moe curly', 'the function was partially applied in advance and can accept multiple arguments');
|
27
|
+
|
28
|
+
func = function(context, message) { equal(this, context, message); };
|
29
|
+
_.bind(func, 0, 0, 'can bind a function to `0`')();
|
30
|
+
_.bind(func, '', '', 'can bind a function to an empty string')();
|
31
|
+
_.bind(func, false, false, 'can bind a function to `false`')();
|
32
|
+
|
33
|
+
// These tests are only meaningful when using a browser without a native bind function
|
34
|
+
// To test this with a modern browser, set underscore's nativeBind to undefined
|
35
|
+
var F = function () { return this; };
|
36
|
+
var Boundf = _.bind(F, {hello: "moe curly"});
|
37
|
+
equal(Boundf().hello, "moe curly", "When called without the new operator, it's OK to be bound to the context");
|
38
|
+
});
|
39
|
+
|
40
|
+
test("partial", function() {
|
41
|
+
var obj = {name: 'moe'};
|
42
|
+
var func = function() { return this.name + ' ' + _.toArray(arguments).join(' '); };
|
43
|
+
|
44
|
+
obj.func = _.partial(func, 'a', 'b');
|
45
|
+
equal(obj.func('c', 'd'), 'moe a b c d', 'can partially apply');
|
46
|
+
});
|
47
|
+
|
48
|
+
test("bindAll", function() {
|
49
|
+
var curly = {name : 'curly'}, moe = {
|
50
|
+
name : 'moe',
|
51
|
+
getName : function() { return 'name: ' + this.name; },
|
52
|
+
sayHi : function() { return 'hi: ' + this.name; }
|
53
|
+
};
|
54
|
+
curly.getName = moe.getName;
|
55
|
+
_.bindAll(moe, 'getName', 'sayHi');
|
56
|
+
curly.sayHi = moe.sayHi;
|
57
|
+
equal(curly.getName(), 'name: curly', 'unbound function is bound to current object');
|
58
|
+
equal(curly.sayHi(), 'hi: moe', 'bound function is still bound to original object');
|
59
|
+
|
60
|
+
curly = {name : 'curly'};
|
61
|
+
moe = {
|
62
|
+
name : 'moe',
|
63
|
+
getName : function() { return 'name: ' + this.name; },
|
64
|
+
sayHi : function() { return 'hi: ' + this.name; }
|
65
|
+
};
|
66
|
+
_.bindAll(moe);
|
67
|
+
curly.sayHi = moe.sayHi;
|
68
|
+
equal(curly.sayHi(), 'hi: moe', 'calling bindAll with no arguments binds all functions to the object');
|
69
|
+
});
|
70
|
+
|
71
|
+
test("memoize", function() {
|
72
|
+
var fib = function(n) {
|
73
|
+
return n < 2 ? n : fib(n - 1) + fib(n - 2);
|
74
|
+
};
|
75
|
+
var fastFib = _.memoize(fib);
|
76
|
+
equal(fib(10), 55, 'a memoized version of fibonacci produces identical results');
|
77
|
+
equal(fastFib(10), 55, 'a memoized version of fibonacci produces identical results');
|
78
|
+
|
79
|
+
var o = function(str) {
|
80
|
+
return str;
|
81
|
+
};
|
82
|
+
var fastO = _.memoize(o);
|
83
|
+
equal(o('toString'), 'toString', 'checks hasOwnProperty');
|
84
|
+
equal(fastO('toString'), 'toString', 'checks hasOwnProperty');
|
85
|
+
});
|
86
|
+
|
87
|
+
asyncTest("delay", 2, function() {
|
88
|
+
var delayed = false;
|
89
|
+
_.delay(function(){ delayed = true; }, 100);
|
90
|
+
setTimeout(function(){ ok(!delayed, "didn't delay the function quite yet"); }, 50);
|
91
|
+
setTimeout(function(){ ok(delayed, 'delayed the function'); start(); }, 150);
|
92
|
+
});
|
93
|
+
|
94
|
+
asyncTest("defer", 1, function() {
|
95
|
+
var deferred = false;
|
96
|
+
_.defer(function(bool){ deferred = bool; }, true);
|
97
|
+
_.delay(function(){ ok(deferred, "deferred the function"); start(); }, 50);
|
98
|
+
});
|
99
|
+
|
100
|
+
asyncTest("throttle", 2, function() {
|
101
|
+
var counter = 0;
|
102
|
+
var incr = function(){ counter++; };
|
103
|
+
var throttledIncr = _.throttle(incr, 32);
|
104
|
+
throttledIncr(); throttledIncr();
|
105
|
+
|
106
|
+
equal(counter, 1, "incr was called immediately");
|
107
|
+
_.delay(function(){ equal(counter, 2, "incr was throttled"); start(); }, 64);
|
108
|
+
});
|
109
|
+
|
110
|
+
asyncTest("throttle arguments", 2, function() {
|
111
|
+
var value = 0;
|
112
|
+
var update = function(val){ value = val; };
|
113
|
+
var throttledUpdate = _.throttle(update, 32);
|
114
|
+
throttledUpdate(1); throttledUpdate(2);
|
115
|
+
_.delay(function(){ throttledUpdate(3); }, 64);
|
116
|
+
equal(value, 1, "updated to latest value");
|
117
|
+
_.delay(function(){ equal(value, 3, "updated to latest value"); start(); }, 96);
|
118
|
+
});
|
119
|
+
|
120
|
+
asyncTest("throttle once", 2, function() {
|
121
|
+
var counter = 0;
|
122
|
+
var incr = function(){ return ++counter; };
|
123
|
+
var throttledIncr = _.throttle(incr, 32);
|
124
|
+
var result = throttledIncr();
|
125
|
+
_.delay(function(){
|
126
|
+
equal(result, 1, "throttled functions return their value");
|
127
|
+
equal(counter, 1, "incr was called once"); start();
|
128
|
+
}, 64);
|
129
|
+
});
|
130
|
+
|
131
|
+
asyncTest("throttle twice", 1, function() {
|
132
|
+
var counter = 0;
|
133
|
+
var incr = function(){ counter++; };
|
134
|
+
var throttledIncr = _.throttle(incr, 32);
|
135
|
+
throttledIncr(); throttledIncr();
|
136
|
+
_.delay(function(){ equal(counter, 2, "incr was called twice"); start(); }, 64);
|
137
|
+
});
|
138
|
+
|
139
|
+
asyncTest("throttle repeatedly with results", 6, function() {
|
140
|
+
var counter = 0;
|
141
|
+
var incr = function(){ return ++counter; };
|
142
|
+
var throttledIncr = _.throttle(incr, 64);
|
143
|
+
var results = [];
|
144
|
+
var saveResult = function() { results.push(throttledIncr()); };
|
145
|
+
saveResult(); saveResult();
|
146
|
+
_.delay(saveResult, 32);
|
147
|
+
_.delay(saveResult, 80);
|
148
|
+
_.delay(saveResult, 96);
|
149
|
+
_.delay(saveResult, 144);
|
150
|
+
_.delay(function() {
|
151
|
+
equal(results[0], 1, "incr was called once");
|
152
|
+
equal(results[1], 1, "incr was throttled");
|
153
|
+
equal(results[2], 1, "incr was throttled");
|
154
|
+
equal(results[3], 2, "incr was called twice");
|
155
|
+
equal(results[4], 2, "incr was throttled");
|
156
|
+
equal(results[5], 3, "incr was called trailing");
|
157
|
+
start();
|
158
|
+
}, 192);
|
159
|
+
});
|
160
|
+
|
161
|
+
asyncTest("throttle triggers trailing call when invoked repeatedly", 2, function() {
|
162
|
+
var counter = 0;
|
163
|
+
var limit = 48;
|
164
|
+
var incr = function(){ counter++; };
|
165
|
+
var throttledIncr = _.throttle(incr, 32);
|
166
|
+
|
167
|
+
var stamp = new Date;
|
168
|
+
while ((new Date - stamp) < limit) {
|
169
|
+
throttledIncr();
|
170
|
+
}
|
171
|
+
var lastCount = counter;
|
172
|
+
ok(counter > 1);
|
173
|
+
|
174
|
+
_.delay(function() {
|
175
|
+
ok(counter > lastCount);
|
176
|
+
start();
|
177
|
+
}, 96);
|
178
|
+
});
|
179
|
+
|
180
|
+
asyncTest("debounce", 1, function() {
|
181
|
+
var counter = 0;
|
182
|
+
var incr = function(){ counter++; };
|
183
|
+
var debouncedIncr = _.debounce(incr, 32);
|
184
|
+
debouncedIncr(); debouncedIncr();
|
185
|
+
_.delay(debouncedIncr, 16);
|
186
|
+
_.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 96);
|
187
|
+
});
|
188
|
+
|
189
|
+
asyncTest("debounce asap", 4, function() {
|
190
|
+
var a, b;
|
191
|
+
var counter = 0;
|
192
|
+
var incr = function(){ return ++counter; };
|
193
|
+
var debouncedIncr = _.debounce(incr, 64, true);
|
194
|
+
a = debouncedIncr();
|
195
|
+
b = debouncedIncr();
|
196
|
+
equal(a, 1);
|
197
|
+
equal(b, 1);
|
198
|
+
equal(counter, 1, 'incr was called immediately');
|
199
|
+
_.delay(debouncedIncr, 16);
|
200
|
+
_.delay(debouncedIncr, 32);
|
201
|
+
_.delay(debouncedIncr, 48);
|
202
|
+
_.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 128);
|
203
|
+
});
|
204
|
+
|
205
|
+
asyncTest("debounce asap recursively", 2, function() {
|
206
|
+
var counter = 0;
|
207
|
+
var debouncedIncr = _.debounce(function(){
|
208
|
+
counter++;
|
209
|
+
if (counter < 10) debouncedIncr();
|
210
|
+
}, 32, true);
|
211
|
+
debouncedIncr();
|
212
|
+
equal(counter, 1, "incr was called immediately");
|
213
|
+
_.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 96);
|
214
|
+
});
|
215
|
+
|
216
|
+
test("once", function() {
|
217
|
+
var num = 0;
|
218
|
+
var increment = _.once(function(){ num++; });
|
219
|
+
increment();
|
220
|
+
increment();
|
221
|
+
equal(num, 1);
|
222
|
+
});
|
223
|
+
|
224
|
+
test("wrap", function() {
|
225
|
+
var greet = function(name){ return "hi: " + name; };
|
226
|
+
var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); });
|
227
|
+
equal(backwards('moe'), 'hi: moe eom', 'wrapped the saluation function');
|
228
|
+
|
229
|
+
var inner = function(){ return "Hello "; };
|
230
|
+
var obj = {name : "Moe"};
|
231
|
+
obj.hi = _.wrap(inner, function(fn){ return fn() + this.name; });
|
232
|
+
equal(obj.hi(), "Hello Moe");
|
233
|
+
|
234
|
+
var noop = function(){};
|
235
|
+
var wrapped = _.wrap(noop, function(fn){ return Array.prototype.slice.call(arguments, 0); });
|
236
|
+
var ret = wrapped(['whats', 'your'], 'vector', 'victor');
|
237
|
+
deepEqual(ret, [noop, ['whats', 'your'], 'vector', 'victor']);
|
238
|
+
});
|
239
|
+
|
240
|
+
test("compose", function() {
|
241
|
+
var greet = function(name){ return "hi: " + name; };
|
242
|
+
var exclaim = function(sentence){ return sentence + '!'; };
|
243
|
+
var composed = _.compose(exclaim, greet);
|
244
|
+
equal(composed('moe'), 'hi: moe!', 'can compose a function that takes another');
|
245
|
+
|
246
|
+
composed = _.compose(greet, exclaim);
|
247
|
+
equal(composed('moe'), 'hi: moe!', 'in this case, the functions are also commutative');
|
248
|
+
});
|
249
|
+
|
250
|
+
test("after", function() {
|
251
|
+
var testAfter = function(afterAmount, timesCalled) {
|
252
|
+
var afterCalled = 0;
|
253
|
+
var after = _.after(afterAmount, function() {
|
254
|
+
afterCalled++;
|
255
|
+
});
|
256
|
+
while (timesCalled--) after();
|
257
|
+
return afterCalled;
|
258
|
+
};
|
259
|
+
|
260
|
+
equal(testAfter(5, 5), 1, "after(N) should fire after being called N times");
|
261
|
+
equal(testAfter(5, 4), 0, "after(N) should not fire unless called N times");
|
262
|
+
equal(testAfter(0, 0), 1, "after(0) should fire immediately");
|
263
|
+
});
|
264
|
+
|
265
|
+
});
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Underscore Test Suite</title>
|
5
|
+
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen">
|
6
|
+
<script src="vendor/jquery.js"></script>
|
7
|
+
<script src="vendor/qunit.js"></script>
|
8
|
+
<script src="vendor/jslitmus.js"></script>
|
9
|
+
<script src="../underscore.js"></script>
|
10
|
+
|
11
|
+
<script src="collections.js"></script>
|
12
|
+
<script src="arrays.js"></script>
|
13
|
+
<script src="functions.js"></script>
|
14
|
+
<script src="objects.js"></script>
|
15
|
+
<script src="utility.js"></script>
|
16
|
+
<script src="chaining.js"></script>
|
17
|
+
<script src="speed.js"></script>
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="qunit"></div>
|
21
|
+
<div id="qunit-fixture">
|
22
|
+
<div id="map-test">
|
23
|
+
<div id="id1"></div>
|
24
|
+
<div id="id2"></div>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<br>
|
28
|
+
<h1 class="qunit-header">Underscore Speed Suite</h1>
|
29
|
+
<p>
|
30
|
+
A representative sample of the functions are benchmarked here, to provide
|
31
|
+
a sense of how fast they might run in different browsers.
|
32
|
+
Each iteration runs on an array of 1000 elements.<br /><br />
|
33
|
+
For example, the 'intersection' test measures the number of times you can
|
34
|
+
find the intersection of two thousand-element arrays in one second.
|
35
|
+
</p>
|
36
|
+
<br>
|
37
|
+
<script type="text/html" id="template">
|
38
|
+
<%
|
39
|
+
// a comment
|
40
|
+
if (data) { data += 12345; }; %>
|
41
|
+
<li><%= data %></li>
|
42
|
+
</script>
|
43
|
+
</body>
|
44
|
+
</html>
|