Home

Awesome

cycle-fetcher-driver

A Cycle.js Driver for making HTTP requests using stackable-fetcher.

Install

npm install @r7kamura/cycle-fetcher-driver

Usage

import Cycle from '@cycle/core';
import { h, makeDOMDriver } from '@cycle/dom'
import { makeFetcherDriver } from '@r7kamura/cycle-fetcher-driver';

Cycle.run(
  ({ HTTP }) => {
    const url = 'http://example.com';
    const request$ = Cycle.Rx.Observable.just({ method: 'GET', url });
    const vtree$ = HTTP
      .filter((response$) => response$.request.url === url)
      .mergeAll()
      .map(({ body }) => body)
      .startWith('Loading...')
      .map(text => h('h1', text));
    return {
      DOM: vtree$,
      HTTP: request$
    };
  },
  {
    DOM: makeDOMDriver('body'),
    HTTP: makeFetcherDriver()
  }
);

image