Model View Controller (MVC) and Backbone.js

Source files of each module follow the Model View Controller (MVC) architectural pattern. One of the core principles of the MVC pattern is to separate the presentation layer (view) of an application from the data (model) used by the application. All interaction between views and models are handled by the controller.

To implement the MVC pattern, SuiteCommerce Advanced (SCA) uses the Backbone.js libraries. Backbone.js is an open-source JavaScript library that provides a framework for developing web applications.

Structure of a Backbone.js Application

Backbone.js is based on the MVC pattern. Modules that define interfaces or handle data use Backbone.js to define routers, views, and models/collections. The Case module, for example, implements each of these:

Backbone.js Module Example

For example, the Case module defines a router (Case.Router.js) that contains the following:

          routes:
{
'cases': 'showCasesList'
,
'cases?:options': 'showCasesList'
,
'cases/:id': 'showCase'
,
'newcase': 'createNewCase'
} 

        

When a user clicks on an individual case from the list of support cases, instead of sending an HTTP request back to the server, the router calls the showCaseList method based on the value of the partial URL (cases). This method performs two main tasks:

Case.Model defines the data object that contains information about an individual support case. Case.Model extends the Backbone.Model by defining additional methods for performing frontend validation. When the router initializes Case.Detail.View, it passes the instance of Case.Model.

SCA Backbone.js Implementation

The Backbone.js libraries provide a general framework for how a web application is structured and its general functionality. However, much of the specific functionality of the application must be implemented. SCA stores Backbone.js files in the following directories:

Note:

In SCA 2020.1 and later, you should use the SuiteCommerce extensibility API’s SCCollection and SCModel components instead of the native Backbone.Collection and Backbone.Model. In SCA2020.2 and later, you should use the SuiteComerce extensibility API’s SCView component instead of the native Backbone.View. SCCollection, SCModel, and SCView are components of the SuiteCommerce extensibility API that replace Backbone.Collection, Backbone.Model, and Backbone.View, respectively. See the extensibility API reference for more information.

Related Topics

SCA Framework Technologies
TypeScript
Asynchronous Module Definitions (AMD) and RequireJS
Logic-less Templates and Handlebars.js

General Notices