Async data fetching from different sources for React components made easy.
The project is under heavy development and the API can be changed.
Inspired by Relay. An attempt to create unified container solution.
NB: Transmitter depends on Rx (used as peer dependency).
import AsyncComponent from 'retransmitter/lib/AsyncComponent';
// this component will be used for react-router
// like <Route path="/users/:userId" component={UserInfoPage} />
export default AsyncComponent(UserInfoPage);
async function UserInfoPage({params: {userId}}) {
const user = await UsersAPI.find({id: userId});
return <UserInfo user={user} />;
}
import Container from 'retransmitter/lib/Container';
import fromStore from 'retransmitter/lib/fromStore';
class TodosListContainer extends Container {
observe() {
return {
todos: TodosAPI.getAll(),
query: fromStore(TheStore).map(state => state.query),
};
}
render() {
const {status, todos, query} = this.state;
switch (status) {
case 'success':
return <TodosList todos={todos} query={query} />;
case 'failure':
return <ErrorMessage />;
case 'pending':
return <Spinner />;
}
}
}
Read more in docs
Install via NPM:
npm install --save retransmitter
Require the lib in your code:
import Transmitter from 'retransmitter';
Also you can require particular components:
import AsyncComponent from 'retransmitter/lib/AsyncComponent';
import Container from 'retransmitter/lib/Container';
import fromStore from 'retransmitter/lib/fromStore';
Still using that old syntax?
var Transmitter = require('retransmitter');
NB: If you're NPM3 user please make sure you have these dependencies installed. I'll make these dependencies as own dependencies after NPM3 will be used widely.
- [x] Promises
- [x] Observables
- [x] Falcor (since it uses Promises and Observables)
- [x] Stores (Flux, Redux)
- [ ] CSP channels
- [ ] Relay