1.0.3 • Published 6 years ago

time-driven-list v1.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

time-driven-list

Install

$ npm install time-driven-list

Usage

import TimeList from 'time-driven-list';

/**
 * Init the list
 */

const timeList = new TimeList({
  needReplay: true, // Controlling whether the event is abandoned after execution.
});

/**
 * Add event
 */
timeList.on({
  callBack: () => {
    console.log('list item 1 done');
  },
  time: 1000, // ms
  needTodo: true,
});

timeList.on({
  callBack: () => {
    console.log('list item 2 done');
  },
  time: 1500, // ms
});

/**
 * Trigger event
 */

// three params, currentTime, deviationTime and custom role edit the qualified list.

timeList.triggerByLimit(1200, 500);
// 'list item 1 done'
// 'list item 2 done'

timeList.triggerByLimit(800, 500, list => list.slice(-1));
// 'list item 1 done'

timeList.triggerByLimit(1200, 500, list => list.slice(-1));
// 'list item 2 done'

timeList.triggerByLimit(1200, 500, list => []);
// none

timeList.triggerByLimit(1200, 500, list => {
  const result = [];
  list.map((item) => {
    if (item.needTodo) {
      result.push(item)
    }
  });
  return result;
});
// 'list item 1 done'

Contact

Author: Jack sirens

E-mail: fanxiaocheng@howzhi.com

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago