Code Monkey home page Code Monkey logo

fish-tacos's Introduction

Eggs Benedict πŸ₯šπŸ₯“πŸžπŸ½

What πŸ‘‹

A simple utility that limits the impact of functions the demand high CPU load.

Why πŸ€·β€β™€οΈ

Functionality that demands intense CPU load can create a poor user experience as their session can hang and become unresponsive.

There are throttle and debounce solutions that help to alleviate the repercussions of CPU intensive UI. Eggs Benedict incorporates these methodologies into a lightweight React and Vanilla JS abstraction.


Eggs Benedict was originally designed to help with the various complex calculations associated with the Avocado application. The library has since been enhanced into a simple developer API that can yield powerful results.

Avocado demo

How πŸ’‘

This library uses Request Animation Frame to implement throttle and debounce solutions simultaneously. This provides the real-time updates of a throttler while ensuring that the UI does not fall out of sync with a debouncer.

Eggs Benedict Flow

Options βš™οΈ

Eggs Benedict offers some light configuration for custom throttle and debounce delays.

{
  throttleDelay: 0, // Default.
  debounceDelay: 100 // Default.
}

Take a look at the interactive CodeSandbox to see configuration examples and their correlation with different CPU loads.

eggs-benedict-options-example

Typescript πŸ‘Œ

You can reference the Eggs Benedict types directly in your application.

import { Options } from "eggs-benedict/types";

You can also supply a typed callback as a generic to the React Hooks and Vanilla JS initializers.

React Hooks

// prettier-ignore
const setLoadControlValue =
  useLoadControl<(value: string) => void>(callback);

Vanilla JS

// prettier-ignore
const [activeLoadControl, cleanUpLoadControl] =
  LoadControl<(value: string) => void>(callback);

Examples πŸ“

React Hooks

In this example we are using the React Hooks import to run some CPU heavy work when the Range <input /> changes its value.

import React from "react";
import { useLoadControl } from "eggs-benedict/hooks";

export default function App() {
  const [count, setCount] = React.useState(0);
  const heavyCpuLoad = (value) => {
    /**
     * CPU HEAVY WORK HERE!
     * - - - - - - - - - - -
     * Maybe some complex calculations based on the Range <input /> value πŸ€“
     */
    setCount(value);
  };
  const setLoadControlCount = useLoadControl(heavyCpuLoad);
  const handleChange = (event) =>
    setLoadControlCount(event.currentTarget.value);

  return (
    <>
      <input type="range" value={count} onChange={handleChange} />
      <p>{count}</p>
    </>
  );
}

Vanilla JS

In this example we are using a Vanilla JS implementation inside a React useEffect scaffold. When the user scrolls the window we run a CPU heavy callback.

import React from "react";
import LoadControl from "eggs-benedict";

export default function App() {
  const [scroll, setScroll] = React.useState(0);
  React.useEffect(() => {
    const heavyCpuLoad = (event) => {
      /**
       * CPU HEAVY WORK HERE!
       * - - - - - - - - - - -
       * Maybe slow DOM heavy math to move some elements around πŸ€“
       */
      setScroll(event.currentTarget.scrollY);
    };
    const [scrollLoadControl, cleanUpScrollLoadControl] = LoadControl(
      heavyCpuLoad
    );
    window.addEventListener("scroll", scrollLoadControl);

    /**
     * Remember to remove the Eggs Benedict instance when unmounting your
     * <Component /> πŸ‘
     */
    return cleanUpScrollLoadControl;
  }, []);
  return (
    <>
      <p style={{ position: "fixed" }}>{scroll}</p>
      <div
        style={{
          height: "200vh",
          backgroundImage: "linear-gradient(to bottom, #58FFC7, #2D8165)",
        }}
      />
    </>
  );
}

fish-tacos's People

Contributors

devonchurch avatar

Watchers

 avatar  avatar

fish-tacos's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Missing package.json file.

A package.json file at the root of your project is required to release on npm.

Please follow the npm guideline to create a valid package.json file.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.