Skip to content
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

Fix EZP-21666: refactor PromiseCAPI and PromiseService classes #24

Closed
wants to merge 6 commits into from

Conversation

wiseman17
Copy link
Contributor

JIRA issue: https://jira.ez.no/browse/EZP-21666
Classes are fixed and refactored. Tests are on the way...

@ezrobot
Copy link

ezrobot commented Nov 6, 2013

jshint with our configuration reports the following issues:

test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 8, col 13, Expected 'logRequests' to have an indentation at 5 instead at 13. (W015)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 9, col 9, Expected '}' to have an indentation at 1 instead at 9. (W015)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 12, col 5, Expected 'promiseContentService' to have an indentation at 1 instead at 5. (W015)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 13, col 81, Expected an assignment or function call and instead saw an expression. (W030)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 4, col 18, 'eZ' is not defined. (W117)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 6, col 13, 'eZ' is not defined. (W117)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 11, col 25, 'eZ' is not defined. (W117)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 12, col 5, 'promiseContentService' is not defined. (W117)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 13, col 5, 'promise' is not defined. (W117)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 13, col 15, 'promiseContentService' is not defined. (W117)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 15, col 1, 'promise' is not defined. (W117)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 1, col 49, 'CAPI' is defined but never used. (W098)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 1, col 49, 'SessionAuthAgent' is defined but never used. (W098)
test/manual/jsRestClientBundle/Resources/public/js/cookbook-PromiseCAPI.js: line 1, col 49, 'PromiseCAPI' is defined but never used. (W098)

14 errors

Silencing q false positive warning on rejection handling,
CS cookbook fixes
*
* @method generatePromiseService
* @param serviceFactory {function} function which returns one of the CAPI services
* @method getPromiseService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_getPromiseService
and it should be marked as protected

@wiseman17
Copy link
Contributor Author

do we really need this? it seems like a big dirty workaround to me

Workaround as opposed to what? Without this option Q library is throwing mentioned warnings whenever we are handling rejection cases (e.g. in real life - any error of any service).

@dpobel
Copy link
Contributor

dpobel commented Nov 7, 2013

as opposed to:

  1. verify that this line does not actually hide a useful information for the user of the REST Client (ie if he handles the error, the warning is gone)
  2. verify that the problem is not in our code and then fix the code not the consequences

And if it turns out that we really need to call this, please add this in a dedicated issue/commit with a proper commit log and with a proper inline comment because:

  1. that's not a refactoring, that's a new code
  2. given the diff of this PR, I'm pretty sure the same occurs before this patch
  3. referencing a confusing question on stackoverflow is not a good comment

@dpobel
Copy link
Contributor

dpobel commented Nov 7, 2013

and can you please create a gist with a valid code that allows to get this warning.

@wiseman17
Copy link
Contributor Author

as opposed to: ...

Both points are exactly what I have done before this fix. But, indeed, it should be done in more "systematic" way.

Should those gists be "executable"? Or just give a straight vision of the problem, like these 2:

This code does NOT throw the warning: https://gist.github.com/wiseman17/7356346
And this chunk does throw it: https://gist.github.com/wiseman17/7356371
The only difference basically is in line 14 - callback behavior.

It will take more time to make "executable" versions, but I can do that as well.

@dpobel
Copy link
Contributor

dpobel commented Nov 7, 2013

yeah, I'm more interested in a real usage of the REST client than in a excerpt of the unit tests.

@wiseman17
Copy link
Contributor Author

Here is the "real life" one: https://gist.github.com/wiseman17/7369604

Took some time, as it turned out that at least on Win7 the Chrome is NOT throwing this warning, but FF and IE do throw it all right :).

@wiseman17
Copy link
Contributor Author

Mentioned issues are fixed.
Indeed we can compare against pure key variable which simplifies things a bit.

@dpobel
Copy link
Contributor

dpobel commented Nov 12, 2013

so I guess, the double name declaration of the method name is not needed anymore ( myClass.prototype.myFunc = function myFunc() {}; can become myClass.prototype.myFunc = function () {};) ?

@wiseman17
Copy link
Contributor Author

That's true. Should I fix it in this on in a separate issue?

@dpobel
Copy link
Contributor

dpobel commented Nov 12, 2013

Since that's related to a change done in this PR, that should definitively be done here as well.

@wiseman17
Copy link
Contributor Author

Done.

@@ -531,7 +531,7 @@ define(["structures/ContentTypeGroupInputStruct", "structures/ContentTypeCreateS
* @param callback {Function} callback executed after performing the request (see
* {{#crossLink "ContentTypeService"}}Note on the callbacks usage{{/crossLink}} for more info)
*/
ContentTypeService.prototype.updateContentTypeDraftMetadata = function updateContentTypeDraftMetadata(
ContentTypeService.prototype.updateContentTypeDraftMetadata = function (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the line change for the parameters is not needed anymore. And the same applies for the loadContentTypeGroupByIdentifier and updateContentTypeDraftMetadata methods.

@dpobel
Copy link
Contributor

dpobel commented Nov 12, 2013

besides my last inline comments, +1

this[key] = this.generatePromiseService(this._capi[key]);
for (key in CAPI) {
if ( (typeof CAPI[key] === "function") && (/^(get[^\s(]+Service)/).test(key) ) {
console.log(key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log !

@wiseman17
Copy link
Contributor Author

Merged

@wiseman17 wiseman17 closed this Nov 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants