The ScenarioObserver
You create a new observer by configuring it to watch one or more scenarios and entities. You always need to declare the scenarios to watch but you can either specify a list of entities from those scenarios or that you just want to scenario state information itself.
var view = insight.getView();
view.withFirstScenario()
.withEntities('SCALAR1', 'ARRAY1', 'parameters', 'SET1')
.notify(function(scenario) {
console.log(scenario);
})
.start();
// Create a few observers but don't call .start() on them
// This will start any observers that have not yet been started
view.start();
ScenarioObserver#notify
then you can stop that observer at any time by calling
ScenarioObserver#dispose
:
var observer = view.withFirstScenario()
.withEntities('SCALAR1', 'ARRAY1', 'parameters', 'SET1')
.notify(function(scenario) {
console.log(scenario);
})
.start();
// A some other point in your code
observer.dispose();
view.withAllScenarios()
or
view.withScenarios(0,1)
. If you want to fetch data once and dispose the observer immediately after then you can use:
view.withFirstScenario()
.withEntities('ARRAY1')
.once(function(scenario) {
scenario.getArray('ARRAY1');
})
.start();
ScenarioObserver#withFirstScenario
is used) or an array of scenarios (when
ScenarioObserver#withScenarios
or
ScenarioObserver#withAllScenarios
are used). These scenario objects are pre-loaded with the scenario properties, scenario summary data and all the entity data that has been requested. All the data is immutable, that is it will not change while the callback function is running: fresh objects will passed in on a future callback. Also, the scenario object will only allow you to access entities that were declared in the observer configuration.
// Single scenario
view.withFirstScenario()
.withEntities('ARRAY1', 'SET1')
.notify(function(scenario) {
var array1 = scenario.getArray('ARRAY1');
var set1 = scenario.getSet('SET1');
// This would throw an error as ARRAY2 has
// not been requested
var array2 = scenario.getArray('ARRAY2');
})
.start();
// Multi scenario
view.withAllScenarios()
.withEntities('ARRAY1')
.notify(function(scenarios) {
scenarios.forEach(function(scenario) {
scenario.getArray('ARRAY1');
});
})
.start();
// With scenario summary data only
view.withFirstScenario()
.withSummaryData()
.notify(function(scenario) {
// You cannot access any entity data here as
// no entities have been subscribed to
var hasResultData =
scenario.getSummaryData().hasResultData();
var objective = scenario.getSummaryData().getObjective();
})
.start();
// With entity data and scenario summary data
view.withFirstScenario()
.withSummaryData()
.withEntities('ARRAY1')
.notify(function(scenario) {
var array1 = scenario.getArray('ARRAY1');
var hasResultData =
scenario.getSummaryData().hasResultData();
var objective = scenario.getSummaryData().getObjective();
})
.start();
It is best to split your view up with multiple scenario observers. Each one should be kept as small as possible, listening to the least number of entities possible, and keeping the responsibility of the notify callback to a minimum. The benefits of this are that you code is more maintainable, easier to separate into modules, and it minimizes the number of UI updates for any given entity change.
© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.