1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    423
    Answers
    23
    Vote Rating
    153
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default Unanswered: Preventing Namespace Collisions

    Unanswered: Preventing Namespace Collisions


    Hello, I'm new to ExtJS and had a question about namespaces. I understand the reasons to use them (for organization and to prevent class collisions within an application).

    In Java, the norm is to create packages with very specific names. These can often be long, e.g. "com.mycompany.widgets.gwt.myapp.controller", etc.

    The reasons for this are probably obvious, since building a Java app essentially merges all of the namespaces of all of the libraries in use, so careful thought must be given to prevent overlap and collisions.

    When it comes to Ext namespaces, is this as much of a concern? If a single web page has separate iframes or windows in it (like a portal), is there a danger that namespaces across separate apps/frames can collide?

    Basically, I'm wondering how far people take the namespaces.

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,075
    Answers
    674
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Here is a good article on our class system that provides info on name spacing conventions:
    http://www.sencha.com/learn/sencha-class-system/

    Regards,
    Scott

  3. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    423
    Answers
    23
    Vote Rating
    153
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default


    Thanks, I had read that but it doesn't say much beyond the fact that packages organize your code. I'm trying to get deeper and determine what the benefits are beyond organization. Mainly, under what conditions will namespaces conflict (in the same application? In the same frame?), how concerned I should be about this, and what is the best way to avoid it.

  4. #4
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    In your daily development duties, namespacing is mostly an organizational practice. The only real-world scenario I've come across where namespaces were important is when I had to integrate some Ext code into a page which already used a 3rd party Javascript framework.

    Having said that, I still think namespacing helps keep you from stepping on your own toes as an application grows in size and scope.

  5. #5
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    423
    Answers
    23
    Vote Rating
    153
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default


    Great, that helps. So to clarify further, the only real danger of namespace collision is if your application is using some external code with the same namespace? And if you're running your app in a portal (like a "widget" in its own iframe), there won't be conflicts with apps in other iframes? In other words, each iframe would be self-contained from a namespace perspective because they're all separate apps running on separate pages.

    Thanks,

    Brian

  6. #6
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    Yes, you generally only have to worry about namespace collisions on Javascript objects which are operating in the same document scope.

    If memory serves me correctly, every page has its own javascript environment and its own global variables. You can explicitly reference items in child iframes with some parent.frames["frameName"] trickery, but in general iframe Javascript namespaces are protected from each other.

  7. #7
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,361
    Answers
    102
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Technically there are no namespaces in JavaScript. Everything is either lexically scoped or globally scoped. We use the word "namespace" but it's not truly.

    Ext is a globally scoped reference. You can test this by doing window.Ext.getVersion().version == Ext.getVersion().version .

    That said, you should not have to worry about collisions if you use a unique namespace identifier (Global reference) for your applications. Couple that with lexically scoped references, and you should be OK

  8. #8
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    423
    Answers
    23
    Vote Rating
    153
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default


    Thanks, Jay. This may just be my lack of familiarity with JavaScript (I built Flex apps for about 8 years before making this switch), but does that apply to iFrames? Since an iFrame is really rendering a separate page, if you run 2 Ext apps in 2 iFrames in a single browser window, does that still mean there is only one Ext instance in use? Or would there be two in this case (one for each iFrame)?

    Regards,

    Brian

  9. #9
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,361
    Answers
    102
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Quote Originally Posted by brian428 View Post
    Thanks, Jay. This may just be my lack of familiarity with JavaScript (I built Flex apps for about 8 years before making this switch), but does that apply to iFrames? Since an iFrame is really rendering a separate page, if you run 2 Ext apps in 2 iFrames in a single browser window, does that still mean there is only one Ext instance in use? Or would there be two in this case (one for each iFrame)?

    Regards,

    Brian
    You're partially.

    Each iframe is its own "sandbox", where they each have their own global pool of references. So, you can have N number of instances of Ext JS running on a single page with frames. I highly discourage that practice, as it's inefficient and extremely difficult to debug.

    Ext JS was not designed to deal with multiple frames.

  10. #10
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    423
    Answers
    23
    Vote Rating
    153
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default


    Hmm...now I feel like I need to dig a bit deeper. We're working on an application that is essentially a portal. There is a "shell" application (which happens to be an ExtJS app) where users can manage their portal and add "widgets" (basically, portlets) to their workspace. These are written in a range of ways: some are ExtJS, some are Flex, some are GWT, etc. Each widget is loaded into an iframe from where ever they are hosted (they may be coming from a range of locations internal to the enterprise). The different widgets only communicate with the outer "shell" application (or with each other) through a very specific API that is very generic (since it has to be usable by many different widgets using different technologies).

    The portal seems to handle all of this just fine. I'm really just trying to make sure that different ExtJS apps loaded into separate widget iframes aren't going to step on each other in some way. They *should* all have different application names anyway, but since they're running in separate iframes it seems like this should isolate them completely.

    If that clarifies my situation enough, can you confirm?

    Thanks,

    Brian