new Core/Context()
The Context object is a state variable to hold the current application state.
It extends Backbone.Model.
The context contains various states of the current View or Layout -- this includes the current model and collection, as well as the current module focused and also possibly the url hash that was matched.
Instantiate a context.
const Context = require('core/context');
let myContext = new Context();
Creating a child context or retrieving an existing one.
Assuming myContext is a context instance.
let childContext = myContext.getChildContext({cid: <contextId>});
If 
Retrieving Data from the Context
A context is a Backbone Model, so its data is stored in the attributes:
var module = myContext.get('module'); // module = "Contacts"
Methods
- 
    addFields(fieldsArray)
- 
    
    Sets the fieldsattribute on this context by extending the currentfieldsattribute with the passed-infieldsArray.Parameters:Name Type Description fieldsArrayArray.<string> The list of field names. Returns:Instance of this model. - Type
- Core/Context
 
- 
    clear( [options])
- 
    
    Recursively clears this context and its children. Unbinds the event listeners, clears the attributes, aborts the request in progress if any, and resets the load flag (calls Core/Context#resetLoadFlag). Parameters:Name Type Argument Description optionsObject <optional> 
 Standard Backbone.Modeloptions.
- 
    getChildContext( [def])
- 
    
    Gets an existing related context or creates a new one. Parameters:Name Type Argument Description defObject <optional> 
 Child context definition. PropertiesName Type Argument Description cidstring <optional> 
 The id of the context to retrieve. This takes precedence over the passed name, the link and the module. namestring <optional> 
 The name of the context to retrieve. This takes precedence over passed the link and the module. linkstring <optional> 
 The link name to retrieve a context from. This takes precedence over the passed module name. modulestring <optional> 
 The module name to retrieve a context from. The first child context matching the module attribute will be returned. forceNewboolean <optional> 
 trueto force the creation a new context, without trying to retrieve an existing one.Returns:The child context. - Type
- Core/Context
 
- 
    initialize( [attributes])
- 
    
    Calls Backbone's initializeand initializes this context's properties.Parameters:Name Type Argument Description attributesObject <optional> 
 The initial hash of attributes. 
- 
    isCreate()
- 
    
    Checks if this context is used for a create view. Returns:trueif this context has thecreateflag set.- Type
- boolean
 
- 
    isDataFetched()
- 
    
    Checks if data has been successfully loaded. Returns:trueif data has been fetched,falseotherwise.- Type
- boolean
 
- 
    loadData( [options])
- 
    
    Loads data (calls fetch on either model or collection). This method sets an internal boolean flag to prevent consecutive fetch operations. Call Core/Context#resetLoadFlag to reset the context's state. Parameters:Name Type Argument Description optionsObject <optional> 
 A hash of options passed to collection/model's fetch method. PropertiesName Type Argument Description fetchboolean <optional> 
 trueto always fetch the data.
- 
    prepare( [force], prepareRelated)
- 
    
    Prepares instances of model and collection and sets them to this context. The method also create related contexts, based on the created bean fields: It creates child context for each linkof eachcollectionfield present on the bean. This method does nothing if this context already contains an instance of a model or a collection.Parameters:Name Type Argument Description forceboolean <optional> 
 trueto force the creation of the model and collection.prepareRelatedboolean trueto always prepare related contexts.Returns:Returns this context instance. - Type
- Core/Context
 
- 
    reloadData( [options])
- 
    
    Refreshes the context's data and refetches the new data if the skipFetchattribute istrue.Parameters:Name Type Argument Description optionsObject <optional> 
 Options for Core/Context#loadData and the reloadevent.Fires:- event:reload
 
- 
    resetLoadFlag( [options])
- 
    
    Resets load-datastate for this context and its child contexts.The Core/Context#loadData method sets an internal boolean flag to prevent multiple identical requests to the server. This method resets this flag. Parameters:Name Type Argument Description optionsObject <optional> 
 A hash of options. PropertiesName Type Argument Default Description recursiveboolean <optional> 
 true trueto reset the child contexts too.resetModelboolean <optional> 
 true trueto reset the flag on the model.resetCollectionboolean <optional> 
 true trueto reset the flag on the collection.
- 
    setFetch(fetch [, options])
- 
    
    Sets the fetchattribute recursively on the context and its children.A context with fetchset tofalsewon't load the data.Parameters:Name Type Argument Description fetchboolean trueto recursively setfetchtotruein this context and its children.optionsObject <optional> 
 A hash of options. PropertiesName Type Argument Description recursiveboolean <optional> 
 trueto recursively set thefetchboolean on the children.
Events
- 
    reload
- 
    
    Triggered before and after the context is reloaded. Parameters:Name Type Argument Description thisCore/Context The context instance where the event is triggered. optionsObject <optional> 
 The options passed during Core/Context#reloadData call.