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
, or inject
, 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.
To better understand how a context provides configured types, assume that an non-anonymous type, with the id
"my/own/type"
, is requested from a context object, context
:
var MyOwnInstanceCtor = context.get("my/own/type");
Internally, (it is as if) the following steps are taken:
If the requested type has been previously created and configured, just return it:
var InstanceCtor = getStored(context, "my/own/type"); if(InstanceCtor != null) { return InstanceCtor; }
Otherwise, the context requires the type's module from the AMD module system, and obtains its
factory function
back:var typeFactory = require("my/own/type");
The factory function is called with the context as argument and creates and returns an instance constructor for that context:
InstanceCtor = typeFactory(context);
The instance constructor is configured with any applicable rules:
InstanceCtor = configure(context, InstanceCtor);
The configured instance constructor is stored under its identifier:
store(context, InstanceCtor.type.id, InstanceCtor);
Finally, it is returned to the caller:
return InstanceCtor;
Note that anonymous types cannot be directly configured, as type configuration rules are targeted at specific, identified types.
AMD Module
require(["pentaho/type/Context"], function(Context) { /* code goes here */ });
Constructor
Name | Description |
---|---|
new Context(platformContextSpec) | Creates a |
Members
Name | Description |
---|---|
instance : Static | Gets the default type context of the Pentaho Type API. |
_byFactoryUid : | Map of instance constructors by factory function uid. |
_byTypeId : | Map of instance constructors by |
_byTypeUid : | Map of instance constructors by |
_Instance : | The root |
transaction : | Gets the ambient transaction, if any, or |
vars : | Gets the associated platform context. |
Methods
Name | Description |
---|---|
enterChange() : pentaho.type.changes.TransactionScope | Enters a scope of change. |
enterCommitted() : pentaho.type.changes.CommittedScope | Enters a read-committed scope. |
get(typeRef, keyArgs) : Class.< | Gets the configured instance constructor of a type. |
getAll(baseTypeId, keyArgs) : Array.< | Gets the configured instance constructors of all of the loaded types that are subtypes of a given base type. |
getAllAsync(baseTypeId, keyArgs) : Promise.< | 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.< | Gets, asynchronously, the configured instance constructor of a type. |
inject(typeRefs, fun, ctx) : function | Binds the initial arguments of a function to the instance constructors corresponding to given type references. |
Constructor Details
new Context(platformContextSpec) | ||||||
---|---|---|---|---|---|---|
Creates a Source: javascript/web/pentaho/type/Context.js, line 154
|
Members Details
instance: Static |
---|
Gets the default type context of the Pentaho Type API. This type context instance is created with the Pentaho Platform's default context variables, as given by |
_byFactoryUid: |
---|
Map of instance constructors by factory function uid. See also |
_byTypeId: |
---|
Map of instance constructors by |
_byTypeUid: |
---|
Map of instance constructors by |
_Instance: |
---|
The root |
transaction: |
---|
Gets the ambient transaction, if any, or |
vars: |
---|
Gets the associated platform context. |
Methods Details
enterChange() : pentaho.type.changes.TransactionScope | ||||
---|---|---|---|---|
Enters a scope of change. To mark the changes in the scope as error, call its To end the scope of change successfully, dispose the returned transaction scope, by calling its 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 Source: javascript/web/pentaho/type/Context.js, line 650
|
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 663
|
get(typeRef, keyArgs) : Class.< | |||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gets the configured instance constructor of a type. For more information on the The modules of standard types and refinement facet mixins are preloaded and can be requested synchronously. These are:
For all of these, the The filter types are also preloaded: If it is not known whether all non-standard types that are referenced by identifier have already been loaded, the asynchronous method version, Source: javascript/web/pentaho/type/Context.js, line 352
See also: pentaho.type.Context#getAsync Example Getting a configured type instance constructor synchronously for a specific application. require(["pentaho/type/Context", "my/viz/chord"], function(Context) { var context = new Context({application: "data-explorer-101"}) // Request synchronously cause it was already loaded in the above `require` var VizChordModel = context.get("my/viz/chord"); var model = new VizChordModel({outerRadius: 200}); // Render the model using the default view model.type.defaultViewClass.then(function(View) { var view = new View(document.getElementById("container"), model); // ... }); }); |
getAll(baseTypeId, keyArgs) : Array.< | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 If it is not known whether all known subtypes of Source: javascript/web/pentaho/type/Context.js, line 506
See also: pentaho.type.Context#getAllAsync , pentaho.type.Context#get , pentaho.type.Context#getAsync Example Getting all require(["pentaho/type/Context"], function(Context) { var context = new Context({application: "data-explorer-101"}); 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.< | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 572
See also: pentaho.type.Context#get , pentaho.type.Context#getAsync Example Getting all require(["pentaho/type/Context"], function(Context) { var context = new Context({application: "data-explorer-101"}); 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.< | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gets, asynchronously, the configured instance constructor of a type. For more information on the 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 452
See also: pentaho.type.Context#get Example Getting a configured type instance constructor asynchronously for a specific application. require(["pentaho/type/Context"], function(Context) { var context = new Context({application: "data-explorer-101"}) context.getAsync("my/viz/chord") .then(function(VizChordModel) { var model = new VizChordModel({outerRadius: 200}); // Render the model using the default view model.type.defaultViewClass.then(function(View) { var view = new View(document.getElementById("container"), model); // ... }); }); }); |
inject(typeRefs, fun, ctx) : function | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Binds the initial arguments of a function to the instance constructors corresponding to given type references. The specified type references are each resolved synchronously, using If a fixed JavaScript context object is specified in Source: javascript/web/pentaho/type/Context.js, line 376
|