cycle-connection-driver

1.0.2 • Public • Published

cycle-connection-driver

A Cycle.js driver for connection status

Travis build status Code Climate Test Coverage Dependency Status devDependency Status

Motivation

Many web apps respond to when a user goes online or offline. For example, Slack displays a warning message and prevents you from typing a new message when you go offline.

This driver helps you respond to changes to a user's connection status within Cycle.js.

Installation

The recommended installation method is through npm:

npm install cycle-connection-driver

Getting Started

The output of this driver is a single Observable. This Observable emits one of two values: "online" and "offline", corresponding to whether the user has become connected or disconnected. The initial value of the stream is the user's connection status at the time that your app's main function is passed to run.

This driver accepts no sinks.

import {run} from '@cycle/core';
import {makeDOMDriver, div} from '@cycle/dom';
import cycleConnectionDriver from 'cycle-connection-driver';
 
function main({Connection}) {
  return {
    DOM: Connection.map(connectionStatus =>
      div('.connection-status', `Connection - Currently ${connectionStatus}`)
    )
  };
}
 
run(main, {
  DOM: makeDOMDriver('.app'),
  Connection: cycleConnectionDriver
});

When Not To Use This Library

This is a small module. You're free to download it from npm – it's not going anywhere – but you could also copy and paste it into your own application.

Package Sidebar

Install

npm i cycle-connection-driver

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • jmeas