Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Enhancement Discussion: Wildcard Require - goog.require('namespace.*');
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Guido Tapia  
View profile  
 More options May 3 2012, 1:09 am
From: Guido Tapia <guido.ta...@gmail.com>
Date: Wed, 2 May 2012 22:09:36 -0700 (PDT)
Local: Thurs, May 3 2012 1:09 am
Subject: Enhancement Discussion: Wildcard Require - goog.require('namespace.*');

Guys this is a feature I would love to see in the compiler (and support in
linter if required and any other related projects).  This would allow code
like the following:

goog.require('namespace.*')

...

findHandlerForRequest(request) {
  for (var clazz in namespace ) {
    var handler = new clazz();
    if (handler.supports(request) {
       handler.run(request);
       return;
    }
  }
  throw new Error('Could not find a handler for request');

}

I don't know what this pattern is called (auto discovery??).  Anyways,
currently closure code always violates the open/closed principle because
any client of an interface must always be aware of all implementations by
having to explicitly define all goog.requires.

This to me sounds like a major enhancement so I put it here for discussion
as its not a huge deal but it would be nice. I'm also a bit intimidated by
the compiler code so since I wouldn't be implementing this I don't feel I
have the right to add a proper enhancement request.

Any comments? Is this even possible with the current
compiler/depsbuilder/linter design?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chad Killingsworth  
View profile  
 More options May 3 2012, 2:18 pm
From: Chad Killingsworth <chadkillingswo...@missouristate.edu>
Date: Thu, 3 May 2012 11:18:36 -0700 (PDT)
Local: Thurs, May 3 2012 2:18 pm
Subject: Re: Enhancement Discussion: Wildcard Require - goog.require('namespace.*');

Isn't this possible with @interface?

/** @interface */
function MyInterface() {}

/**
 * @param {*} obj
 * @return {boolean}
 */
MyInterface.prototype.supports = function(obj) {};

/** @param {*} obj */
MyInterface.prototype.run = function(obj) {};

/** @type {Object.<string, MyInterface>} */
var namespace = {};

/**
 * @constructor
 * @implements {MyInterface}
 */
function Class1() {}
...

namespace.Class1 = Class1;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Lenz  
View profile  
 More options May 3 2012, 2:21 pm
From: John Lenz <concavel...@gmail.com>
Date: Thu, 3 May 2012 11:21:14 -0700
Local: Thurs, May 3 2012 2:21 pm
Subject: Re: [closure-compiler-discuss] Enhancement Discussion: Wildcard Require - goog.require('namespace.*');

Off the top of my head, I don't know of anything that would prevent the
wild cards in the requires.

Iterating over members of a namespace is not something that is supported by
ADVANCED compilation, so an alternate registration/discovery mechanism
would be needed, but that doesn't change the core of this proposal.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido Tapia  
View profile  
 More options May 3 2012, 5:49 pm
From: Guido Tapia <guido.ta...@gmail.com>
Date: Thu, 3 May 2012 14:49:21 -0700 (PDT)
Local: Thurs, May 3 2012 5:49 pm
Subject: Re: [closure-compiler-discuss] Enhancement Discussion: Wildcard Require - goog.require('namespace.*');

@Chad: Interfaces are fully supported but discovery of types is not.  All
clients must be aware of the concrete implementations of their services (by
having to goog.require them).
@John: I'm not hung up on the discovery approach.  The goog.reflect module
would also be a good candidate.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Naze  
View profile  
 More options May 3 2012, 6:27 pm
From: Nathan Naze <nn...@google.com>
Date: Thu, 3 May 2012 15:27:35 -0700
Local: Thurs, May 3 2012 6:27 pm
Subject: Re: [closure-compiler-discuss] Enhancement Discussion: Wildcard Require - goog.require('namespace.*');
The linter does not know about other namespaces -- it cannot know
without scanning the entire fileset.  It only looks at one file at a
time.  Therefore, it can't dereference wildcards.

Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Lenz  
View profile  
 More options May 3 2012, 7:51 pm
From: John Lenz <concavel...@gmail.com>
Date: Thu, 3 May 2012 16:51:08 -0700
Local: Thurs, May 3 2012 7:51 pm
Subject: Re: [closure-compiler-discuss] Enhancement Discussion: Wildcard Require - goog.require('namespace.*');

Nathan,

I don't see the linter's precision as a show stopper, it will already
happily let you "require" non-existent things or non-existent inner types.
 The linter would simply say "you've required the correct namespace to
fullfill the requirements for this file".  This is effectively what it does
now anyway.

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »