mirror of
https://github.com/sstent/node.git
synced 2026-01-27 15:41:43 +00:00
updated app
This commit is contained in:
118
node_modules/derby-examples/sink/lib/app/bindings-bench.js
generated
vendored
Normal file
118
node_modules/derby-examples/sink/lib/app/bindings-bench.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
// Generated by CoffeeScript 1.3.1
|
||||
var N, app, get, ready, render, _ref;
|
||||
|
||||
_ref = app = require('./index'), get = _ref.get, ready = _ref.ready;
|
||||
|
||||
render = require('./shared').render;
|
||||
|
||||
N = 100;
|
||||
|
||||
get('/bindings-bench', function(page, model) {
|
||||
var boxes, i, _i;
|
||||
boxes = [];
|
||||
for (i = _i = 0; 0 <= N ? _i < N : _i > N; i = 0 <= N ? ++_i : --_i) {
|
||||
boxes.push({
|
||||
count: 0,
|
||||
top: 0,
|
||||
left: 0,
|
||||
color: 0,
|
||||
content: 0,
|
||||
i: i
|
||||
});
|
||||
}
|
||||
model.set('_boxes', boxes);
|
||||
return render(page, 'bindingsBench', {
|
||||
modes: ['setProperty', 'setBox', 'setAll']
|
||||
});
|
||||
});
|
||||
|
||||
ready(function(model) {
|
||||
var boxValue, boxes, fn, frames, modes, run, setAll, setBox, setProperty, start, tickBox, tickProperty, timeout;
|
||||
boxes = model.at('_boxes');
|
||||
tickProperty = function(box) {
|
||||
var count;
|
||||
count = box.incr('count');
|
||||
box.set('top', Math.sin(count / 10) * 10);
|
||||
box.set('left', Math.cos(count / 10) * 10);
|
||||
box.set('color', count % 255);
|
||||
return box.set('content', count % 100);
|
||||
};
|
||||
setProperty = function() {
|
||||
var i, _i;
|
||||
for (i = _i = 0; 0 <= N ? _i < N : _i > N; i = 0 <= N ? ++_i : --_i) {
|
||||
tickProperty(boxes.at(i));
|
||||
}
|
||||
};
|
||||
tickBox = function(box, i) {
|
||||
var count;
|
||||
count = box.get('count') + 1;
|
||||
return box.set({
|
||||
count: count,
|
||||
top: Math.sin(count / 10) * 10,
|
||||
left: Math.cos(count / 10) * 10,
|
||||
color: count % 255,
|
||||
content: count % 100,
|
||||
i: i
|
||||
});
|
||||
};
|
||||
setBox = function() {
|
||||
var i, _i;
|
||||
for (i = _i = 0; 0 <= N ? _i < N : _i > N; i = 0 <= N ? ++_i : --_i) {
|
||||
tickBox(boxes.at(i), i);
|
||||
}
|
||||
};
|
||||
boxValue = function(box, i) {
|
||||
var count;
|
||||
count = box.count + 1;
|
||||
return {
|
||||
count: count,
|
||||
top: Math.sin(count / 10) * 10,
|
||||
left: Math.cos(count / 10) * 10,
|
||||
color: count % 255,
|
||||
content: count % 100,
|
||||
i: i
|
||||
};
|
||||
};
|
||||
setAll = function() {
|
||||
var box, i, previous, value, _i, _len;
|
||||
previous = boxes.get();
|
||||
value = [];
|
||||
for (i = _i = 0, _len = previous.length; _i < _len; i = ++_i) {
|
||||
box = previous[i];
|
||||
value.push(boxValue(box, i));
|
||||
}
|
||||
return boxes.set(value);
|
||||
};
|
||||
frames = 0;
|
||||
start = fn = timeout = null;
|
||||
run = function() {
|
||||
var fps;
|
||||
fn();
|
||||
if (frames++ === 20) {
|
||||
fps = frames * 1000 / (new Date - start);
|
||||
model.set('_fps', fps.toFixed(1));
|
||||
frames = 0;
|
||||
start = +(new Date);
|
||||
}
|
||||
return timeout = setTimeout(run, 0);
|
||||
};
|
||||
modes = {
|
||||
setProperty: setProperty,
|
||||
setBox: setBox,
|
||||
setAll: setAll
|
||||
};
|
||||
app.start = function(e, el) {
|
||||
var mode;
|
||||
clearTimeout(timeout);
|
||||
mode = el.innerHTML;
|
||||
model.set('_bindProperties', mode === 'setProperty');
|
||||
model.set('_mode', mode);
|
||||
fn = modes[mode];
|
||||
frames = 0;
|
||||
start = +(new Date);
|
||||
return run();
|
||||
};
|
||||
return app.stop = function() {
|
||||
return clearTimeout(timeout);
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user