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

Update has.js #101

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

AndrewEastwood
Copy link

Adding requirejs config support

Adding requirejs config support
Added condition to extract plugin config
define("has", function(){
define("has", ['module'], function(module){
var moduleConfig = {};
if (typeof module.config === "function")
Copy link
Contributor

Choose a reason for hiding this comment

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

lets match the style:
==, no space between the if and the (, and use brackets {}.

Copy link
Author

Choose a reason for hiding this comment

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

It's ok to remove spaces but why do you want to use non-strict comparation for that? eqeqeq works faster and typeof always returns string

Copy link
Contributor

Choose a reason for hiding this comment

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

This code going to be hit a few million times is it? Naw, it's a micro-opt and counter to the existing style. Technically because typeof always returns a string the == is performing the same steps as ===.

@AndrewEastwood
Copy link
Author

ok, I removed third '='

if(typeof module.config == "function"){
moduleConfig = module.config() || {};
}
for (var propKey in moduleConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

The code style seems to favor hoisting vars out (it was a phase :P). So that would make it:

var propKey, moduleConfig;
if(typeof module.config == "function"){
  moduleConfig = module.config();
}
for(propKey in moduleConfig){

Copy link
Author

Choose a reason for hiding this comment

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

What if we just use simple code for this as @jrburke has done in https://github.com/requirejs/text/blob/master/text.js#L23

var moduleConfig = (module.config && module.config()) || {};
for(var propKey in moduleConfig){
    has.add(propKey, moduleConfig[propKey]);
}

something like that above

Copy link
Contributor

Choose a reason for hiding this comment

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

Naw, different project styles. We are consuming a foreign thing so have to be more cautious whereas that plugin expects to work with RequireJS and its constructs.

if(typeof module.config == "function"){
moduleConfig = module.config();
}
for (propKey in moduleConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

Soo close! Brackets + spacing of the for(

@AndrewEastwood
Copy link
Author

😄 what about now?

@jdalton
Copy link
Contributor

jdalton commented Jun 5, 2014

Can you add a unit test and have you signed the CLA?

@@ -149,7 +149,14 @@
// Expose has()
// some AMD build optimizers, like r.js, check for specific condition patterns like the following:
if(typeof define == "function" && typeof define.amd == "object" && define.amd){
define("has", function(){
define("has", ["module"], function(module){
var propKey, moduleConfig = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to init moduleConfig = {}; it can just be moduleConfig;.

@AndrewEastwood
Copy link
Author

alright. I've signed it just now 😀

@jdalton
Copy link
Contributor

jdalton commented Jun 5, 2014

CLA submitted on 2014-06-05 21:06:04.

@jdalton
Copy link
Contributor

jdalton commented Jun 5, 2014

So for the test it looks like runTests.html has require.js commented out. Maybe enable it below the other script loads, load it via AMD+config, & delay the population of the results until after the module is loaded. Whew.

@AndrewEastwood
Copy link
Author

omg! the version of requirejs is 0.14.5+
I'm gonna upgrade it to 2.1.14

@fn-zz
Copy link

fn-zz commented Jun 6, 2014

+1

@AndrewEastwood
Copy link
Author

I come up with that approach for tests or, we can rewrite all detects to use requirejs (:

@jdalton
Copy link
Contributor

jdalton commented Jun 11, 2014

I'll try to review this soon but can't make any promises 😞

@AndrewEastwood
Copy link
Author

This waits whole month for review 😒

@jdalton
Copy link
Contributor

jdalton commented Jul 9, 2014

Sorry, I haven't made time for this yet.

@AndrewEastwood
Copy link
Author

Howdy @jdalton! So, what's about this?

@jdalton
Copy link
Contributor

jdalton commented Sep 26, 2014

I gotta be honest, I'm not really an active contributor to this project anymore. If any other contributor has time to pick this up, review, & merge please have at it.

@AndrewEastwood
Copy link
Author

I see. Alright, let's put this on their decisions :)

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

Successfully merging this pull request may close these issues.

4 participants