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

Fixing toJson #4

Open
0x-r4bbit opened this issue Mar 18, 2014 · 5 comments
Open

Fixing toJson #4

0x-r4bbit opened this issue Mar 18, 2014 · 5 comments

Comments

@0x-r4bbit
Copy link
Contributor

sofa.Util.toJson still handles stupid backend response. Despite from the fact that the backend should be fixed accordingly, it also introduces a side effect as you can see in line 348 https://github.com/sofa/sofa-core/blob/master/src/sofa.util.js#L357-L371.

Any updates on the backend handling?

We should make the toJson method behave like one would expect when using a toJson method. Therefore I would recommend either introducing a separate method that uses toJson and adds the side effect, or introducing a parameter to control wether we want toJson behave like ass or not.

@cburgdorf @nickjanssen thoughts anyone?

Background is that I need this method in sofa.HttpService. Of course, the places where our http service is used only calls our backend, which means calling the current toJson on top of that with the side effect would actually be the right thing.

But to do things "right" we should expect that one can use the http service for other endpoints too!

@nickjanssen
Copy link
Contributor

I think that function is badly named, since there is already JSON.parse(), causing confusion to what this toJson does. Better would be toBackendJson() or something. In the cases where you don't want the hacks you can just use JSON.parse instead, so why make a new one or add parameters?

@0x-r4bbit
Copy link
Contributor Author

Well of course you are right. It would basically be a function that wraps JSON.parse().

@0x-r4bbit
Copy link
Contributor Author

Or actually, JSON.parse() would be used in a fromJson function (which I'm currently implementing). JSON.stringify() would be used in toJson() instead.

@cburgdorf
Copy link
Member

I agree with @nickjanssen that this method is named badly. It's not at all converting anything to JSON. It's the other way around. It's parsing a JSON string into a JavaScript object. So it should rather be something like parseLegacyJson or something like that. But @PascalPrecht why do you actually need that from inside the HttpService. The HttpService just like Angular's $http service should not know about our backend hacks.

@0x-r4bbit
Copy link
Contributor Author

This went hand in hand with the toJson method that is actually used inside $http service. Of course it doesn't know about backend hacks. But this method does bullshit compared to the name.

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

3 participants