@sayari/falcor-connect
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Falcor Connect

React-Falcor bindings and a Higher Order Component

Usage

See /examples.

import { createElement } from 'react';
import { Model } from 'falcor'
import { createEventHandler, compose, withProps } from 'recompose'
import { Observable } from 'rxjs'
import { ChildProps, FalcorList, WithFalcor } from '../src'


const {
  stream: graphChange$,
  handler: graphChange,
} = createEventHandler<void, Observable<void>>()

const model = new Model({
  cache: {},
  onChange: graphChange as () => void,
})
  .batch()
  .boxValues()
  .treatErrorsAsValues()


const withFalcor = WithFalcor(model, graphChange$)

type Fragment = {
  todos: FalcorList<{ label: string, status: 'pending' | 'complete' }>
}

export const TodoList = compose(
  withProps({ page: 0 }),
  withFalcor<{ page: number }, Fragment>(({ page }) => [
    ['todos', { from: page, to: page + 10 }, ['label', 'status']],
    ['todos', 'length']
  ]),
  ({ page, graph: { todos }}: ChildProps<{ page: number }, Fragment>) => {
    return createElement('div', {},
      createElement('ul', {},
        Object.keys(todos)
          .filter((key) => key !== 'length')
          .map((key) => (
            createElement('li', {
              className: todos[key].status,
              key: todos[key].label
            }, todos[key].label)
          ))),
      createElement('p', {}, `Showing ${page * 10} to ${page * 10 + 10} of ${todos.length}`)
    )
  }
)

Readme

Keywords

none

Package Sidebar

Install

npm i @sayari/falcor-connect

Weekly Downloads

28

Version

0.3.0

License

ISC

Unpacked Size

95.2 kB

Total Files

70

Last publish

Collaborators

  • anigussie
  • dak52
  • cgroth
  • tyler-tm
  • mtomran
  • elismith
  • doelfke
  • trimtab
  • d-s-g
  • seanathon
  • jferrell-sayari
  • mmoorer90
  • james.lane.conkling
  • julietadams
  • mggower