platform/packages/poll
2022-01-04 20:03:52 +08:00
..
.idea Add 'packages/poll/' from commit '14637ac137e083a90e1db397f0a90561888c3bde' 2020-02-15 18:29:16 -05:00
example Merged from sdk-2.12.x_nnbd 2021-06-20 20:37:20 +08:00
lib Merged from sdk-2.12.x_nnbd 2021-06-20 20:37:20 +08:00
test Merged from sdk-2.12.x_nnbd 2021-06-20 20:37:20 +08:00
.gitignore Add 'packages/poll/' from commit '14637ac137e083a90e1db397f0a90561888c3bde' 2020-02-15 18:29:16 -05:00
.travis.yml Add 'packages/poll/' from commit '14637ac137e083a90e1db397f0a90561888c3bde' 2020-02-15 18:29:16 -05:00
analysis_options.yaml Updated linter 2022-01-04 20:03:52 +08:00
AUTHORS.md Merged from sdk-2.12.x_nnbd 2021-06-20 20:37:20 +08:00
CHANGELOG.md Merged from sdk-2.12.x_nnbd 2021-06-20 20:37:20 +08:00
LICENSE Updated linter 2022-01-04 20:03:52 +08:00
poll.iml Add 'packages/poll/' from commit '14637ac137e083a90e1db397f0a90561888c3bde' 2020-02-15 18:29:16 -05:00
pubspec.yaml Updated linter 2022-01-04 20:03:52 +08:00
README.md Add 'packages/poll/' from commit '14637ac137e083a90e1db397f0a90561888c3bde' 2020-02-15 18:29:16 -05:00

poll

Pub build status

package:angel_client support for "realtime" interactions with Angel via long polling.

Angel supports WebSockets on the server and client, which makes it very straightforward to implement realtime collections. However, not every user's browser supports WebSockets. In such a case, applications might gracefully degrade to long-polling the server for changes.

A PollingService wraps a client-side Service (typically a REST-based one), and calls its index method at a regular interval. After indexing, the PollingService performs a diff and identifies whether items have been created, modified, or removed. The updates are sent out through onCreated, onModified, etc., effectively managing a real-time collection of data.

A common use-case would be passing this service to ServiceList, a class that manages the state of a collection managed in real-time.

import 'package:angel_client/io.dart';
import 'package:angel_poll/angel_poll.dart';

main() {
  var app = new Rest('http://localhost:3000');

  var todos = new ServiceList(
    new PollingService(
      // Typically, you'll pass a REST-based service instance here.
      app.service('api/todos'),

      // `index` called every 5 seconds
      const Duration(seconds: 5),
    ),
  );

  todos.onChange.listen((_) {
    // Something happened here.
    // Maybe an item was created, modified, etc.
  });
}