-
Notifications
You must be signed in to change notification settings - Fork 114
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
Double backslashes on double quotes in serialized Flux state? #174
Comments
@jedrichards I ran into this same issue and just stopped serializing/deserializing in my store's static methods so they look like this.
Which gives me this warning.
Which is untrue because I get back a JSON string and it all works great. |
Aha yes, nice one. That's simpler :) Yeah, I think there's something a bit funny going on. Like you say, either the docs, warning, method naming or implementation could probably be changed to make things clearer. I would expect to return properly serialized data from a method named |
Yeah, the double serializing is a real problem. Right now The outer JSON is so simple, what if we wrapped it explicitly without stringifying the whole thing? |
Something like:
|
Yeah, that could work ... Alternatively you could double up on backslashes in the ouput, something like, return JSON.stringify(stateTree).split('\\').join('\\\\'); at https://github.com/acdlite/flummox/blob/master/src/Flux.js#L253 |
@jedrichards is this solved? |
I think this either needs solving in the library itself, or in the docs. As it is the serialisation API is quite confusing, and doesn't work as advertised. I'd be happy to put together a PR if people thought I was on the right track with the suggestion in my previous comment? Alternatively feel free to close this if you'd rather. |
@jedrichards I just submitted a PR that removes the warning and adds some explanation to the docs. We'll see if that's a problem for anyone but that's how I'm using it in my project. |
Hey
I have a simple store that serializes plain JS objects like so,
And when I call my flux's serialize method server side I get a string somewhat like this (the escaped quotes being due to the fact that first I stringify the store and then you stringify the whole store tree, effectively double stringifying some parts of the output),
I put this string into my app template (using Handlebars) and it ends up rendered on the page something like,
The problem is that when I call
flux.deserialize(stateString)
in the client it chokes on it, specificallyJSON.parse
throws a wobbly. Afaiu this is because by the timestateString
has been parsed into a string literal JS has striped out the backslashes (as expected), so that when I print it out in the console it looks like,I don't really know what's going on there, aside from the fact that
JSON.parse
doesn't like it at all.Now, I can fix this by doubling up on the backslashes server side before rendering the string into the template. Doing something like this,
Which results in rendered template,
The above string feeds into
flux.deserialize()
quite happily and gets parsed properly and the app state recreated.Just wondering if you've come across this sort of thing before? Have you found yourself double escaping backslashes, is it the right way to go or am I being thick?
Thanks!
Great package btw! :)
The text was updated successfully, but these errors were encountered: