remove old callbacks in Request.JSONP.request_map #1315

Merged
merged 2 commits into from Aug 12, 2015

Projects

None yet

4 participants

@SergioCrisostomo
Member

fixes #1293

Add option to remove old Request.JSONP.request_map callbacks. Defaults to false to be BC.

@DimitarChristoff
Member

since that's not official API (the stored responses) BC should be ignored
and data should be removed by default. anyone who's augmented it to use
request_map to cache results clearly know what they are doing and can
adjust their code accordingly imo.

On Tuesday, August 11, 2015, Sergio Crisostomo notifications@github.com
wrote:

fixes #1293 #1293

Add option to remove old Request.JSONP.request_map callbacks. Defaults to

false to be BC.

You can view, comment on, or merge this pull request online at:

#1315
Commit Summary

  • remove old callbacks in Request.JSONP.request_map

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#1315.

Dimitar Christoff

"JavaScript is to JAVA what hamster is to ham"
@D_mitar - https://github.com/DimitarChristoff

@arian
Member
arian commented Aug 11, 2015

Agreed with @DimitarChristoff

@SergioCrisostomo
Member

Nice feedback! will update soonish and ping back.

@anutron anutron and 1 other commented on an outdated diff Aug 11, 2015
Source/Request/Request.JSONP.js
@@ -119,19 +119,20 @@ Request.JSONP = new Class({
return !!this.running;
},
- clear: function(){
+ clear: function(index){
@anutron
anutron Aug 11, 2015 Member

Hmmm.

What if the index isn't passed in? If it's required, that's a breaking change.

What if the index passed in isn't the running request?

@DimitarChristoff
DimitarChristoff Aug 11, 2015 Member

it's not breaking because worst case scenario, it will just try to delete an undefined property.

I have a better fix which does not change the API - storing the index within the script tag, then auto deleting

http://jsfiddle.net/dimitar/frxnqj5q/1/

@anutron
anutron Aug 11, 2015 Member

Good stuff. Might suggest we used data-jsonp-index or something rather than the element attribute, but whatever, it doesn't matter really.

@DimitarChristoff
DimitarChristoff Aug 11, 2015 Member

i considered it but it's so short lived - initially even thought of storage but that meant storage gc when element is removed. i'd agree about data-prop as it ought to be slightly cheaper.

@DimitarChristoff
DimitarChristoff Aug 12, 2015 Member

easier fix still. one liner

    Request.JSONP.request_map['request_' + index] = function(){
        delete Request.JSONP.request_map['request_' + index];
        this.success(arguments, index);
    }.bind(this);

so
+ delete Request.JSONP.request_map['request_' + index];

@DimitarChristoff DimitarChristoff commented on the diff Aug 11, 2015
Specs/Request/Request.JSONP.js
@@ -52,4 +57,29 @@ describe('Request.JSONP', function(){
});
+ it('should clear the request callback map', function(){
@DimitarChristoff
DimitarChristoff Aug 11, 2015 Member

why don't we use function(done){ ... done() ... } for async but we have waitsFor(<ambiguous number>, fn);

@SergioCrisostomo
SergioCrisostomo Aug 12, 2015 Member

@DimitarChristoff: we are still using Jasmine 1.3 and the done() API is from 2.0. We can do that upgrade in another PR, that would be good.

@SergioCrisostomo
Member

Updated again. No index anymore and using Dimitar's oneliner, much better idea.

@SergioCrisostomo
Member

Nice! Yeah, that index was already there from before and is unused. Will cherry pick your work and use it. thanks!

Sent from my iPhone

On 12 aug 2015, at 12:19, Dimitar Christoff notifications@github.com wrote:

@SergioCrisostomo check master...DimitarChristoff:SergioCrisostomo-fix1293 - missed an index and such.


Reply to this email directly or view it on GitHub.

@SergioCrisostomo SergioCrisostomo merged commit 5f286e7 into mootools:master Aug 12, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment