Package arez.dom

Class NetworkStatus

java.lang.Object
arez.dom.NetworkStatus

@ArezComponent(requireId=DISABLE) public abstract class NetworkStatus extends Object
An observable model that declares state that tracks when the user is "online". The online state is essentially a reflection of the browsers "navigator.onLine" value. If an observer is observing the model, the model listens for changes from the browser and updates the online state as appropriate. However if there is no observer for the state, the model will not listen to to the browser events so as not to have any significant performance impact.

A very simple example


 import com.google.gwt.core.client.EntryPoint;
 import akasha.Global;
 import akasha.Console;
 import arez.Arez;
 import arez.networkstatus.NetworkStatus;

 public class NetworkStatusExample
   implements EntryPoint
 {
   public void onModuleLoad()
   {
     final NetworkStatus networkStatus = NetworkStatus.create();
     Arez.context().observer( () -> {
       Console.log( "Network Status: " + ( networkStatus.isOnLine() ? "Online" : "Offline" ) );
       if ( networkStatus.isOffLine() )
       {
         Console.log( "Offline since: " + networkStatus.getLastChangedAt() );
       }
     } );
   }
 }
 
  • Method Details

    • create

      @Nonnull public static NetworkStatus create()
      Create an instance of NetworkStatus.
      Returns:
      the NetworkStatus instance.
    • isOffLine

      public boolean isOffLine()
      Return true if the browser is offline, false otherwise.
      Returns:
      true if the browser is offline, false otherwise.
    • isOnLine

      Return true if the browser is online, false otherwise.
      Returns:
      true if the browser is online, false otherwise.
    • getLastChangedAt

      @Observable @Nonnull public abstract Date getLastChangedAt()
      Return the last time at which online status changed. This will default to the time the component was created, otherwise the time at which the online status was changed.
      Returns:
      the last time at which online status changed.