Skip to content

Commit

Permalink
Make step-button step continously while pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
somebee committed Feb 5, 2018
1 parent 74f775b commit 87a8917
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
13 changes: 11 additions & 2 deletions client.imba
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ state:reset = do
state:step = do |times|
for app in apps
let i = 0
while ++i < times
while i++ < times
app:api.step
return

Expand All @@ -54,12 +54,21 @@ state:run = do

bm.run(async: true, queued: false)

tag Stepper < button
def ontouchstart t
@interval = setInterval(&,10) do
state.step(1)

def ontouchend t
clearInterval(@interval)


Imba.mount <div[state].root ->
<header#header>
<input type="number" model.number='count'>
<span> "todos "
<button :tap='reset'> "reset"
<button :tap=['step',13]> "step"
<Stepper> "step"
<span.flex>
<button :tap='run'> "Run benchmark"

Expand Down
17 changes: 15 additions & 2 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ state.step = function(times) {
for (let j = 0, len = apps.length, app; j < len; j++) {
app = apps[j];
let i = 0;
while (++i < times){
while (i++ < times){
app.api.step();
};
};
Expand Down Expand Up @@ -476,14 +476,27 @@ state.run = function() {
return bm.run({async: true,queued: false});
};

var Stepper = _T.defineTag('Stepper', 'button', function(tag){
tag.prototype.ontouchstart = function (t){
return this._interval = setInterval(function() {
return state.step(1);
},10);
};

tag.prototype.ontouchend = function (t){
return clearInterval(this._interval);
};
});


Imba.mount(_T.$('div',this).flag('root').setData(state).setTemplate(function() {
var $ = this.$, self = this;
return Imba.static([
($.a=$.a || _T.$('header',this).setId('header')).setContent([
($.b=$.b || _T.$('input',this).setType("number").set('model','count',{number:1})).end(),
($.c=$.c || _T.$('span',this).setText("todos ")).end(),
($.d=$.d || _T.$('button',this).on('tap','reset',0).setText("reset")).end(),
($.e=$.e || _T.$('button',this).on('tap',['step',13],0).setText("step")).end(),
($.e=$.e || Stepper.build(this).setText("step")).end(),
($.f=$.f || _T.$('span',this).flag('flex')).end(),
($.g=$.g || _T.$('button',this).on('tap','run',0).setText("Run benchmark")).end()
],2).end(),
Expand Down

0 comments on commit 87a8917

Please sign in to comment.