Array Filters
Sometimes you only need a slice of the data from particular arrays.
The keys from the array that should be included needs to be generated, this will usually be calculated from some user input or iteration over a related set. You can add an array filter for any of the array entities that a scenario observer is listening to. The array filter is a function that should return a map of the keys (set name or indices ordinal) from the array to be fetched.
// Array filters view.withFirstScenario() .withEntities('ARRAY1', 'ARRAY2') .filter('ARRAY1', function() { // Return a map of the set name to values that // should be included. Only specify the indices // you want to filter down return { 'SET1': [1,2,3], 'SET2': [false] }; }) .filter('ARRAY2', function() { // You can also refer to the indices by ordinal // rather than set name return {0: ['A', 'B']}; }) .notify(function(scenario) { var array1 = scenario.getArray('ARRAY1'); // Can only access the keys from the array that // have been included in the filter var value = array1.getValue([1, false, 'test']); }) .start();
The scenario observers will call the filter functions each time they need to fetch data for those arrays. Evaluating before each fetch allows the filter values to be dynamic. If multiple observers use the same array from the same scenario and filtered by the same values then the data will only be downloaded once, maintaining efficiency for the view.
![]() |
Note Any changes to an array entity will cause a scenario observer to update. It does not take array filters into account.
|