Skip to content

Deferred Updating

Ralf Bitter edited this page May 17, 2023 · 4 revisions

The Controller

The View

Calling the Controller Handler from Global JavaScript


In cases where updates don't need to happen live you can use the .defer modifier that batches data updates with the next network request as shown in the following example.

The Controller

The controller asynDefer.lc loads the ASYNergy library and the asynDeferView.lc view. It contains a handler that returns a string including the text values of two <input> fields named "searchtermA" and "searchtermB".

<?lc

put "asynDefer,index,query" into gControllerHandlers


command asynDefer
  rigLoaderLoadLibrary "ASYNergy"
end asynDefer


command index
	get rigLoadView("asynDeferView")
end index


command query
  rigAsynRespond "You searched for {{searchtermA}} and {{searchtermB}}"
end query

The View

The view includes two <input> fields using the .defer modifier, a button and a paragraph with an asyn:mutable directive.

Note: You need to add names to the values of defer directives like asyn:model.defer=<handler>.<name>.

The gData variable [[gData["asynergyScript"] ]] is used to load the ASYNergy JavaScript framework.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>

  <body>

    <div style="float: left;margin-right: 20px;">
		
      <input asyn:model.defer="query.searchtermA" type="text">
			
      <input asyn:model.defer="query.searchtermB" type="text">
			
      <button asyn:click="query">Search</button>

    </div>
        
    <div>
      <p asyn:mutable="query"></p>
    </div>


    [[gData["asynergyScript"] ]]
  </body>
</html>

As the user types into the <input> field, no network requests will be sent. Even if the user clicks away from the input field, no requests will be sent.

When the user presses "Search", ASYNergy will send ONE network request containing the text values of both <input> fields, and calls the query controller handler.

This can drastically cut down on network usage when it's not needed.

Calling the Controller handler from Global JavaScript

To call the query handler of the revIgniter controller from global JavaScript use the ASYNergy.emit method, such as:

<script>

  ASYNergy.emit('query');

</script>
Clone this wiki locally