Docs Help

Terms, Icons, and Labels

Many classes have shortcut names used when creating (instantiating) a class with a configuration object. The shortcut name is referred to as an alias (or xtype if the class extends Ext.Component). The alias/xtype is listed next to the class name of applicable classes for quick reference.

Access Levels

Framework classes or their members may be specified as private or protected. Else, the class / member is public. Public, protected, and private are access descriptors used to convey how and when the class or class member should be used.

Member Types

Member Syntax

Below is an example class member that we can disect to show the syntax of a class member (the lookupComponent method as viewed from the Ext.button.Button class in this case).

lookupComponent ( item ) : Ext.Component
protected

Called when a raw config object is added to this container either during initialization of the items config, or when new items are added), or {@link #insert inserted.

This method converts the passed object into an instanced child component.

This may be overridden in subclasses when special processing needs to be applied to child creation.

Parameters

item :  Object

The config object being added.

Returns
Ext.Component

The component to be added.

Let's look at each part of the member row:

Member Flags

The API documentation uses a number of flags to further commnicate the class member's function and intent. The label may be represented by a text label, an abbreviation, or an icon.

Class Icons

- Indicates a framework class

- A singleton framework class. *See the singleton flag for more information

- A component-type framework class (any class within the Ext JS framework that extends Ext.Component)

- Indicates that the class, member, or guide is new in the currently viewed version

Member Icons

- Indicates a class member of type config

- Indicates a class member of type property

- Indicates a class member of type method

- Indicates a class member of type event

- Indicates a class member of type theme variable

- Indicates a class member of type theme mixin

- Indicates that the class, member, or guide is new in the currently viewed version

Class Member Quick-Nav Menu

Just below the class name on an API doc page is a row of buttons corresponding to the types of members owned by the current class. Each button shows a count of members by type (this count is updated as filters are applied). Clicking the button will navigate you to that member section. Hovering over the member-type button will reveal a popup menu of all members of that type for quick navigation.

Getter and Setter Methods

Getting and setter methods that correlate to a class config option will show up in the methods section as well as in the configs section of both the API doc and the member-type menus just beneath the config they work with. The getter and setter method documentation will be found in the config row for easy reference.

History Bar

Your page history is kept in localstorage and displayed (using the available real estate) just below the top title bar. By default, the only search results shown are the pages matching the product / version you're currently viewing. You can expand what is displayed by clicking on the button on the right-hand side of the history bar and choosing the "All" radio option. This will show all recent pages in the history bar for all products / versions.

Within the history config menu you will also see a listing of your recent page visits. The results are filtered by the "Current Product / Version" and "All" radio options. Clicking on the button will clear the history bar as well as the history kept in local storage.

If "All" is selected in the history config menu the checkbox option for "Show product details in the history bar" will be enabled. When checked, the product/version for each historic page will show alongside the page name in the history bar. Hovering the cursor over the page names in the history bar will also show the product/version as a tooltip.

Search and Filters

Both API docs and guides can be searched for using the search field at the top of the page.

On API doc pages there is also a filter input field that filters the member rows using the filter string. In addition to filtering by string you can filter the class members by access level, inheritance, and read only. This is done using the checkboxes at the top of the page.

The checkbox at the bottom of the API class navigation tree filters the class list to include or exclude private classes.

Clicking on an empty search field will show your last 10 searches for quick navigation.

API Doc Class Metadata

Each API doc page (with the exception of Javascript primitives pages) has a menu view of metadata relating to that class. This metadata view will have one or more of the following:

Expanding and Collapsing Examples and Class Members

Runnable examples (Fiddles) are expanded on a page by default. You can collapse and expand example code blocks individually using the arrow on the top-left of the code block. You can also toggle the collapse state of all examples using the toggle button on the top-right of the page. The toggle-all state will be remembered between page loads.

Class members are collapsed on a page by default. You can expand and collapse members using the arrow icon on the left of the member row or globally using the expand / collapse all toggle button top-right.

Desktop -vs- Mobile View

Viewing the docs on narrower screens or browsers will result in a view optimized for a smaller form factor. The primary differences between the desktop and "mobile" view are:

Viewing the Class Source

The class source can be viewed by clicking on the class name at the top of an API doc page. The source for class members can be viewed by clicking on the "view source" link on the right-hand side of the member row.

Cmd 7.1.0


top

Building Progressive Web Apps with Sencha Cmd

Cmd 6.5+ helps you turn any Ext JS app into a progressive web app.

Progressive web apps provide a native app experience using modern web technologies. Google offers an excellent introduction to progressive web apps: Your First Progressive Web App

Cmd specifically allows developers to:

  • Display an app banner that invites Android users to install the app to their home screen.

  • Provide offline support via service-worker based caching for browsers which support this feature.

Note: You must first have Node JS installed locally to use the Cmd Progressive Web App integrations.

Requirements

Using the Progressive Web App functionality requires Node JS 6+

Add to Home Screen Banner

To add an "Add to Home Screen" banner to your app, add a progressive config object to your app.json. The progressive config object has two items: manifest and serviceWorker. The manifest config contains data for a web app manifest. Cmd automatically adds the required <link rel=”manifest”/> tag to your app’s index.html file at build time once this config is in place.

The presence of a web app manifest doesn't necessarily mean that supported browsers will show the add to home screen banner immediately. Chrome, for example, uses a set of criteria including the use of a service worker, SSL status, and visit frequency heuristics to determine when to show the banner.

Example:

"progressive": {
    "manifest": {

        "name": "My App",
        "short_name": "My App",
        "icons": [{
            "src": "resources/icon-small.png",
            "sizes": "96x96"
        }, {
            "src": "resources/icon-medium.png",
            "sizes": "192x192"
        }, {
            "src": "resources/icon-large.png",
            "sizes": "256x256"
        }],
        "theme_color": "#054059",
        "background_color": "#054059",
        "display": "standalone",
        "orientation": "portrait",
        "start_url": "/index.html"
    }
}

Caching with Service Workers

Perhaps the most important feature of progressive web apps is providing offline functionality. Generally, this is done by caching an app shell (the HTML, JavaScript, CSS, font, and image assets needed to display your app), as well as content, which is typically retrieved via AJAX calls to a REST API.

Progressive web apps use service workers to provide caching. When the "progressive" config is present in your app.json, Cmd creates a service worker at build time using sw-precache that automatically caches the app shell. You can also have the service worker cache AJAX requests by adding @sw-cache comments within your code.

// @sw-cache

Imagine a store that retrieves a list of upcoming events from the server. We can have the service worker generated by Cmd cache the API call so that the result is available when offline by adding an @sw-cache comment to the url:

Ext.define('App.store.UpcomingEvents', {
    extend: 'Ext.data.Store',
    proxy: {
        type: 'ajax',

        // @sw-cache
        url: '/api/upcoming-events.json',
        reader: {
            type: 'json'
        }
    }
});

The @sw-cache comment can be placed above any string or object property. The string to which it is attached should be the url being cached. When the url is dynamic (for example it contains an id in the path or query string), you can optionally specify a "urlPattern" config to control which requests are cached. For example, imagine an AJAX request for a specific event:

Ext.define('App.model.Event', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'date'],

    proxy: {
        type: 'rest',

        // @sw-cache { urlPattern: "\\/api\\/events\\/\\d+" }
        url : '/events'
    }
});

Controlling Cache Behavior

The @sw-cache comment accepts a number of options:

  • urlPattern: A regular expression that, when matched, causes the response to be cached

  • handler: Defaults to "networkFirst". Can be one of the following:

    • networkFirst Try to handle the request by fetching from the network. If it succeeds, store the response in the cache. Otherwise, try to fulfill the request from the cache. This is the strategy to use for basic read-through caching. It's also good for API requests where you always want the freshest data when it is available but would rather have stale data than no data.

    • cacheFirst If the request matches a cache entry, respond with that. Otherwise try to fetch the resource from the network. If the network request succeeds, update the cache. This option is good for resources that don't change, or have some other update mechanism.

    • fastest Request the resource from both the cache and the network in parallel. Respond with whichever returns first. Usually, this will be the cached version, if there is one. On the one hand this strategy will always make a network request, even if the resource is cached. On the other hand, if/when the network request completes the cache is updated, so that future cache reads will be more up-to-date.

    • cacheOnly Resolve the request from the cache, or fail. This option is good for when you need to guarantee that no network request will be made, for example saving battery on mobile.

    • networkOnly Handle the request by trying to fetch the URL from the network. If the fetch fails, fail the request. Essentially, the same as not creating a route for the URL at all.

  • options: An object with the following properties:

    • debug [Boolean] Determines whether extra information is logged to the browser's console.

    • networkTimeoutSeconds [Number] A timeout that applies to the toolbox.networkFirst built-in handler. If networkTimeoutSeconds is set, then any network requests that take longer than that amount of time will automatically fall back to the cached response if one exists. When networkTimeoutSeconds is not set, the browser's native networking timeout logic applies.

    • cache [Object]

      • name [String] The name of the Cache used to store Response objects. Using a unique name allows you to customize the cache's maximum size and age of entries.
      • maxEntries [Number] Imposes a least-recently used cache expiration policy on entries cached via the various built-in handlers. You can use this with a cache that's dedicated to storing entries for a dynamic set of resources with no natural limit. Setting cache.maxEntries to, e.g., 10 would mean that after the 11th entry is cached, the least-recently used entry would be automatically deleted. The cache should never end up growing beyond cache.maxEntries entries. This option will only take effect if cache.name is also set. It can be used alone or in conjunction with cache.maxAgeSeconds.
      • maxAgeSeconds [Number] Imposes a maximum age for cache entries, in seconds. You can use this with a cache that's dedicated to storing entries for a dynamic set of resources with no natural limit. Setting cache.maxAgeSeconds to, e.g., 86400 would mean that any entries older than a day would automatically be deleted. This option will only take effect if cache.name is also set. It can be used alone or in conjunction with cache.maxEntries.

Example: Limiting the number of cached responses for an API call

If we only want to cache the ten most recently accessed upcoming events from our example above, we can achieve this by adding

options: { cache: { name: ‘events’, maxEntries: 10 } }

to our @sw-cache comment. For example:

Ext.define('App.model.Event', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'date'],

    proxy: {
        type: 'rest',
        // @sw-cache { urlPattern: "\\/api\\/events\\/\\d+", options: { cache: { name: 'events', maxEntries: 10 } } }
        url : '/events'
    }
});

Note: After adding @sw-cache comments or making changes to app.json, you’ll need to run "sencha app build" to test your changes. The service-worker is only included in the production build of your app. This is because development build's load each code file as a separate request, so pre-caching all of the assets needed for your app shell is not possible when running a development build. Be sure to use the production build to test caching behavior.

Note: Once built, an app’s first re-load will pick up the changes to the progressive manifest and caching. Since the service-worker is fetched and installed asynchronously when you reload the app in your browser, it may not initially cache API calls that are made while your app is launching. You may need to reload your browser a second time to cache API calls made during launch.

The serviceWorker Config

In addition to @sw-cache comments, you can configure the service worker cache requests by adding a runtimeCaching property to the progressive.serviceWorker section in your app.json. All of the options described above are supported.
So for example, to cache the list of upcoming events as well as the data for the ten most recently viewed events, you could add the following to your app.json instead of adding @sw-cache comments to your store and model classes.

Here is a complete example with both manifest and serviceWorker configs.

"progressive": {

    "manifest": {

        "name": "My App",
        "short_name": "My App",

        "icons": [{
            "src": "resources/icon-small.png",
            "sizes": "96x96"
        }, {
            "src": "resources/icon-medium.png",
            "sizes": "192x192"
        }, {
            "src": "resources/icon-large.png",
            "sizes": "256x256"
        }],

        "theme_color": "#054059",
        "background_color": "#054059",
        "display": "standalone",
        "orientation": "portrait",
        "start_url": "/index.html"
    },

    "serviceWorker": {

        "runtimeCaching": [
            {
                "urlPattern": "\\/api\\/events"
            }, 
            {
                "urlPattern": "\\/api\\/events\\/\d+",
                "options": {
                    "cache": {
                        "name": "events",
                        "maxEntries": 10
                    }
                }
            }
        ]
    }
}

Note: While you can use both the runtimeCaching config in app.json and @sw-cache comments to specify caching behavior, @sw-cache comments will take precedence. For this reason we recommend choosing one method or the other for your app, instead of mixing both.

Cmd 7.1.0