0.0.3 • Published 9 years ago

@r7kamura/cycle-fetcher-driver v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

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(
  ({ DOM, HTTP }) => {
    const url = 'http://example.com';
    const request$ = Rx.Observable.just({ method: 'GET', url });
    const vtree$ = responses.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()
  }
);