• Stars
    star
    393
  • Rank 106,178 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Compose render props imperatively with async/await/CPS kinda sugar

epita✞h

All Contributors

In memoriam HOCs and Render Props

Read the article

Also, we think you may want to take a look on React Hooks API now

import epitath from 'epitath'
...

const App = epitath(function*() {
  const { loading, data } = yield <Query />
  const { time } = yield <Time />

  return (
    <div className="App">
      {loading ? (
        <h1>Loading</h1>
      ) : (
        <div>
          <h1>{`Hello, ${data.user.name}`}</h1>
          <h2>The time is {time.toLocaleString()}!</h2>
        </div>
      )}
    </div>
  )
})

npm package

Compose HOCs imperatively like async/await. No callback hell!

Live demo Source of demo

Install

yarn add epitath

or

npm install --save epitath

Why

Render props are amazing for providing more functionality but once you need to stack a bunch of them you get what recalls a painful callback hell.

<Query>
  {({ data }) =>
    <Mutation>
      {({ mutate, result })=>
        <Form>
        etc
        </Form>
      }
    </Mutation>
  }
</Query>

How

Wait, we just mentioned "callback hell". So what if we had a function that would allow us to have a kind of sugar for continuation-passing-style Γ  la async/await?

And that's exactly what epitath is, it just takes care of the callbacks for you. The whole code is this:

import React from 'react'
import immutagen from 'immutagen'

export default component => {
  const generator = immutagen(component)

  const compose = context => {
    const value = context.value
    return context.next
      ? React.cloneElement(value, null, values => compose(context.next(values)))
      : value
  }

  function Epitath(props) {
    return compose(generator(props))
  }

  Epitath.displayName = `EpitathContainer(${component.displayName || 'anonymous'})`

  return Epitath
}

Note that epitath will only yield the first argument of the render function. In order to consume multiple arguments, we recommend creating a wrapper component:

const MutationWrapper = ({ children, ...props }) =>
  <Mutation {...props}>{(mutate, result) => children({ mutate, result })}</Mutation>

const { mutate, result } = yield <MutationWrapper />

How is this different from Suspense?

Suspense only allows you to evalulate a promise once. It does not allow you to trigger a re-render for a state update. And with epitath you can even use Formik, Apollo optimistic, React Powerplug and Smalldots tooling and etc!

BTW it's epitaph not "epitath"

"These Astrocoders dudes simply don't know how to spell words in English!"

Actually it was intended, for 2 reasons:

  1. We wanted to put a cross as icon of the package
  2. Epitaph is already taken in NPM

Contributing

Steps to get it running

Install the deps

yarn install

Boot the demo

yarn start

Things missing that we would like a little help

  • Tests
  • TypeScript support

Acknowledgements

Thanks @jamiebuilds for the suggestions on how simplifying the API

Contributors

Thanks goes to these wonderful people (emoji key):


Jamie

πŸ€” πŸ’»

Eli Perelman

πŸ€” πŸ’»

Gabriel Rubens

πŸ€” πŸ’»

Medson Oliveira

πŸ€” πŸ’»

George Lima

πŸ€” πŸ’»

Eliabe JΓΊnior

πŸ’» 🎨

Guilherme Decampo

πŸ€”

gtkatakura

πŸ€” πŸ’¬ πŸ’‘

Erjan Kalybek

πŸ“–

Jack Hanford

πŸ“–

Haz

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

More Repositories

1

nubank-api

NuBank API - Not related to Nu Pagamentos S.A.
JavaScript
564
star
2

react-native-selectable-text

Capture text selection and customize the action menu
Objective-C
220
star
3

lenses-ppx

GADT lenses
Reason
106
star
4

react-image-smooth-loading

[not maintained] Images which just flick to appear aren't cool. Images which appear smoothly with a fade like Instagram are cool
JavaScript
85
star
5

restyled

Styled Components concept for Reason React, only works with bs-react-native for now
OCaml
69
star
6

node-pdf-invoice

A Phantom free PDF invoice generator built with PDFKit
JavaScript
62
star
7

recontainers

[DEPRECATED] ReasonReact utilitary high order components
Reason
54
star
8

nubank-clone

NuBank's app clone built with React Native
JavaScript
48
star
9

meteor-astrocoders-publish

Smartly re-use Meteor publications logic
JavaScript
33
star
10

bs-epitath

Render Props CPS-like composition for ReasonReact
OCaml
29
star
11

fullstack-challenge

This is our Fullstack Test. If you want to be an astrocoder... Just do it!
28
star
12

bs-reason-apollo

ReactApollo bindings for BS
OCaml
23
star
13

astroman

Command-line interface for creating new sites based on Gatsby, ReasonML or Create React App
JavaScript
20
star
14

astro-design

Astro Design Components
OCaml
20
star
15

waterfall

JavaScript
17
star
16

react-native-tooltip-view

A deadly simple tooltip view that you can put whatever you want πŸŽ‰
JavaScript
17
star
17

reason-epitath

CPS sugar usage for React Render Props composition in ReasonML
HTML
16
star
18

bacen-exchange-rates

Reason API to fetch the daily reports from BACEN PTAX exchanges
OCaml
16
star
19

bs-react-native-vector-icons

ReasonML bindings for react-native-vector-icons
OCaml
16
star
20

product-cart-reason-graphql-react-native

OCaml
16
star
21

minha-lojinha-pix

JavaScript
15
star
22

emv-parser

A simple and lightweight emv-parser made for human beings
JavaScript
15
star
23

astrocoders-landing

Astrocoders landing
JavaScript
14
star
24

pix-dashboard

PIX dashboard
Reason
14
star
25

astroapp-rn-boilerplate

AstroApp, all backend React Native app boilerplate
JavaScript
13
star
26

meteor-one-signal

Basic Meteor and OneSignal integration. If you would like to contribute send us your PR!
JavaScript
12
star
27

summhub-server

Notifications hub
Reason
12
star
28

bs-package-boilerplate

A BuckleScript NPM package boilerplate
OCaml
12
star
29

rn-meteor-containerize

A React Container component designed specially for react-native-meteor
JavaScript
11
star
30

nautilus

OCaml
10
star
31

bs-universe

OCaml
10
star
32

meteor-slack-logs

Client | Server logs on a slackchannel. If you would like to contribute send us your PR!
JavaScript
9
star
33

old-astroman

Rapid scaffolding for React Native, Meteor and React Boilerplate projects (but now focused on RN)
JavaScript
9
star
34

postgres-orm

A lightweight and simple ORM on top of node-postgres
TypeScript
8
star
35

pdfmake-to-html

An experiment to convert pdfmake's JSON tree into a DOM tree
JavaScript
7
star
36

gen

As simple as a generator can be
JavaScript
7
star
37

astro-graphql-pg-ocaml

GraphQL server in OCaml with PG
OCaml
7
star
38

auto-star-github

JavaScript
7
star
39

lambdasorocaba-5-onegraph

OCaml
6
star
40

bs-react-native-linear-gradient

Bucklescript bindings for react-native-linear-gradient
OCaml
6
star
41

open-faas-node12-template

JavaScript
6
star
42

react-horizontal-stepper

JavaScript
6
star
43

bs-react-feather

Reason bindings for react-feather
OCaml
5
star
44

universe-landing

Landing page for universe - finding bindings of ReasonML to JS
TypeScript
5
star
45

bs-monorepo-boilerplate

JavaScript
5
star
46

bs-react-native-router-flux

BuckeScript bindings for RNRF, really really not ready yet
OCaml
5
star
47

pix-br-code

5
star
48

pix-e-zapsign

JavaScript
5
star
49

typezy

Head to head typing game that ends with someone tipsy!
JavaScript
4
star
50

jest-meteor-mocks

Common Meteor mocks for Jest
JavaScript
4
star
51

reasonml-starter

JavaScript
4
star
52

summhub-app

OCaml
4
star
53

meteor-talker

Reactively re-runs a client code whenever a server condition changes
JavaScript
4
star
54

react-show-on-scroll-top

Show Component's children whenever the user scrolls towards the top
JavaScript
4
star
55

qldbex

QLDB Elixir Interface
Elixir
4
star
56

ex_aws_qldb

Elixir QLDB
Elixir
3
star
57

react-currency-masked-input

Input masking for currency, in React
JavaScript
3
star
58

meteor-nice-correios

Get Correios shipping costs without complications
JavaScript
3
star
59

holidays-br

BR holidays
C++
2
star
60

docker-circleci-ocaml

CircleCI docker for opam and ocalm
2
star
61

compose-with-tracker

react-komposer helper for Meteor Tracker system
JavaScript
2
star
62

pivotal-stats

Simple CLI for fetching contributors stats from your Pivotal Tracker
JavaScript
2
star
63

zipcodes

Zipcodes API server
JavaScript
2
star
64

meteor-supercollection

Enforce readability and simplify your mongo queries in Meteor
JavaScript
2
star
65

bs-material-ui-pickers

OCaml
2
star
66

meteor-infinite-scroll

Simple infinite scroll
JavaScript
2
star
67

sum-price-tool-extension

JavaScript
2
star
68

rn-redux-form-field

A Field wrapper using Native Base components
JavaScript
1
star
69

summary-screen

JavaScript
1
star
70

ex_pix_utils

PIX utils
Elixir
1
star
71

alexa-pivotal-tracker

Alexa meets Pivotal Tracker. An Alexa integration with Pivotal Tracker.
JavaScript
1
star
72

unanimity

Search across multiple REST APIs keeping results in unanimity
JavaScript
1
star
73

astropdf

A React JSX syntax-like for pdfMake experiment
JavaScript
1
star
74

meteor-subscribe-with-scroll

Infinite Scroll with Meteor subscription system
JavaScript
1
star
75

reasonreact-graphql-boilerplate

A reasonable boilerplate for ReasonReact and GraphQL
JavaScript
1
star
76

meteor-intl-tel-input

International input masker
JavaScript
1
star
77

remmet

Emmet for react!
1
star
78

meteor-method-with-scroll

Call to a Meteor method with a incrementing skip param when onInfinite event of InfiniteScroll is fired.
JavaScript
1
star
79

cra-starter

JavaScript
1
star
80

bs-fluture

Fluture bindings to BuckleScript
1
star
81

meteor-accounts-fb-hook

Grabs user's Facebook info and save them in profile.
JavaScript
1
star
82

sum-up-hour-tool

How much I will get paid ?
HTML
1
star
83

decoratr

A simple factory function that constructs a ES7 decorator
JavaScript
1
star
84

rustler_mjml

Elixir
1
star
85

react-native-starter

JavaScript
1
star
86

astrocoders-guerrillamail

JavaScript
1
star
87

react-number-format

React component to format numbers in an input or as a text.
JavaScript
1
star
88

ganalytics-error-logger

Easiest way to track errors client/server side with google analytics
JavaScript
1
star