1.1.4 • Published 6 years ago

@sycoraxya/iaspect-raf v1.1.4

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
6 years ago

iaspect-raf

fileSize Coverage build type definitions code style: prettier

Installation:

npm install @sycoraxya/iaspect-raf

or

yarn add @sycoraxya/iaspect-raf

Specific version

npm install @sycoraxya/iaspect-raf@v1.1.3

or

yarn add @sycoraxya/iaspect-raf@v1.1.3

See tags for version numbers

Importing:

Add the following line to your script

import Raf from "@sycoraxya/iaspect-raf";

Or add the folder to your webpack.config:

resolve: {
    modulesDirectories: ["node_modules/@sycoraxya"];
}

// And add the following line to your scripts
import Raf from "iaspect-raf";

Usage

iaspect-raf has 3 timers: Now, Timeout and Interval.

Now

Use Now to perform an action in the next animationframe.

import Raf from "@sycoraxya/iaspect-raf";

Raf.now((rafInstance, elapsed) => {
    // Do stuff
});

Timeout

Use Timeout to perform an action after given MS.

The second argument can be a number or a Settings object.

import Raf from "@sycoraxya/iaspect-raf";

Raf.timeout((rafInstance, elapsed) => {
    // Do stuff
}, 200);

Interval

Use Interval to perform an action after given MS and repeat it.

The second argument can be a number or a Settings object.

import Raf from "@sycoraxya/iaspect-raf";

Raf.interval((rafInstance, elapsed) => {
    // Do stuff
}, 200);

Using a Settings object

If you want to specify a tickFn, use a Settings object instead of a number as the second argument

The tickFn includes the final tick

Raf.interval(
    (rafInstance, elapsed) => {
        // Do stuff after 200ms
    },
    {
        time: 200,
        tickFn: (rafInstance, elapsed) => {
            // Do stuff every tick
        },
    },
);

Types

Exported types

  • RafTimeout
  • RafInterval
  • RafNow

You can import these types like this:

import Raf, { RafInterval } from "@sycoraxya/iaspect-raf";

let interval: RafInterval;

Callback

All callbacks are called with the following arguments:

ArgumentDescription
rafInstanceThe instance of the raf timer that's created (RafNow, RafInterval, RafTimeout)
elapsed(number) The amount of time in ms that has elapsed since the method started

Settings

A Settings object can be passed as the second argument instead of a number.

Settings can contain the following properties:

PropertyRequiredDescription
timeYes(number) the time in MS
tickFnNo(Callback) A function that gets called every animationframe

RafNow & RafTimeout

methods

MethodDescription
pausePauses the timer
resumeResumes the timer
stopStops the timer
restartRestarts the timer with the settings that were defined at creation

properties

PropertyTypeDescription
pausedbooleanIs the instance paused
donebooleanIs the instance done
progressnumberThe progress of the current iteration as a percentage
elapsednumberHow much time has elapsed since the start of the current iteration

RafInterval

RafInterval inherits all methods and properties from RafNow and adds the following:

properties

PropertyDescription
iteration(number) The iteration of the interval. Starts at 1
1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago