This library provides an Arez browser component that wraps a Promise and exposes observable state that tracks the state of the promise.
The simplest way to use component;
- add the following dependencies into the build system. i.e.
<dependency>
<groupId>org.realityforge.arez.promise</groupId>
<artifactId>arez-promise</artifactId>
<version>0.122</version>
</dependency>
-
add the snippet
<inherits name="arez.promise.ObservablePromise"/>
into the .gwt.xml file. -
Use the
ObservablePromise
component. eg.
import com.google.gwt.core.client.EntryPoint;
import elemental2.dom.DomGlobal;
import elemental2.dom.Response;
import elemental2.promise.Promise;
import arez.Arez;
import arez.promise.ObservablePromise;
public class Example
implements EntryPoint
{
public void onModuleLoad()
{
final Promise<Response> promise = DomGlobal.fetch( "https://example.com/" );
final ObservablePromise<Response, Object> observablePromise = ObservablePromise.create( promise );
Arez.context().autorun( () -> {
final String message = "Promise Status: " + observablePromise.getState();
DomGlobal.console.log( message );
} );
}
}
For more information about component, please see the Website. For the source code and project support please visit the GitHub project.
The component was released as open source so others could benefit from the project. We are thankful for any contributions from the community. A Code of Conduct has been put in place and a Contributing document is under development.
The component is licensed under Apache License, Version 2.0.