6.1.2 • Published 3 years ago

framesync v6.1.2

Weekly downloads
488,102
License
MIT
Repository
github
Last release
3 years ago

Framesync

A tiny frame scheduler for performantly batching reads, updates and renders.

Segregating actions that read and write to the DOM will avoid layout thrashing.

It's also a way of ensuring order of execution across a frame. For instance, Framer Motion batches animations on the update step, and renders on the render step, allowing independent animation of transform properties.

Install

npm install framesync

Usage

Framesync splits a frame into discrete read, update, preRender, render and postRender steps.

Scheduling functions

Functions can be scheduled to different parts of the render loop with sync.

import sync from 'framesync';

It provides four functions, one for scheduling a function to run on each part of the frame:

sync.update(() => {});

Frame data

Each function is provided data about the current frame:

sync.update(({ delta, timestamp }) => {});
  • delta: Time since last frame (in milliseconds)
  • timestamp: Timestamp of the current frame.

This object is recycled across frames, so values should be destructured if intended to be used asynchronously.

Keep alive

We can run a function as an ongoing process by passing true as the second parameter:

let count = 0;

sync.update(() => count++, true);

This will keep the process running until it's actively cancelled.

Run immediately

The third parameter, immediate, can be used to sync a function on the current frame step.

By default, Framesync will schedule functions to run the next time that frame step is fired:

sync.update(({ timestamp }) => {
  // The following function will run on the subsequent frame:
  sync.update((frame) => frame.timestamp !== timestamp);
});

By setting immediate to true, we can add this at the end of the current step:

sync.update(({ timestamp }) => {
  // The following function will run on the **current** frame:
  sync.update(
    (frame) => frame.timestamp === timestamp,
    false,
    true
  );
});

Cancelling

Synced processes can be cancelled with the cancelSync function:

import sync, { cancelSync } from 'framesync';

let count = 0;

const process = sync.render(() => {
  count++;
  if (count >= 10) cancelSync.render(process);
}, true);
@verticon/utils@infinitebrahmanuniverse/nolb-fram@everything-registry/sub-chunk-1700svelte-motionwy-popmotionwy-framer-motiontest13456the-oaveda-template-corek0ng_d1nosaur_quenak0ng_d1nosaur_quenbk0ng_d1nosaur_quenck0ng_d1nosaur_quendk0ng_d1nosaur_quenek0ng_d1nosaur_quenfk0ng_d1nosaur_quengk0ng_d1nosaur_quenhk0ng_d1nosaur_quenik0ng_d1nosaur_quenjk0ng_d1nosaur_quenkk0ng_d1nosaur_quennk0ng_d1nosaur_quenok0ng_d1nosaur_quenpk0ng_d1nosaur_quenqk0ng_d1nosaur_quenrk0ng_d1nosaur_quenlk0ng_d1nosaur_quenmk0ng_d1nosaur_quensk0ng_d1nosaur_quentk0ng_d1nosaur_quenuk0ng_d1nosaur_quenvk0ng_d1nosaur_quenwk0ng_d1nosaur_quenxk0ng_d1nosaur_quenyk0ng_d1nosaur_quenzstylefirespacex_cycl3_roamospacex_cycl3_roampspacex_cycl3_roamqspacex_cycl3_roamrspacex_cycl3_roamsspacex_cycl3_roamtspacex_cycl3_roamuspacex_cycl3_roamvspacex_cycl3_roamwspacex_cycl3_roamxspacex_cycl3_roamyspacex_cycl3_roamzspacex_j4vaa_c3qmspacex_j4vad_c3qmspacex_j4vae_c3qmspacex_j4vaf_c3qmspacex_j4vag_c3qmspacex_j4vah_c3qmspacex_j4vai_c3qmspacex_j4vaj_c3qmspacex_j4vajk_c3qmspacex_j4vajl_c3qmspacex_java_c3qcspacex_java_c3qdspacex_java_c3qespacex_java_c3qfspacex_java_c3qgspacex_java_c3qhspacex_java_c3qispacex_java_c3qjspacex_java_c3qkspacex_java_c3qlspacex_java_c3qmspacex_java_c3qnspacex_java_c3qospacex_java_c3qpspacex_java_c3qrspacex_java_c3qsspacex_java_c3qtspacex_java_c3quspacex_java_c3qvspacex_java_c3qwspacex_j4vajzb_c3qmspacex_j4vajzc_c3qmspacex_j4vajzm_c3qmspacex_j4vajzn_c3qmspacex_j4vajzv_c3qmspacex_j4vajzx_c3qmspacex_j4vao_c3qmspacex_j4vap_c3qmspacex_j4vaq_c3qmspacex_j4var_c3qmspacex_j4vas_c3qmspacex_j4vat_c3qmspacex_j4vau_c3qmspacex_j4vaw_c3qmspacex_j4vay_c3qmspacex_java_c3qspacex_java_c3qaspacex_java_c3qbspacex_java_c3qxspacex_java_c3qyspacex_java_c3qzspacexa_cycl3_roam
6.1.2

3 years ago

6.1.1

3 years ago

6.1.0

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

6.0.0-rc.1

4 years ago

5.3.0

4 years ago

5.2.3

4 years ago

5.2.2

4 years ago

5.2.1

4 years ago

5.2.0

4 years ago

5.1.0

4 years ago

5.0.0

4 years ago

4.1.0

5 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.1.9

7 years ago

3.1.8

7 years ago

3.1.7

7 years ago

3.1.6

7 years ago

3.1.5

7 years ago

3.1.4

7 years ago

3.1.3

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.5.0

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago