npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yy-loop

v0.4.1

Published

Simple and configurable game/update loop.

Downloads

7

Readme

yy-loop

Simple and configurable game/main loop

features

  • emits events (using eventemitter3)
  • run every frame or after an interval
  • control how many times each function runs
  • loop pauses when app loses focus
  • uses requestAnimationFrame()

rationale

This is a replacement for YY-Update. I use this in all my games, and as a base class for my other libraries, including pixi-ease and pixi-viewport.

installation

npm i yy-loop

simple example

const Loop = require('yy-loop')

const loop = new Loop()

// add a function to the loop that logs the elapsed time
loop.add((elapsed) => console.log(elapsed))

// add a function to the loop that runs ever second for 5 times
const entry = loop.add((elapsed) => console.log(elapsed), 1000, 5)

// run each time entry is called
entry.on('each', () => console.log('It has been one second.'))

// run after entry is complete
entry.on('done', () => console.log('completed'))

live example

https://davidfig.github.io/loop/

API

src/loop.js

    /**
     * basic loop support
     * @param {object} [options]
     * @param {number} [options.maxFrameTime=1000/60] maximum time in milliseconds for a frame
     * @param {object} [options.pauseOnBlur] pause loop when app loses focus, start it when app regains focus
     *
     * @event each(elapsed, Loop)
     * @event start(Loop)
     * @event stop(Loop)
     */
    constructor(options)

    /**
     * start requestAnimationFrame() loop
     * @return {Loop} this
     */
    start()

    /**
     * stop loop
     * @return {Loop} this
     */
    stop()

    /**
     * loop through updates; can be called manually each frame, or called automatically as part of start()
     * @param {number} elapsed time since last call (will be clamped to this.maxFrameTime)
     */
    update(elapsed)

    /**
     * adds a callback to the loop
     * @deprecated use add() instead
     * @param {function} callback
     * @param {number} [time=0] in milliseconds to call this update (0=every frame)
     * @param {number} [count=0] number of times to run this update (0=infinite)
     * @return {object} entry - used to remove or change the parameters of the update
     */
    interval(callback, time, count)

    /**
     * adds a callback to the loop
     * @param {function} callback
     * @param {number} [time=0] in milliseconds to call this update (0=every frame)
     * @param {number} [count=0] number of times to run this update (0=infinite)
     * @return {object} entry - used to remove or change the parameters of the update
     */
    add(callback, time, count)

    /**
     * adds a one-time callback to the loop
     * @param {function} callback
     * @param {number} time in milliseconds to call this update
     * @return {object} entry - used to remove or change the parameters of the update
     */
    timeout(callback, time)

    /**
     * remove a callback from the loop
     * @param {object} entry - returned by add()
     */
    remove(entry)

    /**
     * removes all callbacks from the loop
     */
    removeAll()

    /**
     * @type {number} count of all animations
     */
    get count()

    /**
     * @type {number} count of running animations
     */
    get countRunning()

src/entry.js

/** Entry class for Loop */
class Entry extends Events
{
    /**
     * create an entry in the update loop
     * used by Loop
     * @param {function} callback
     * @param {number} [time=0] in milliseconds to call this update
     * @param {number} [count] number of times to run this update (undefined=infinite)
     */
    constructor(callback, time, count)

    /**
     * update checks time and runs the callback
     * @param {number} elapsed
     * @return {boolean} whether entry is complete and may be removed from list
     */
    update(elapsed)

    /**
     * @type {boolean} pause this entry
     */
    set pause(value)

License

MIT License
(c) 2017 YOPEY YOPEY LLC by David Figatner