All Projects → axross → repromised

axross / repromised

Licence: MIT license
🤝 Declarative promise resolver as a render props component

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to repromised

paginated
⚛️ React render props component & custom hook for pagination.
Stars: ✭ 20 (+0%)
Mutual labels:  render-props
react-combine-contexts
🚀Use multiple React Contexts without pain.
Stars: ✭ 23 (+15%)
Mutual labels:  render-props
PromisedFuture
A Swift based Future/Promises framework to help writing asynchronous code in an elegant way
Stars: ✭ 75 (+275%)
Mutual labels:  promise
mst-effect
💫 Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-5%)
Mutual labels:  promise
react-callbag-listener
👂 A React render-prop component that listens to values emitted by callbags
Stars: ✭ 21 (+5%)
Mutual labels:  render-props
indexeddb-orm
Indexed DB ORM
Stars: ✭ 53 (+165%)
Mutual labels:  promise
vue2-element
基于vue2 + vue-router2 + element-ui + vuex2 + fetch + webpack2 企业级后台管理系统最佳实践
Stars: ✭ 115 (+475%)
Mutual labels:  promise
promise-abortable
Promise lib for aborting in chain.
Stars: ✭ 19 (-5%)
Mutual labels:  promise
mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (+415%)
Mutual labels:  promise
co demo
A step-by-step guide about how to avoid callback hell with ES6 Promises + generators (aka make your own "co")
Stars: ✭ 17 (-15%)
Mutual labels:  promise
ngx-localstorage
An Angular wrapper for localstorage/sessionstorage access.
Stars: ✭ 27 (+35%)
Mutual labels:  promise
etsy-ts
Etsy API wrapper written in typescript
Stars: ✭ 18 (-10%)
Mutual labels:  promise
miniprogram-network
Redefine the Network API of Wechat MiniProgram (小程序网络库)
Stars: ✭ 93 (+365%)
Mutual labels:  promise
rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
Stars: ✭ 18 (-10%)
Mutual labels:  promise
nodeJS examples
Server, routing, db examples using NodeJS v6
Stars: ✭ 34 (+70%)
Mutual labels:  promise
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (+420%)
Mutual labels:  promise
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (+65%)
Mutual labels:  promise
rmfr
Node.js implementation of rm -fr – recursive removal of files and directories
Stars: ✭ 23 (+15%)
Mutual labels:  promise
PiedPiper
A small set of classes and functions to make easy use of Futures, Promises and async computation in general. All written in Swift for iOS 10+, WatchOS 3, tvOS and Mac OS X apps.
Stars: ✭ 44 (+120%)
Mutual labels:  promise
wtsqs
Simplified Node AWS SQS Worker Wrapper
Stars: ✭ 18 (-10%)
Mutual labels:  promise

Repromised

npm GitHub stars GitHub license

Repromised is a component to build children by resolving a promise with Render Props pattern.

  • 🚀 Dependency free
  • 🏄‍ Extremely tiny
  • 🔌 Plug and Play
  • 👷 Well tested
  • 👔 Built with TypeScript

Example

TRY IT OUT HERE

Repromised Example

Install

npm i -S repromised

APIs

<Repromised>

Props

Name Type Required Description
promise () => Promise<Value> A function returning a promise (it will be called when the component is mounted)
initial Value (the same type with the value what the promise should resolves) An initial value
children (snapshot: Snapshot) => ReactNode A render props function

Snapshot

<Repromised> receives children as a render-props pattern function that gives a snapshot object which has the shape like the following:

Name Type Description
status "PENDING", "FULFILLED" or "REJECTED" The promise's status. In TypeScript you can use Status enum instead of string enum
value Value (the value what the promise resolves) or null The value what the promise resolves. When status is "PENDING" or "REJECTED" and props.initial is not given, this is null
error Error or null The error when the promise rejects. This is null if status is not "REJECTED"
isLoading boolean A short hand value whether the promise's status is "PENDING" or not (same with to status === "PENDING").
requireValue Value (the value what the promise resolves) Same as value but it throws an error if value is null

Usage

import Repromised from 'repromised';

const SearchResult = ({ query }) => (
  <Repromised promise={() => fetchByQuery(query)} initial={[]} key={query}>
    {snapshot => snapshot.isLoading
      ? <Loading />
      : <ResultList>
          {snapshot.value.map(result => <ResultListItem result={result} />)}
        </ResultList>
    }
  </Repromised>
);

License

MIT

Contribute

Any feedback is welcome! You can help improving this project leaving Pull requests and helping with Issues.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].