Help us understand the problem. What is going on with this article?

手が止まったらオートセーブする。

More than 1 year has passed since last update.

lodashの_.throttleを使えば簡単に実装できる。

save=_.throttle(_save,10*1000)

サーバーの通信制限をフロント側で回避できる。

例えば、gistへの認証付きcorsなら10秒に1回程度のリクエストは規制にかからない。

_save=(str)=>{
  //to gist, with api
}

oninput系の間引きにも使える。

t.oninput =_.debounce(on,50); //fps20 =1000/20

全部

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.js"></script>
let fn={}
fn.ce=(d=>document.createElement(d))
fn.now =function(time){
 /*add local time jp*/   
 if(time=='jp'||time=='jpn') return new Date( Date.now()+ 1000*60*60*9  ).toISOString().split('.')[0] +'Z'
 if(time) return new Date(time).toISOString().split('.')[0] +'Z';
 else return new Date( Date.now() ).toISOString().split('.')[0] +'Z';
}
;
let t=fn.ce('textarea')
,o=fn.ce('pre')
,l=fn.ce('label')
,_save=(str)=>{
  let n=fn.now('jp');
  console.log(n,str)
  l.textContent =n;
}
,save=_.throttle(_save,10*1000)
,on=function(ev){
  o.innerHTML = t.value;
  save(t.value);
}
;[t,l,o].forEach(d=>document.body.appendChild(d))
;
t.oninput =_.debounce(on,70);
HadaGunjyo
let target=(lines === sloc)?'good':'bad'; 説法より一行の動くコード
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away