Skip to main content
Hitachi Vantara Lumada and Pentaho Documentation

Context

pentaho.type. Context

A class that holds configured types.

When a component, like a visualization, is being assembled, it should not necessarily be unaware of the environment where it is going to be used. A context object gathers information that has a global scope, such as the current locale or the current theme, which is likely to have an impact on how a visualization is presented to the user. For instance, the color palette used in a categorical bar chart might be related to the current theme. As such, besides holding contextual, environmental information, a context object should contain the necessary logic to facilitate the configuration of component types using that information. The Pentaho Type API embraces this concept by defining types as type factories that take a context object as their argument.

The instance constructors of types must be obtained from a context object, using one of the provided methods: get, getAsync, getAll, or getAllAsync so that these are configured before being used. This applies whether an instance constructor is used for creating an instance or to derive a subtype.

A type context holds environmental information in the form of an environment of the JavaScript Pentaho Platform, which contains relevant information such as: application, user, theme and locale. Their values determine (or "select") the type configuration rules that apply and are used to configure the constructors provided by the context.

Note that anonymous types cannot be directly configured, as type configuration rules are targeted at specific, identified types.

For information on how to configure the Context class, see pentaho.type.spec.IContext.

AMD Module

require(["pentaho/type/Context"], function(Context) { /* code goes here */ });

See also: pentaho.type.spec.IContext

Constructor

Name Description
new Context(env, config)

Creates a Context with given variables.

Members

Name Description
environment :  pentaho.environment.IEnvironment

Gets the associated platform environment.

instances :  pentaho.type.InstancesContainer

Gets the associated instances' container.

isConfiguring :  boolean

Gets a value that indicates that the context is currently loading and, in particular, configuring a type.

transaction :  pentaho.type.changes.Transaction

Gets the ambient transaction, if any, or null.

Methods

Name Description
createAsync(envSpec) : Promise.<<code>!pentaho.type.Context>
Static

Creates a new context with a given environment and returns a promise for it.

enterChange() : pentaho.type.changes.TransactionScope

Enters a scope of change.

enterCommitted() : pentaho.type.changes.CommittedScope

Enters a read-committed scope.

get(typeRef, keyArgs) : Class.<<code>pentaho.type.Instance>

Gets the configured instance constructor of a type.

getAll(baseTypeId, keyArgs) : Array.<<code>Class.<<code>pentaho.type.Value>>

Gets the configured instance constructors of all of the loaded types that are subtypes of a given base type.

getAllAsync(baseTypeId, keyArgs) : Promise.<<code>Array.<<code>Class.<<code>pentaho.type.Instance>>>

Gets a promise for the configured instance constructors of all of the types that are subtypes of a given base type.

getAsync(typeRef, keyArgs) : Promise.<<code>!Class.<<code>pentaho.type.Instance>>

Gets, asynchronously, the configured instance constructor of a type.

getChangesetsPending(container) : Array.<<code>pentaho.type.changes.Changeset>

Gets any changesets still being delivered through notifications in the commit phase of transactions.

getDependency(depRef, keyArgs) : Object | Array | pentaho.type.Instance | pentaho.type.Type

Resolves a module dependency reference.

getDependencyApply(depRef, fun, ctx) : any

Resolves a module dependency reference and applies a given function to the array results.

getDependencyApplyAsync(depRef, fun, ctx) : Promise

Resolves a module dependency reference, asynchronously, and applies a given function to the array results.

getDependencyAsync(depRef, keyArgs) : Promise.<(Object | Array | pentaho.type.Instance | pentaho.type.Type)>

Resolves a module dependency reference, asynchronously.

Constructor Details

new Context(env, config)

Creates a Context with given variables.

Source: javascript/web/pentaho/type/Context.js, line 359

Parameters:
Name Default Value Summary
env : pentaho.environment.IEnvironment

A platform environment. When unspecified, it defaults to pentaho.environment.main.

config : pentaho.config.IConfiguration

The configuration for the given environment.

See also: pentaho.type.spec.IContext

Members Details

environment:  pentaho.environment.IEnvironment

Gets the associated platform environment.

Source: javascript/web/pentaho/type/Context.js, line 502

instances:  pentaho.type.InstancesContainer

Gets the associated instances' container.

Source: javascript/web/pentaho/type/Context.js, line 512

isConfiguring:  boolean

Gets a value that indicates that the context is currently loading and, in particular, configuring a type.

Certain changes to types are not safe when performed from configurations. This property allows blocking these changes.

Source: javascript/web/pentaho/type/Context.js, line 525

transaction:  pentaho.type.changes.Transaction

Gets the ambient transaction, if any, or null.

Source: javascript/web/pentaho/type/Context.js, line 1003

Methods Details

createAsync(envSpec) : Promise.<<code>!pentaho.type.Context>
Static

Creates a new context with a given environment and returns a promise for it.

Source: javascript/web/pentaho/type/Context.js, line 1626

Parameters:
Name Default Value Summary
envSpec : pentaho.environment.spec.IEnvironment
Optional

The environment variables' specification. When unspecified, it defaults to pentaho.environment.main. Unspecified platform context properties default to the value of those of the default context.

Returns:
Name Description
Promise.<<code>!pentaho.type.Context>

A promise for the new context.

enterChange() : pentaho.type.changes.TransactionScope

Enters a scope of change.

To mark the changes in the scope as error, call its reject method.

To end the scope of change successfully, dispose the returned transaction scope, by calling its dispose method.

If the scope initiated a transaction, then that transaction is committed. Otherwise, if an ambient transaction already existed when the change scope was created, that transaction is left uncommitted.

To end the scope with an error, call its reject method.

Source: javascript/web/pentaho/type/Context.js, line 1028

Returns:
Name Description
pentaho.type.changes.TransactionScope

The new transaction scope.

enterCommitted() : pentaho.type.changes.CommittedScope

Enters a read-committed scope.

Within this scope there is no current transaction and reading the properties of instances obtains their committed values.

Source: javascript/web/pentaho/type/Context.js, line 1041

Returns:
Name Description
pentaho.type.changes.CommittedScope

The read-committed scope.

get(typeRef, keyArgs) : Class.<<code>pentaho.type.Instance>

Gets the configured instance constructor of a type.

For more information on the typeRef argument, see UTypeReference.

The modules of standard types and mixins are preloaded and can be requested synchronously. These are:

For all of these, the pentaho/type/ or pentaho/type/mixins/ prefix is optional (when requested to a context; the AMD module system requires the full module identifiers to be specified).

If it is not known whether all non-standard types that are referenced by identifier have already been loaded, the asynchronous method version, getAsync, should be used instead.

Source: javascript/web/pentaho/type/Context.js, line 596

Parameters:
Name Default Value Summary
typeRef : pentaho.type.spec.UTypeReference

A type reference.

keyArgs : Object
Optional

The keyword arguments.

Parameters:
Name Default Value Summary
defaultBase : pentaho.type.spec.UTypeReference
Optional

The default base type of typeRef when it is an immediate generic object specification.

Returns:
Name Description
Class.<<code>pentaho.type.Instance>

The instance constructor.

Throws:
Name Description
pentaho.lang.ArgumentRequiredError

When typeRef is an empty string or Nully.

pentaho.lang.ArgumentInvalidError

When typeRef is of an unsupported JavaScript type: not a string, function, array or object.

pentaho.lang.ArgumentInvalidError

When typeRef is a type constructor (e.g. Type)

pentaho.lang.ArgumentInvalidError

When typeRef is an instance.

Error

When the identifier of a type is not defined as a module in the AMD module system (specified directly in typeRef, or present in an generic type specification).

Error

When the identifier of a non-standard type is from a module that the AMD module system has not loaded yet (specified directly in typeRef, or present in an generic type specification).

pentaho.lang.OperationInvalidError

When the value returned by a factory function is not an instance constructor of a subtype of Instance (specified directly in typeRef, or obtained indirectly by loading a type's module given its identiifer).

pentaho.lang.ArgumentInvalidError

When typeRef is, or contains, an array-shorthand, list type specification that has more than one child element type specification.

See also: pentaho.type.Context#getAsync

getAll(baseTypeId, keyArgs) : Array.<<code>Class.<<code>pentaho.type.Value>>

Gets the configured instance constructors of all of the loaded types that are subtypes of a given base type.

This method is a synchronous version of pentaho.type.Context#getAllAsync

If it is not known whether all known subtypes of baseTypeId have already been loaded (for example, by a previous call to getAllAsync), the asynchronous method version, getAllAsync, should be used instead.

Source: javascript/web/pentaho/type/Context.js, line 716

Parameters:
Name Default Value Summary
baseTypeId : string

The identifier of the base type.

keyArgs : object
Optional

Keyword arguments.

Parameters:
Name Default Value Summary
isBrowsable : boolean
Optional
null

Indicates that only types with the specified isBrowsable value are returned.

isAbstract : boolean
Optional
null

Indicates that only types with the specified isAbstract value are returned.

Returns:
Name Description
Array.<<code>Class.<<code>pentaho.type.Value>>

An array of instance contructors.

Throws:
Name Description
Error

When the identifier of a type is not defined as a module in the AMD module system.

Error

When the identifier of a non-standard type is from a module that the AMD module system has not loaded yet.

See also: pentaho.type.Context#getAllAsync , pentaho.type.Context#get , pentaho.type.Context#getAsync

Example

Getting all "my/component" sub-types browsable in the application "data-explorer-101".

require(["pentaho/type/Context"], function(Context) {

 Context.createAsync({application: "data-explorer-101"})
 .then(function(context) {
 var ComponentModels = context.getAll("my/component", {isBrowsable: true});

 ComponentModels.forEach(function(ComponentModel) {
 console.log("will display menu entry for: " + ComponentModel.type.label);
 });
 });
});
getAllAsync(baseTypeId, keyArgs) : Promise.<<code>Array.<<code>Class.<<code>pentaho.type.Instance>>>

Gets a promise for the configured instance constructors of all of the types that are subtypes of a given base type.

Any errors that may occur will result in a rejected promise.

Source: javascript/web/pentaho/type/Context.js, line 770

Parameters:
Name Default Value Summary
baseTypeId : string

The identifier of the base type.

keyArgs : object
Optional

Keyword arguments.

Parameters:
Name Default Value Summary
isBrowsable : boolean
Optional
null

Indicates that only types with the specified isBrowsable value are returned.

isAbstract : boolean
Optional
null

Indicates that only types with the specified isAbstract value are returned.

Returns:
Name Description
Promise.<<code>Array.<<code>Class.<<code>pentaho.type.Instance>>>

A promise for an array of instance classes.

See also: pentaho.type.Context#get , pentaho.type.Context#getAsync

Example

Getting all "my/component" sub-types browsable in the application "data-explorer-101".

require(["pentaho/type/Context"], function(Context) {

 Context.createAsync({application: "data-explorer-101"})
 .then(function(context) {
 return context.getAllAsync("my/component", {isBrowsable: true})
 })
 .then(function(ComponentModels) {
 ComponentModels.forEach(function(ComponentModel) {
 console.log("will display menu entry for: " + ComponentModel.type.label);
 });
 });
});
getAsync(typeRef, keyArgs) : Promise.<<code>!Class.<<code>pentaho.type.Instance>>

Gets, asynchronously, the configured instance constructor of a type.

For more information on the typeRef argument, see UTypeReference.

This method can be used even if a generic type specification references non-standard types whose modules have not yet been loaded by the AMD module system.

Source: javascript/web/pentaho/type/Context.js, line 661

Parameters:
Name Default Value Summary
typeRef : pentaho.type.spec.UTypeReference

A type reference.

keyArgs : Object
Optional

The keyword arguments.

Parameters:
Name Default Value Summary
defaultBase : pentaho.type.spec.UTypeReference
Optional

The default base type of typeRef when it is an immediate generic object specification.

Returns:
Name Description
Promise.<<code>!Class.<<code>pentaho.type.Instance>>

A promise for the instance constructor.

See also: pentaho.type.Context#get

Example

Getting a configured type instance constructor, asynchronously, for a specific application.

require(["pentaho/type/Context"], function(Context) {

 Context
 .createAsync({application: "data-explorer-101"})
 .then(function(context) {

 context.getAsync("my/viz/chord").then(function(VizChordModel) {

 var model = new VizChordModel({outerRadius: 200});

 // ...
 });

 });
});
getChangesetsPending(container) : Array.<<code>pentaho.type.changes.Changeset>

Gets any changesets still being delivered through notifications in the commit phase of transactions.

If a transaction is started and committed from within the did:change listener of another, then multiple changesets may be returned.

Source: javascript/web/pentaho/type/Context.js, line 1145

Parameters:
Name Default Value Summary
container : pentaho.type.mixins.Container

The container.

Returns:
Name Description
Array.<<code>pentaho.type.changes.Changeset>

An array of changesets, if any changeset exists; null otherwise.

getDependency(depRef, keyArgs) : Object | Array | pentaho.type.Instance | pentaho.type.Type

Resolves a module dependency reference.

Source: javascript/web/pentaho/type/Context.js, line 847

Parameters:
Name Default Value Summary
depRef : pentaho.type.spec.UModuleDependencyReference

A module dependency reference.

keyArgs : object
Optional

Keyword arguments.

Parameters:
Name Default Value Summary
dependentId : string
Optional

The identifier of the dependent type, for resolving relative identifiers.

Returns:
Name Description
Object | Array | pentaho.type.Instance | pentaho.type.Type

A module dependency.

Throws:
Name Description
pentaho.lang.ArgumentInvalidError

When depRef is not a valid module dependency reference.

Error

Other errors, as documented in: get, getAll and InstancesContainer#get.

getDependencyApply(depRef, fun, ctx) : any

Resolves a module dependency reference and applies a given function to the array results.

This method calls getDependency and then applies the given function to the resolved dependencies. Any module dependency reference which evaluates to an array can be specified.

Source: javascript/web/pentaho/type/Context.js, line 964

Parameters:
Name Default Value Summary
depRef : pentaho.type.spec.UModuleDependencyReference

A module dependency reference.

fun : function

The function to apply the results on.

ctx : Object
Optional

The object on which to call fun.

Returns:
Name Description
any

The result of calling the given function.

See also: pentaho.type.Context#getDependency , pentaho.type.Context#getDependencyApplyAsync

getDependencyApplyAsync(depRef, fun, ctx) : Promise

Resolves a module dependency reference, asynchronously, and applies a given function to the array results.

This method calls getDependencyAsync and then applies the given function to the resolved dependencies. Any module dependency reference which evaluates to an array can be specified.

Source: javascript/web/pentaho/type/Context.js, line 988

Parameters:
Name Default Value Summary
depRef : pentaho.type.spec.UModuleDependencyReference

A module dependency reference.

fun : function

The function to apply the results on.

ctx : Object
Optional

The object on which to call fun.

Returns:
Name Description
Promise

A promise for the result of calling the given function.

See also: pentaho.type.Context#getDependencyAsync , pentaho.type.Context#getDependencyApply

getDependencyAsync(depRef, keyArgs) : Promise.<(Object | Array | pentaho.type.Instance | pentaho.type.Type)>

Resolves a module dependency reference, asynchronously.

Source: javascript/web/pentaho/type/Context.js, line 871

Parameters:
Name Default Value Summary
depRef : pentaho.type.spec.UModuleDependencyReference

A module dependency reference.

keyArgs : object
Optional

Keyword arguments.

Parameters:
Name Default Value Summary
dependentId : string
Optional

The identifier of the dependent type, for resolving relative identifiers.

Returns:
Name Description
Promise.<(Object | Array | pentaho.type.Instance | pentaho.type.Type)>

A promise for a module dependency.