These are chat archives for canjs/canjs

14th
Jul 2016
Jeremy Miller
@jjm340
Jul 14 2016 00:59
I'll be damned, that worked!
Carl von Buelow
@cvbuelow
Jul 14 2016 15:57
Is there a way to intercept all canjs ajax requests and modify or replace the request?
@cvbuelow ^
which is aliased to can.ajaxSetup
Carl von Buelow
@cvbuelow
Jul 14 2016 16:56
yeah i looked at that. i thought you could only set defaults with that
Michael Price
@web-mech
Jul 14 2016 17:07
you can modify almost every aspect of your requests in the settings param
https://api.jquery.com/jQuery.ajax/ - look at converters, beforeSend, complete, etc
Carl von Buelow
@cvbuelow
Jul 14 2016 17:19
ok thanks. i don't think this allows me to do an interception the way i need though, i.e. pause the request, do some other async stuff, resume the request
Michael Price
@web-mech
Jul 14 2016 17:25
gotcha, that should allow you to do some of your own manual manipulation though, i.e. abort / retry the request, each event delegate receives a raw xhr object as the first param, its up to you from there pretty much
you can also resort to overriding the raw jquery ajax method yourself but anti-pattern
Carl von Buelow
@cvbuelow
Jul 14 2016 17:32
ok how do i retry the request using the raw xhr object?
Michael Price
@web-mech
Jul 14 2016 17:34
but there are ton of jQuery ajax retry libs out there, just find one that suits you/your code style
here is a super basic one https://gist.github.com/aeurielesn/2511005
Carl von Buelow
@cvbuelow
Jul 14 2016 17:39
right, i need to do it in beforeSend though so I can do other async stuff first and then send the original request, so technically not a retry i guess, more like pause and continue
Michael Price
@web-mech
Jul 14 2016 17:40
sounds like a control flow issue, what async thing are you trying to do before the request?
Carl von Buelow
@cvbuelow
Jul 14 2016 17:41
a fetch request
Michael Price
@web-mech
Jul 14 2016 17:43
This message was deleted
Thomas Sieverding
@Bajix
Jul 14 2016 17:43
Why’re you trying to do this via intercepting ajax calls?
Use can-connect and make new behaviors, or otherwise do this sort of thing elsewhere
Carl von Buelow
@cvbuelow
Jul 14 2016 17:48
doing it at a lower level allows me to do it in one place instead of modifying my code everywhere i'm making an ajax request, which given the codebase is not a realistic option
Thomas Sieverding
@Bajix
Jul 14 2016 17:48
What’s your use-case?
Carl von Buelow
@cvbuelow
Jul 14 2016 17:51
it's for when session expiration occurs. if the user's session is expired and they make some ajax calls in parallel then each call returns a new session. to avoid this we want to intercept the calls (pause them), get a new session using a single call, then resume the other calls
Thomas Sieverding
@Bajix
Jul 14 2016 17:52
Yea, that’s not how sessions work
You should fix your server side session management instead
You should use something like that to intercept errors, and then route them to login if there’s a 401
Carl von Buelow
@cvbuelow
Jul 14 2016 17:55
lol that's how they work for us unfortunately. changing the server side is not an option
this is for anonymous user sessions
Sunil George
@georgesunil81
Jul 14 2016 19:02
A quick question about stache. I have a need to do some calculations with stache curly-fields. Can I do something like {{pageNumber + 1}}?
It does not work!
Is there a way to some simple calculations like that within stache?
Kevin Phillips
@phillipskevin
Jul 14 2016 19:03
you’ll have to use a helper
Michael Price
@web-mech
Jul 14 2016 19:03
@georgesunil81 you should use a helper for that
Sunil George
@georgesunil81
Jul 14 2016 19:03
Oh! ok.
Sunil George
@georgesunil81
Jul 14 2016 19:48
When I pass in values into the helper function, it gets converted into a string with the actual function code! Not sure why that is happening!?
I am using the helper as {{addPageNumber pageNumber}}
'addPageNumber': function(pagenumber) {
console.log(pagenumber);
         return "test";
    },
the console.log actually prints out function code!
Any idea why that would be happening?
Michael Price
@web-mech
Jul 14 2016 20:10
@georgesunil81 its a compute
invoke that param and it will be your value
Kevin Phillips
@phillipskevin
Jul 14 2016 20:27
or use call expressions
{{addPageNumber(pageNumber)}}
which get the value by default, instead of a compute
:point_up: @georgesunil81
Sunil George
@georgesunil81
Jul 14 2016 21:37
Ah!