Git Product home page Git Product logo

nareh's Introduction

nareh | Terminal

a terminal-style personal website.

disclaimer

in its current state, this is not the best code implementation for this website. the hope is to continuously update the site as i learn, and even possibly change technologies.

inspiration credits

while the idea to make a website of this style was a personal one, inspiration for the implementation of this website comes from Yassine Fathi. a youtuber i enjoy, Forrest Knight, also referenced Yassine's implementation, and i inevitably drew some inspiration from his implementation as well.

nareh's People

Contributors

nareha avatar vertanzil avatar

Stargazers

 avatar Michael Lan avatar Kyle Chui avatar Matt Wang avatar Advaith G avatar

Watchers

 avatar

nareh's Issues

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler (src/reportWebVitals.js)

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler

const reportWebVitals = onPerfEntry => {
  if (onPerfEntry && onPerfEntry instanceof Function) {
    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler.
      getCLS(onPerfEntry);
      getFID(onPerfEntry);
      getFCP(onPerfEntry);
      getLCP(onPerfEntry);
      getTTFB(onPerfEntry);
    });
  }
};
export default reportWebVitals;```

Promises need to be resolved or awaited to return the expected value, otherwise, they return the promise object.

Unresolved promises:

Forgetting to await a promise is a frequent mistake. There are places where the use of a promise object is confusing or unclear because the developer forgot to resolve it.

This rule forbids returning promises where another type is expected such as in:

conditionals
void returns
spread operators
Missing error handling:

Promises that aren’t resolved will finish running at an unexpected time. When they do not contain error handling and they raise an exception, the associated call stack will be wrong.

What is the potential impact?
Using a promise instead of its resolved value can have unexpected results leading to bugs.

In conditionals, it will always return a truthy value.
In places where the expected type is void, returning a promise is often a mistake.
Using the spread operator on a promise will raise an exception.
The executor function of a promise can also be an async function. However, this usually denotes a mistake:

If an async executor function throws an error, the error won’t cause the created promise to reject and will be lost. Therefore, this could make it difficult to debug and handle runtime errors.
If a promise executor function is using await, this means that it’s not necessary to use the Promise constructor, or the scope of the Promise constructor can be reduced.
Exceptions
This rule can be ignored for promises that you know will always resolve like timers.

await new Promise(resolve => time.setTimeout(1000));```

f you mistakenly treated a promise as its resolved value, you can ensure it is properly resolved by using await or resolve on the promise. In some cases, you may need to use an "immediately invoked function expression" (IIFE):

(async function foo() {
  const result = await bar();
  // work with result
})();
If you forgot to handle the promise rejection, you should handle it either with .catch(error β‡’ {/…​/}) or .then(result β‡’ {}, error β‡’ {}).

Noncompliant code example
const promise = new Promise((resolve, reject) => {
  // ...
  resolve(false)
});
if (promise) {
  // ...
}
Compliant solution
const promise = new Promise((resolve, reject) => {
  // ...
  resolve(false)
});
if (await promise) {
  // ...
}
Noncompliant code example
const p = new Promise(async (resolve, reject) => {
  doSomething('Hey, there!', function(error, result) {
    if (error) {
      reject(error);
      return;
    }
    await saveResult(result)
    resolve(result);
  });
});

await p;
Compliant solution
const p = new Promise((resolve, reject) => {
  doSomething('Hey, there!', function(error, result) {
    if (error) {
      reject(error);
      return;
    }
    resolve(result);
  });
});

const result = await p;
await saveResult(result);
Noncompliant code example
apiCalls.forEach(async (apiCall) => {
  await apiCall.send();
});
Compliant solution
for (const apiCall of apiCalls) {
  await apiCall.send();
}
Noncompliant code example
fetch('https://api.com/entries')
  .then(result => {
    // ...
  });
Compliant solution
fetch('https://api.com/entries')
  .then(result => {
    // ...
  })
  .catch(error => {
    // ...
  });
How does this work?
In JavaScript, a promise is a mechanism to perform tasks asynchronously. To this end, the language provides the Promise object which represents the eventual completion or failure of an asynchronous operation and its resulting value. A promise can be created with the Promise constructor accepting an executor function as an argument, which has resolve and reject parameters that are invoked when the promise completes or fails.

The logic of the promise is executed when it is called, however, its result is obtained only when the promise is resolved or awaited.```

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.