Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Adding ng-jq functionality, the ability to force jqLite or any other lib... #10761

Closed
wants to merge 1 commit into from

Conversation

mboudreau
Copy link
Contributor

...rary by name to be used for angular.element

Added unit tests to check that jq function returns the right result, but couldn't test adding a fake jQuery object without failing many other tests. Maybe this is better for e2e tests? I would add some, but couldn't figure out the structure.

@mboudreau
Copy link
Contributor Author

@mzgol @lgalfaso
Here's the new pull request that should fix ng-jq for angular master branch.

@mgol
Copy link
Member

mgol commented Jan 15, 2015

@mboudreau Thanks, I'll review it later today.

Note for the future - never commit anything to the master branch, this is probably the source of your problems. master should be used exclusively to pull from the upstream master so that you can easily have the same master locally as the latest master in the Angular repository.

Your changes should be made on a different branch that you can then easily rebase on top of master.

Another thing: if sth goes wrong it's not necessary to open a new PR; it's enough if you amend the commit, introduce changes, rebase on top of latest master and do "git push --force". GitHub will pick it up as long as the branch name doesn't change.

You can read this guide: http://contribute.jquery.org/commits-and-pull-requests/
This is for jQuery but things not related to commit message format are universal to working with most other open source projects, including Angular.

@mboudreau
Copy link
Contributor Author

@mzgol Thanks for the tips. I already knew about them, I just didn't want to mess up things for the Angular team and I figured a redo would of been simpler. Maybe not.

Either way, it's done now :P

@petebacondarwin Is there anything else you want me to do? Like add that public api?

@mgol
Copy link
Member

mgol commented Jan 16, 2015

@mboudreau Fire grunt test in terminal, you'll see a couple of linting errors, e.g. not exporting the jq variable (it needs to be added to the beginning of the file in the /* global block.

* (eg. jQuery).
*
* This directive is global for the whole of the angular library, hence the directive can only
* be added to the top-most HTML element.
Copy link
Member

Choose a reason for hiding this comment

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

This is not true as you're catching ng-jq anywhere in the document. I'd rather copy the text from ngCsp.js:

"put the ngJq directive on the root element of the application or on the angular.js script tag, whichever appears first in the html document."

so that it's advised to put it there but not claim it won't work otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Member

Choose a reason for hiding this comment

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

@mboudreau If you could rebase your PR over latest master after introducing remaining changes, that'd be great. It seems you branched at a commit that fails tests so it's impossible for your PR to pass tests because of that. It should be fine on latest master (am I right, @petebacondarwin?).

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect so @mzgol. Thanks for reviewing this one!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mzgol @petebacondarwin I just tried merging the upstream master to my local without issue, however, the build is still failing even after an npm/bower install/update. Same error as the CI build (unless there's something different on the build server that I'm missing locally):

error:   TypeError: Cannot read property '0' of undefined
    at _.groupBy.tap.tap.docTypes.directive (/home/michelb/Work/angular.js/docs/config/processors/pages-data.js:65:43)
    at Function.tap (/home/michelb/Work/angular.js/node_modules/lodash/dist/lodash.js:6448:7)
    at lodash.ctor.(anonymous function) [as tap] (/home/michelb/Work/angular.js/node_modules/lodash/dist/lodash.js:5924:31)
    at /home/michelb/Work/angular.js/docs/config/processors/pages-data.js:62:14
    at /home/michelb/Work/angular.js/node_modules/lodash/dist/lodash.js:3513:29
    at forOwn (/home/michelb/Work/angular.js/node_modules/lodash/dist/lodash.js:2105:15)
    at Function.map (/home/michelb/Work/angular.js/node_modules/lodash/dist/lodash.js:3512:9)
    at lodash.ctor.(anonymous function) [as map] (/home/michelb/Work/angular.js/node_modules/lodash/dist/lodash.js:5924:31)
    at navGroupMappers.api (/home/michelb/Work/angular.js/docs/config/processors/pages-data.js:53:10)
    at /home/michelb/Work/angular.js/docs/config/processors/pages-data.js:192:28

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure you're on a latest master? If you're on Linux/OS X, could you invoke:

git show -s --format=%ci `git merge-base HEAD master` | head

? This should show you a date from today or yesterday; if it's older, it means you didn't rebase over latest changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mzgol 2015-01-21 09:53:33 +1100 is the output.

Everything looks good to me, I got all the changes. Dunno what I'm missing to build...

Apparently, Travis is having issues too, so I don't know what's going on. Weird stale files somewhere?

@mgol
Copy link
Member

mgol commented Jan 16, 2015

@petebacondarwin Is there anything else you want me to do? Like add that public api?

csp needed to be exposed to $sniffer as it's used later in the code. jq is needed only during bootstrap, the rest is left to the chosen library so I think we're good.

@mgol
Copy link
Member

mgol commented Jan 16, 2015

@mboudreau This looks mostly good, only a couple of remarks. 👍

@mboudreau
Copy link
Contributor Author

@mzgol Added the fixes from your comments. Cheers.

@mboudreau
Copy link
Contributor Author

@mzgol @petebacondarwin Build still failing after merge from upstream. Anyone care to help me debug? I'm trying to understand this document processor code, but there's a lot of abstraction...

@gkalpak
Copy link
Member

gkalpak commented Jan 21, 2015

I don't know for sure, but adding @module ng in the directive's ngdoc might help.

* @ngdoc directive
* @name ngJq
*
* @element html
Copy link
Member

Choose a reason for hiding this comment

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

Why specifically html ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be ANY I think

@mboudreau
Copy link
Contributor Author

@gkalpak Thanks for that. That indeed fixed it.

I also added all prefixes to the directive. Thanks for your direction :)

@mboudreau
Copy link
Contributor Author

@mzgol CI still failing, but not because of my code:

ScriptTimeoutError: Timed out awaiting response to command "switchToFrame" after 30000 ms (WARNING: The server did not provide any stacktrace information)

Is there a way to restart the build? I'm fairly sure it's just me being unlucky :P

*/
var jq = function() {
if (isDefined(jq.name_)) return jq.name_;
var el;
Copy link
Member

Choose a reason for hiding this comment

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

Indentation should be 2 spaces (not tabs).

@gkalpak
Copy link
Member

gkalpak commented Jan 22, 2015

I restarted the flakey build and all is green now.
But I have left some inline comments... 😇

@@ -1457,7 +1510,9 @@ function bindJQuery() {
}

// bind to jQuery if present;
jQuery = window.jQuery;
var jqName = jq();
jQuery = jqName != null ? window[jqName] : window.jQuery;
Copy link
Member

Choose a reason for hiding this comment

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

I've missed it before: an empty ng-jq attribute should mean "use jqLite" and not "use the native detection algorithm" as it's done now. Otherwise it'll be impossible for people to opt in to jqLite if jQuery is included on the site which is one of the major points of this functionality. :)

Refs the above comment by @gkalpak.

@mboudreau
Copy link
Contributor Author

@gkalpak @mzgol Build's still failing. Getting script timeouts.

@mboudreau
Copy link
Contributor Author

@gkalpak @mzgol What's next gents? How do I get my little baby into Angular master?

jQuery = window.jQuery; // use default jQuery.
if (isDefined(jqName)) { // `ngJq` present
jQuery = jqName === null ? undefined : window[jqName]; // if empty; use jqLite. if not empty, use jQuery specified by `ngJq`.
}
Copy link
Member

Choose a reason for hiding this comment

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

Hm...I still see some tabs here 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gkalpak God damnit. Fixed now.

@lgalfaso
Copy link
Contributor

@mboudreau overall looks good, but can you please squash this into one commit?

…library by name to be used for angular.element

fixing linting and jshint comments, as per @mzgol request

fixing weird duplication of docs when merging

adding other ng prefixes to be added and test to jq(), fixing documentation error by adding @module ng, changing @element to be any

removing tabs, again.

removing jq._name = undefined; as not useful anymore

adding strict equality for tests

Adding better description of ng-jq, fixing tabs/spaces

changing the logic behind ngJq to be more robust; removing jQuery = window[jqName] for when jqName is empty string

replacing tabs for spaces
@mboudreau
Copy link
Contributor Author

@lgalfaso Done :)

@lgalfaso
Copy link
Contributor

lgalfaso commented Feb 4, 2015

landed as 09ee82d

@lgalfaso lgalfaso closed this Feb 4, 2015
@mboudreau
Copy link
Contributor Author

Woo! Thanks guys! @lgalfaso @gkalpak @mzgol @petebacondarwin

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants