DYEBench should use TodoMVC to test FlightJS for consistency
[WebKit-https.git] / PerformanceTests / DoYouEvenBench / resources / todomvc / dependency-examples / flight / app / js / data / stats.js
1 /*global define */
2 'use strict';
3
4 define([
5     'flight/lib/component',
6     '../store'
7 ], function (defineComponent, dataStore) {
8     function stats() {
9         this.defaultAttrs({
10             dataStore: dataStore
11         });
12
13         this.recount = function () {
14             var todos = this.attr.dataStore.all();
15             var all = todos.length;
16             var remaining = todos.reduce(function (memo, each) {
17                 return memo += each.completed ? 0 : 1;
18             }, 0);
19
20             this.trigger('dataStatsCounted', {
21                 all: all,
22                 remaining: remaining,
23                 completed: all - remaining,
24                 filter: localStorage.getItem('filter') || ''
25             });
26         };
27
28         this.after('initialize', function () {
29             this.on(document, 'dataTodosLoaded', this.recount);
30             this.on(document, 'dataTodoAdded', this.recount);
31             this.on(document, 'dataTodoRemoved', this.recount);
32             this.on(document, 'dataTodoToggled', this.recount);
33             this.on(document, 'dataClearedCompleted', this.recount);
34             this.on(document, 'dataTodoToggledAll', this.recount);
35         });
36     }
37
38     return defineComponent(stats);
39 });