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

I think computed method shouldn't have side effect #30

Closed
duxinxiao opened this issue May 2, 2018 · 2 comments
Closed

I think computed method shouldn't have side effect #30

duxinxiao opened this issue May 2, 2018 · 2 comments

Comments

@duxinxiao
Copy link

Thanks for all of your work, but I think making computed method async is anti vue's design. In my opinion, I think computed method shouldn't change any state or make api call. If you must, I think you'd better use 'watch' instead.

@foxbenjaminfox
Copy link
Owner

foxbenjaminfox commented May 2, 2018

Well, you certainly don't have to use vue-async-computed if you don't want to 😃.

Not every Vue plugin fits with everybody's preferred style, so it's perfectly fine that this one doesn't fit with yours. For what it's worth, I agree with you that computed methods shouldn't try to avoid changing state, either locally or remotely. But there's still plenty of room for making API calls that are safe and idempotent, such as HTTP GET requests.

Such computed properties are, in my opinion, not really any less pure than ones which depend purely on local state. Yes, behind the scenes there is some hidden state (that vue-async-computed is handling for you), but the end result is an abstraction that let's you treat it just as purely and unstatefully as any local data.

I think there is power in such abstractions. Vue itself keeps and modifies some hidden state when watching for data changes, and that's fine: the interface that it exposes uses these implementation details behind the scenes, but doesn't expose them.

My goal is for vue-async-computed to do much the same. I like to think that I managed, and that the result is useful. I even think that it functions in much the same ways as Vue's internals, and so is very much in sync with Vue's philosophy.

Of course, it's OK to disagree: if you feel that you don't want to use this plugin, there's nothing wrong with that, and you are certainly free to write your own Vue applications in whatever way you feel is best for you. But I do hope that you understand a bit better now, after my explanation, why I don't think that there is anything wrong with asynchronous computed methods, if used responsibly.

@duxinxiao
Copy link
Author

Thanks for your patiently reply, I get a better understanding of your design purpose. I think it fine to handle GET requests or something like that ( just like you said, you handle the hidden state for users, make a easy to use api ). It's cool to share your thoughts, thanks for your work

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

No branches or pull requests

2 participants