You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #264 Send data back and forth as JSON (weaverryan)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
Send data back and forth as JSON
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| Tickets | Fixes#251 (a bit unrelated, but it fixes it)
| License | MIT
tl;dr the "data" of your component is now sent via JSON for the Ajax calls. Ajax calls are still made via `GET` (unless you're triggering an action or your data is too long) with a new `?data={... json}`.
**Longer Explanation**
Until now, I've been trying to send data back to the server as `?query` params or as POST data (which is just query params stored in the body of the request).
However, using query parameters simply isn't robust enough. Most notably, it makes handling `null` values impossible. If you have a LiveProp - e.g. `firstName` - on the server set to `null`, how should that be sent back to the server? As `?firstName=`? In that case, how do you distinguish from an empty string? One option is to NOT send `firstName` at all on the Ajax request. But then, what if you have a `LiveProp` that is an array with `['firstName' => null]`? If we don't send `firstName`, the array will dehydrate to an empty array.
In the end, the goal is to effectively "freeze" your component's data, send it to the frontend, and have the frontend send it back. Using query parameters simply isn't robust enough to do this without, but JSON is.
There is no real downside to this: it just felt more pure to send data back and forth as query parameters and return HTML. We still return HTML, but sending JSON will make the behavior solid.
Commits
-------
2b808ea Send data back and forth as JSON
0 commit comments