ljharb on master
[eslint config] [base] [patch] … [eslint config] [patch] extend … Merge pull request #1996 from r… (compare)
ljharb on master
[editorial] [react] fix typo [eslint config] [*] [deps] upda… (compare)
Can anyone please explain this part of the airbnb style guide to me?
https://github.com/airbnb/javascript#arrays--mapping
It says:
4.6 Use Array.from instead of spread ... for mapping over iterables, because it avoids creating an intermediate array.
// bad
const baz = [...foo].map(bar);
// good
const baz = Array.from(foo, bar);
But I don't understand why you wouldn't instead do:
const baz = foo.map(bar);
foo.map(bar)
is fine. If it's a non-array iterable
, then use Array.from
to prevent converting to an array just to use map
11.2 Don’t use generators for now.
Why? They don’t transpile well to ES5.
React
portion of the guide to be updated further? Given the way it refers to function components as stateless
and only recommending them if you don't have state or refs, I feel like it hasn't been updated to reflect the introduction of hooks
Hi there
I have an async function which I would like to convert to an Observable stream (using rxjs operators). The await
calls must execute in the order they appear in the function.
async authenticateUser(profile: Profile): Promise<any> {
let authCookie: any;
try {
authCookie = await getCookie();
} catch (error) {
console.error(error);
}
if (!authCookie || authCookie?.length < 1) {
cancelAuthenticationCookieGet();
throw {message: "login failed", status: -2};
}
await saveProfileAsync(profile);
await storeCurrentAuthCookieAsync(authCookie);
storeSessionStorage();
await setPartitionSessionCookie(profile.url, authCookie);
}
Is there a clean way to accomplish the above?
description is :
Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output. You can also manipulate, traverse, and in some ways simulate runtime given the output.
jest
yarn create react-app ...
and by default I got setupTests.js
file with import '@testing-library/jest-dom/extend-expect';
@testing-library...
packages
setupTests.js
file according to the enzyme
test runner instead of default @testing-library...
@helper
)? For example, a form to let user write setting for servers, we don' t know how many settings they will make so we use a Form(serversetting:List[ServerSetting]) serversetting->list(mapping(id->number,purpose->Text)(ServerSetting.apply)(ServerSetting.unapply))
data structure. In this case, what is the best way to write the html code?