-
Notifications
You must be signed in to change notification settings - Fork 28
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
[email protected] compliance #77
base: master
Are you sure you want to change the base?
Conversation
xhr @v2.3 suggests that the `json` option should be a boolean, and the data should be set on `body`. While the behaviour is backwards compatible, I figure it would be a good idea to match its behaviour.
…where the explicitly provided body should take precedence over the model’s data.
@@ -82,7 +83,7 @@ module.exports = function (xhr) { | |||
// For older servers, emulate JSON by encoding the request into an HTML-form. | |||
if (options.emulateJSON) { | |||
params.headers['content-type'] = 'application/x-www-form-urlencoded'; | |||
params.body = params.json ? {model: params.json} : {}; | |||
params.body = params.json ? {model: params.body || params.json} : {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to think of the condition where params.json would be true, and there would be no params.body. This would result in params.body being set to {model: true}
which seems incorrect.
If params.json
is true
, it means new lines 70 and 71 ran above, which means params.body
has to be set to either options.attrs
or model.toJSON(options)
. So at the bare minimum it's already set to {}
;
Following this logic I believe that this line should read:
params.body = params.json ? { model: params.body } : {};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you're right.
The case this was attempting to address was if somebody passed a non-boolean truthy value to json
in options
. Except now I realize this is json
in params
, which will always be (true || undefined).
Making this change shortly.
This looks great, thanks for staying on top of this change. +1 from me |
Great thinking, this could have been considered a bug before! |
@naugtur tests have been broken across all Ampersand modules for about a year now :( I don't have the expertise or access to fix the CI tests. |
👍 |
Tests ran from PRs from external repos will always fail, only tests made from PRs from local branches will run. |
Recently, xhr clarified its behaviour for the
json
option, suggesting thatjson
is flipped on/off, and thebody
is instead set to… the body. This has the side effect of preventing true/false being sent as a value via thejson
option, but is otherwise backwards compatible.This PR is mostly to bring ampersand-sync inline with how xhr prefers its data, but also solves one very specific, confusing use case that would fail (without this PR). I'll try to explain it:
In short, this should make
.sync
options behaviour more congruent withxhr
'soptions
behaviour. While usingbody
is not an option specified within ampersand-sync's documentation, anddata
should probably be the preferred way to pass data, sometimes it's tricky to remember which property to use (body or data) when switching between usingxhr
andampersand-sync
.Overall, this PR shouldn't introduce any breaking changes.