forked from extern/naming-cheatsheet
docs: remove "fetch", prefer "get" (#78)
This commit is contained in:
parent
99ff58ce66
commit
b392481dae
27
README.md
27
README.md
@ -161,6 +161,15 @@ function getFruitCount() {
|
|||||||
|
|
||||||
> See also [compose](#compose).
|
> See also [compose](#compose).
|
||||||
|
|
||||||
|
You can use `get` when performing asynchronous operations as well:
|
||||||
|
|
||||||
|
```js
|
||||||
|
async function getUser(id) {
|
||||||
|
const user = await fetch(`/api/user/${id}`)
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### `set`
|
### `set`
|
||||||
|
|
||||||
Sets a variable in a declarative way, with value `A` to value `B`.
|
Sets a variable in a declarative way, with value `A` to value `B`.
|
||||||
@ -194,16 +203,6 @@ resetFruits()
|
|||||||
console.log(fruits) // 5
|
console.log(fruits) // 5
|
||||||
```
|
```
|
||||||
|
|
||||||
### `fetch`
|
|
||||||
|
|
||||||
Request for some data, which takes some indeterminate time (i.e. async request).
|
|
||||||
|
|
||||||
```js
|
|
||||||
function fetchPosts(postCount) {
|
|
||||||
return fetch('https://api.dev/posts', {...})
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `remove`
|
### `remove`
|
||||||
|
|
||||||
Removes something _from_ somewhere.
|
Removes something _from_ somewhere.
|
||||||
@ -241,7 +240,7 @@ Creates new data from the existing one. Mostly applicable to strings, objects, o
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function composePageUrl(pageName, pageId) {
|
function composePageUrl(pageName, pageId) {
|
||||||
return (pageName.toLowerCase() + '-' + pageId)
|
return pageName.toLowerCase() + '-' + pageId
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -343,11 +342,11 @@ function renderPosts(posts, minPosts, maxPosts) {
|
|||||||
Indicate the previous or the next state of a variable in the current context. Used when describing state transitions.
|
Indicate the previous or the next state of a variable in the current context. Used when describing state transitions.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
function fetchPosts() {
|
async function getPosts() {
|
||||||
const prevPosts = this.state.posts
|
const prevPosts = this.state.posts
|
||||||
|
|
||||||
const fetchedPosts = fetch('...')
|
const latestPosts = await fetch('...')
|
||||||
const nextPosts = concat(prevPosts, fetchedPosts)
|
const nextPosts = concat(prevPosts, latestPosts)
|
||||||
|
|
||||||
this.setState({ posts: nextPosts })
|
this.setState({ posts: nextPosts })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user