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
Feat/callbacks error and success #7946
Conversation
f2ebaa8
to
b6f8a6f
Compare
Hi @dhoko Thanks for the PR. I don't know if we need this (it's quite complicated).
(I didn't test it). would it work for you? if so feel free to update your PR |
The default solution does not work as expected, it's triggered too many times and we cannot detect if the request is a success or an error cf: I can change the implementation by using too arguments instead of one object: trackEvent(category, action, name, value, {success,error});
// to
trackEvent(category, action, name, value, onSuccess, onError); What do you think ? |
@@ -5148,9 +5219,9 @@ if (typeof Piwik !== 'object') { | |||
* @param string name (optional) The Event's object Name (a particular Movie name, or Song name, or File name...) | |||
* @param float value (optional) The Event's value | |||
*/ | |||
trackEvent: function (category, action, name, value) { | |||
trackEvent: function (category, action, name, value, callbacks) { |
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.
Is callbacks
a common name for that? Reading that parameter I expected to pass an array of callbacks. Also it needs to be documented as a parameter. Shall we maybe rather still use callback
, especially since a function callback would work as well? Or is it maybe worth to use a settings
object to allow {success: function()..., error: function ()...}
that would be okay for me as it is optional anyway. Just to avoid having to add many more optional parameters in the future.
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.
There are methods like trackLink
that currently expect callback
. We'd need to make sure to use consistent naming and behaviour and to maintain backwards compatibility.
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.
Yup we can use onSuccess, onError
1 more argument to the function. I doesn't break the compatibility cf L2513
// Compatibility for eventLink
if('function' === typeof cb) {
I didn't look, but maybe there is a way to "fix" the default solution so it can do what you need as well as keeping BC for those who may be using the |
The meaning of this PR wasn't to rewrite the current callback system. I try to improve it and fix it. Today with Piwik:
Bonus: it doesn't break the compatibility. Why ? Because I am working with a mobile app, I cannot do a request for each event (it's expensive) so I need to put these items to a cache (localStorage) and send my events after a . |
b6f8a6f
to
29b697e
Compare
29b697e
to
596fc7e
Compare
Hi @dhoko - Do you still think we should merge this PR? if so please leave a comment, and we will take another look... For sure, we would need to have automated tests as well ( |
Yup, I will try to write some tests. I don't know Qunit yet, i work with Jasmine. |
class already extends BaseFactory with class name & error msg overrides
Fix piwiki
Fix cb declaration
596fc7e
to
0aa454c
Compare
Something is fucked up with my fork. Sorry for the mess, I will create a new PR. |
Hi,
We cannot add a callback to detect both error and success for GET and POST.
Now, with trackEvent we can set an object as the fifth argument to set callbacks.