Results 1 to 8 of 8

Thread: Most recommended way to use requires array?

  1. #1
    Isnogud
    Guest

    Default Most recommended way to use requires array?

    Hi,

    I'm curious whats the most recommended way to use the requires array.
    Should I use the one in Application.js and fill it with all files and classes I gonna need or should I specify it in each class?

    Code:
    Ext.define('MyCompany.Application', {
    extend: 'Ext.app.Application',
    
    requires : ['Ext.data.proxy.Rest', 'Ext.button.Button',  'Ext.form.field.Text']
    
    ...
    
    });
    OR

    Code:
    Ext.define('MyCompany.store.MyStore', {
    extend: 'Ext.data.Store',
    
    requires: ['Ext.data.proxy']
    
    ...
    
    });
    Code:
    Ext.define('MyCompany.view.Login', {
    extend: 'Ext.window.Window',
    
    requires: ['Ext.button.Button', 'Ext.form.field.Text']
    
    ...
    
    });
    Thanks in advance.

  2. #2
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    122
    Answers
    10

    Default

    For me it makes sense that you use it per class, Application is too big of a context.

  3. #3
    Isnogud
    Guest

    Default

    Quote Originally Posted by A. Llorente View Post
    For me it makes sense that you use it per class, Application is too big of a context.
    What if I have already specified the class 'Ext.button.Button' in my login-view and I need the class for my register-view too?
    Should I specifiy it for both views?
    Wouldn't it be more maintenance friendly if I had one file, which requires all classes I need?

    Or aren't there any negative effects if I import the same class 2, 3 or 4 times?

  4. #4
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    122
    Answers
    10

    Default

    The build process is smart enough to include it only one time. In our application we include the same classes from multiple locations, the definition only gets included one in the generated app.js

  5. #5
    Isnogud
    Guest

    Default

    Quote Originally Posted by A. Llorente View Post
    The build process is smart enough to include it only one time. In our application we include the same classes from multiple locations, the definition only gets included one in the generated app.js
    Okay, I guess it depends on personal preferences.
    Thank you for replying!

  6. #6
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    122
    Answers
    10

    Default

    Well, up to a certain point, you can also have problems with dependencies if you include files in the incorrect order, this can become a nightmare if your project is big.

    Why do you think that adding the requires in the Application is better than doing it per class?

  7. #7
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,253
    Answers
    759

    Default

    It's definitely better to do it per class, doing it at the application level somewhat defeats the purpose of doing it. Also, it will become entirely unmaintainable as your project grows larger.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  8. #8
    Isnogud
    Guest

    Default

    Quote Originally Posted by A. Llorente View Post
    Well, up to a certain point, you can also have problems with dependencies if you include files in the incorrect order, this can become a nightmare if your project is big.

    Why do you think that adding the requires in the Application is better than doing it per class?
    I don't, I was just curious.
    I almost created a new class which would add all classes I need to the requires array and add it to the Application.js.
    I wanted to get rid of adding every single field for each class over and over again.

    BUT I think I'm okay with this solution now.
    As long as there are no evil side effects.

    Thanks!

Similar Threads

  1. [DUP] Adds Array instead of Ext.Array to Requires
    By pringlescan in forum JetBrains IDE Plugin
    Replies: 5
    Last Post: 24 Jul 2015, 9:48 AM
  2. Missing in requires or uses array
    By WeeJavaDude in forum JetBrains IDE Plugin
    Replies: 4
    Last Post: 10 Jun 2015, 6:13 AM
  3. Replies: 2
    Last Post: 12 Apr 2015, 10:48 PM
  4. Replies: 7
    Last Post: 9 Jan 2014, 12:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •