2014-09-12 86 views

回答

1
@override 
    void attached() { 
    super.attached(); 
    dom.window.onMouseMove.listen(mouseMoveHandler); 
    } 

    PolymerJob mouseMoveJob; 
    void mouseMoveHandler(dom.MouseEvent e) { 
    print('mousemove'); 
    mouseMoveJob = scheduleJob(mouseMoveJob, onDone, new Duration(milliseconds: 500)); 
    } 

    void onDone() { 
    print('done'); 
    } 

如果作業不改在500毫秒執行它。
在聚合物初始化過程中經常使用的時候,因爲xxx是從其他幾個州,其被相繼初始化一個變化的更新

xxxChanged(old); 

簡潔地叫了幾次,但是當xxxChanged是爲執行它足夠最後更新(應使用更短的超時,然後像0-20毫秒,取決於是否只從同步或異步代碼調用xxxChanged@observable字段被綁定到滑塊<input type="range" value='{{slider}}'>
當您移動旋鈕時,這會在很短的時間間隔內經常調用sliderChanged(oldVal, newVal)。更新的執行非常昂貴,無法在兩個此類調用之間完成,例如參見http://bwu-dart.github.io/bwu_datagrid/example/e04_model.html。如果沒有一些延遲執行,這將是非常麻煩的使用。

0

嘗試使用Future

doJob() => print('hi'); 

new Future(doJob).then((_) => print('job is done')); 

這裏是docs for the Future class

+0

我對Polymer的'.job'感興趣的事情之一是它「可以在超時之前重複調用,但它只會導致一個副作用。」未來聽起來不像是一個非常好的比賽,沒有很多額外的代碼。 有[PolymerJob類](http://www.dartdocs.org/documentation/polymer/0.14.0+1/index.html#polymer/polymer.PolymerJob),但我仍然試圖找出如果那可行。 – Randy 2014-09-13 00:43:38