Getting to know your application

When generating an Ext JS application using Sencha Cmd, we end up with a code base that adheres to the concept of namespacing in class names and in the directory structure, as shown here:

Getting to know your application

The structure created with Sencha Cmd's "generate app" feature

We should be familiar with all of this, as it was already covered when we discussed MVVM in Ext JS. Having said that, there are some parts of this that are worth examining further to see whether they're being used to the full.

/overrides

This is a handy one to help us fall into a positive and predictable pattern. There are some cases where you need to override Ext JS functionality on a global level. Maybe, you want to change the implementation of a low-level class (such as Ext.data.proxy.Proxy) to provide custom batching behavior for your application. Sometimes, you might even find a bug in Ext JS itself and use an override to hotfix until the next point release. The overrides directory provides a logical place to put these changes (just mirror the directory structure and namespacing of the code you're overriding). This also provides us with a helpful rule, that is, subclasses go in /app and overrides go in /overrides.

/.sencha

This contains configuration information and build files used by Sencha Cmd. In general, I'd say try and avoid fiddling around in here too much until you know Sencha Cmd inside out because there's a chance you'll end up with nasty conflicts if you try and upgrade to a newer version of Sencha Cmd. Fortunately, Chapter 4, Sencha Cmd, is all about Sencha Cmd, where we'll dive deep into this folder.

bootstrap.js, bootstrap.json, and bootstrap.css

The Ext JS class system has powerful dependency management through the requires feature, which gives us the means to create a build that contains only the code that's in use. The bootstrap files contain information about the minimum CSS and JavaScript needed to run your application as provided by the dependency system. As we'll see in Chapter 4, Sencha Cmd, you can even create custom bootstrap files depending on your requirements.

/packages

In a similar way to how Ruby has RubyGems and Node.js has npm, Sencha Cmd has the concept of packages (a bundle which can be pulled into your application from a local or remote source).

This allows you to reuse and publish bundles of functionality (including CSS, images, and other resources) to reduce copy and paste of code, and share your work with the Sencha community. This directory is empty until you configure packages to be used in your app.

/resources and SASS

SASS is a technology that aids in the creation of complex CSS by promoting reuse and bringing powerful features (such as mixins and functions) to your style sheets. Ext JS uses SASS for its theme files and encourages you to use it as well. We'll look at this in Chapter 4, Sencha Cmd.

index.html

We know that index.html is the root HTML page of our application. It can be customized as you see fit (although, it's rare you'll need to). There's one caveat and it's written in a comment in the file already:

<!-- The line below must be kept intact for Sencha Cmd to build your application -->
<script id="microloader" type="text/javascript" src="bootstrap.js"></script>

We know what bootstrap.js refers to (loading up our application and starting to fulfill its dependencies according to the current build), so heed the comment and leave this script tag well alone!

/build and build.xml

The /build directory contains build artifacts (the files created when the build process is run). If you run a production build, then you'll get a directory inside /build called production and you should use only these files when deploying. The build.xml file allows you to avoid tweaking some of the files in /.sencha when you want to add some extra functionality to a build process. If you want to do something before, during, or after the build, this is the place to do it. We'll come back to the build process when we look at Sencha Cmd in Chapter 4, Sencha Cmd.

app.js

This is the main JavaScript entry point to your application. The comments in this file advise avoiding editing it in order to allow Sencha Cmd to upgrade it in the future. The Application.js file at /app/Application.js can be edited without fear of conflicts and will enable you to do the majority of things you might need to do.

app.json

This contains configuration options related to Sencha Cmd and booting your application. We'll cover this more in Chapter 4, Sencha Cmd.

When we refer to the subject of this book as a JavaScript application, we need to remember that it's just a website composed of HTML, CSS, and JavaScript as well. However, when dealing with a large application that needs to target different environments, it's incredibly useful to augment this simplicity with tools that assist in the development process. At first, it may seem that the default application template contains a lot of cruft, but they are the key to supporting the tools that will help you craft a solid product.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset