task-combiner
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

解决什么问题?

我们常常在同步周期派发多个命令,这样会引起后续多次任务,比如

this.setState({ b: 200 });
this.setState({ a: 100 });

我们可能希望他们被合并后,在 nextTick 后执行,如:

this.setState({ a: 100, b: 200 });

使用

const taskCombiner = new TaskCombiner();
taskCombiner.setAsyncMethodType(asyncMethodType.nextTick); // 默认是用 raf 发起异步
taskCombiner.setTaskApplier(paintCells); // 设置执行函数
taskCombiner.setTaskApplier((accumulatedTask, newTask) => {
  // 设置合并策略,缺省是合并成 undefined
  return { ...accumulatedTask, ...newTask };
});

taskCombiner.addTask(taskParams); // 需要执行操作时,只需将任务追加进去,即可自动调度异步合并执行

Readme

Keywords

none

Package Sidebar

Install

npm i task-combiner

Weekly Downloads

2

Version

1.0.1

License

ISC

Unpacked Size

5.14 kB

Total Files

5

Last publish

Collaborators

  • imaoda