GitXplorerGitXplorer
s

paradox.dart

public
7 stars
4 forks
0 issues

Commits

List of commits on branch master.
Unverified
2766e0f407b607866db5547644e9b945d45a1360

add a homepage to pubspec

ssethladd committed 11 years ago
Unverified
88aaac356a7a04e62e5d3279d60a6bc6a0bb598d

clarification on how it works

ssethladd committed 11 years ago
Unverified
64da92149fdda362aa48eca548464c21da11812d

merge from origin

ssethladd committed 11 years ago
Unverified
2e283bcffe8f5a2a803f06e975a63022dda508c1

add status

ssethladd committed 11 years ago
Unverified
2e45daa31b25733fc510074971f5ac269065c75d

Initial commit

ssethladd committed 11 years ago
Unverified
62ce49ff490e5e48f96539db2fcd5cc51ca636c4

first commit

ssethladd committed 11 years ago

README

The README file for this repository.

Paradox

Working with HttpRequests, even when offline

This library is an attempt to help you write offline-first apps. It queues up HttpRequests and retries them until successful. Your requests are retried until you are online and the request is a success.

Usage

library example;

import 'package:paradox/paradox.dart';
import 'dart:html';

main() {
  init().then((SendHttpRequest sendRequest) {
    querySelector('button').onClick.listen((e) {
      String data = 'msg=hi';
      if ((querySelector('#force-error') as InputElement).checked) {
        data += '&error=true';
      }
      sendRequest('http://localhost:8888/test',
          method: 'POST',
          requestHeaders: {'Content-Type': 'application/x-www-form-urlencoded'},
          sendData: data);
    });
  });

How it works

The library is initialized with init(), which configures a local database using the Lawndart library.

Send requests using sendRequest, which has the same interface as HttpRequest.request. The request is first stored locally. Then, the request is tried. If successful, the request is deleted from the local storage.

If the request fails for any reason (network, server 500, gremlins), a timer is started for a retry. The timer fires at a constant rate until all stored requests are successfully sent.

Each request is given a time to next retry, which exponentially increases with every request. While the internal timer fires at a constant rate, individual requests are increasingly delayed until successful.

If the browser detects the network connection is offline, no retries will happen. Only when the browser detects the network connection is online will retries occur again.

Therefore, if the browser says the connection is offline, all requests go straight to the local database and no network connectivity is attempted. If the browser thinks it is online, all requests are tried.

Feedback on the algorithm is much appreciated.

Browser compatibility

This library should support all modern browsers, thanks to Lawndart.

Status

Very much alpha. Feedback welcome!

Bugs and source

Please file issues and feature requests. You can get the source code from Github.

See LICENSE.