a zip code crypto-currency system good for red ONLY

AnimationFrameAction.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { AsyncAction } from './AsyncAction';
  2. import { AnimationFrame } from '../util/AnimationFrame';
  3. /**
  4. * We need this JSDoc comment for affecting ESDoc.
  5. * @ignore
  6. * @extends {Ignored}
  7. */
  8. export class AnimationFrameAction extends AsyncAction {
  9. constructor(scheduler, work) {
  10. super(scheduler, work);
  11. this.scheduler = scheduler;
  12. this.work = work;
  13. }
  14. requestAsyncId(scheduler, id, delay = 0) {
  15. // If delay is greater than 0, request as an async action.
  16. if (delay !== null && delay > 0) {
  17. return super.requestAsyncId(scheduler, id, delay);
  18. }
  19. // Push the action to the end of the scheduler queue.
  20. scheduler.actions.push(this);
  21. // If an animation frame has already been requested, don't request another
  22. // one. If an animation frame hasn't been requested yet, request one. Return
  23. // the current animation frame request id.
  24. return scheduler.scheduled || (scheduler.scheduled = AnimationFrame.requestAnimationFrame(scheduler.flush.bind(scheduler, null)));
  25. }
  26. recycleAsyncId(scheduler, id, delay = 0) {
  27. // If delay exists and is greater than 0, or if the delay is null (the
  28. // action wasn't rescheduled) but was originally scheduled as an async
  29. // action, then recycle as an async action.
  30. if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
  31. return super.recycleAsyncId(scheduler, id, delay);
  32. }
  33. // If the scheduler queue is empty, cancel the requested animation frame and
  34. // set the scheduled flag to undefined so the next AnimationFrameAction will
  35. // request its own.
  36. if (scheduler.actions.length === 0) {
  37. AnimationFrame.cancelAnimationFrame(id);
  38. scheduler.scheduled = undefined;
  39. }
  40. // Return undefined so the action knows to request a new async id if it's rescheduled.
  41. return undefined;
  42. }
  43. }
  44. //# sourceMappingURL=AnimationFrameAction.js.map