Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
/ arez-promise Public archive

Arez component that wraps a Promise and makes it observable

License

Notifications You must be signed in to change notification settings

arez/arez-promise

Repository files navigation

Arez-Promise

Build Status

This library provides an Arez browser component that wraps a Promise and exposes observable state that tracks the state of the promise.

Quick Start

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 );
    } );
  }
}

More Information

For more information about component, please see the Website. For the source code and project support please visit the GitHub project.

Contributing

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.

License

The component is licensed under Apache License, Version 2.0.