1
0
Fork 0

Add optional rate event delay

I've long been opposed to adding this delay, but a proper fix (for deferred,
async rating) that meets the needs of our current project will require
changes that I don't have time to take on for a little while.  As such, this
will be a temporary solution for hopefully no more than a month's time.

* src/client/Client.js (_initBeforeLoadHook): Pass value to event in
  addition to step id.
* src/client/event/RateEventHandler.js: Implement delay.

DEV-6145
master
Mike Gerwitz 2019-09-19 10:51:10 -04:00
parent b2c05fb136
commit 0553060f42
2 changed files with 50 additions and 12 deletions

View File

@ -1877,12 +1877,15 @@ module.exports = Class( 'Client' )
client._quote.visitData( function( bucket )
{
client.program.beforeLoadStep( event.stepId, bucket,
function( event_name )
function( event_name, _, value )
{
event_count++;
client.handleEvent( event_name,
{ stepId: event.stepId },
{
stepId: event.stepId,
value: value,
},
function()
{
try_continue_nav();

View File

@ -80,6 +80,11 @@ module.exports = Class( 'RateEventHandler' )
* argument will contain the result of the rate call. Note that the quote
* will be automatically filled with the return data.
*
* For use as a last resort, there's the ability to delay rating N
* seconds by passing a numeric value via `data`. This is intended as a
* temporary workaround for slow supplier APIs until deferred rating can
* be properly implemented.
*
* @param {string} type event id; ignored
*
* @param {function(*,Object)} continuation to invoke on completion
@ -88,9 +93,14 @@ module.exports = Class( 'RateEventHandler' )
*/
'public handle': function( type, c, data )
{
var _self = this,
quote = this._client.getQuote(),
qstep = quote.getCurrentStepId();
var _self = this;
var quote = this._client.getQuote();
var qstep = quote.getCurrentStepId();
// arbitrary delay before rating (use as a last resort)
var delay = ( typeof +data.value === 'number' )
? data.value * 1e3
: 0;
// do not perform rating if quote is locked; use existing rates, if
// available (stored in bucket)
@ -118,7 +128,14 @@ module.exports = Class( 'RateEventHandler' )
function dorate()
{
_self._performRating( quote, c, data.indv, data.stepId );
_self._scheduleRating( delay, function( finish )
{
_self._performRating( quote, data.indv, data.stepId, function()
{
finish();
c.apply( null, arguments );
} );
} );
}
// perform rating immediately
@ -128,15 +145,36 @@ module.exports = Class( 'RateEventHandler' )
},
'private _performRating': function( quote, c, indv, dest_step_id )
/**
* Prepare to perform rating and schedule dialog to display
*
* If a delay is provided, then rating will be delayed by that number of
* milliseconds. The dialog will be permitted to display during this
* delay period.
*
* @param {number} delay rating delay in milliseconds
* @param {Function} callback continuation after delay
*/
'private _scheduleRating': function( delay, callback )
{
var _self = this;
// queue display of "rating in progress" dialog
var dialog_close = this.queueProgressDialog(
this.__self.$( '_DIALOG_DELAY_MS' )
);
const delay_ms = Math.max( delay, 0 ) || 0;
setTimeout( function()
{
callback( dialog_close );
}, delay_ms );
},
'private _performRating': function( quote, indv, dest_step_id, c )
{
var _self = this;
// grab the rates from the server for the already posted quote data
this._dataProxy.get( this._genRateUrl( quote, indv ),
function( response, err )
@ -160,9 +198,6 @@ module.exports = Class( 'RateEventHandler' )
// let subtypes handle additional processing
_self.postRate( err, data, _self._client, quote );
// close rating dialog after rates are displayed
dialog_close();
// invalidate the step to force emptying of the bucket, ensuring
// that data is updated on the screen when it's re-rated (will
// be undefined if the step hasn't been loaded yet, in which