Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recommendation on how to handle unsafe async / remote fetch functions #39

Closed
silesky opened this issue Jan 25, 2021 · 4 comments · Fixed by #78
Closed

Add recommendation on how to handle unsafe async / remote fetch functions #39

silesky opened this issue Jan 25, 2021 · 4 comments · Fixed by #78

Comments

@silesky
Copy link

silesky commented Jan 25, 2021

Currently the only fetch example is:

function fetchPosts(postCount) {
return fetch('https://api.dev/posts', {...})
}

“Fetch” is a synonym for get, and it — on its own —- implies a safe operation. How should we name unsafe operations that are also async, like update / delete etc?

to continue this pattern, we would expect:

  • fetchPost
  • fetchDeletePost
  • fetchCreatePost
    ... etc

Or, do we just forget the fetch altogether?

I’d like to propose just dropping the “fetchFoo” completely from the style guide, and not distinguish between fetching from a remote service or any other synchronous or asynchronous internal “getFoo” function.

The semantics of “fetchFoo” only differ from “getFoo” in that they encode a data type in the name (a promise), which is a potential code smell. (see #37)

@silesky silesky changed the title Asynchronous non-get functions unsafe async / remote fetch functions Jan 25, 2021
@silesky silesky changed the title unsafe async / remote fetch functions How to handle unsafe async / remote fetch functions Jan 25, 2021
@silesky silesky changed the title How to handle unsafe async / remote fetch functions Add recommendation on how to handle unsafe async / remote fetch functions Jan 25, 2021
@kettanaito
Copy link
Owner

Hey, @silesky. Thanks for raising this.

I think the original suggestion of fetchPosts isn't the best one. I'd rather call it getPosts to highlight a data retrieval operation. In regards to other async actions, I'd name them after what they represent:

  • createPost
  • updateUser
  • deleteUser

I see little value in a fetch prefix in these cases.

What do you think about this?

@silesky
Copy link
Author

silesky commented Feb 1, 2021

Hey, @silesky. Thanks for raising this.

I think the original suggestion of fetchPosts isn't the best one. I'd rather call it getPosts to highlight a data retrieval operation. In regards to other async actions, I'd name them after what they represent:

  • createPost

  • updateUser

  • deleteUser

I see little value in a fetch prefix in these cases.

What do you think about this?

Completely agree!

@kettanaito
Copy link
Owner

Do you think we should remove the "fetch" action from the suggested ones?

@silesky
Copy link
Author

silesky commented Feb 1, 2021

Do you think we should remove the "fetch" action from the suggested ones?

Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants