forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
51 lines (46 loc) · 1.87 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { connect } from 'react-redux';
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { component as Users,
selectors as usersSel,
actions as usersActions } from './users/index';
const { usersFetch, usersFetchCancel } = usersActions;
export function App({ users, fetchStatus, usersFetch, usersFetchCancel }) {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Async RxJS Ajax Fetch</h2>
</div>
<div className="usersDiv">
<div className="desc">
<p>Demonstrates the use of redux-logic to perform async fetching using RxJS ajax (with xhr abort on cancel). This example uses the built-in declarative functionality for cancellation and limiting (takeLatest).
</p>
<p><b>Usage:</b> Click on the fetch button to initiate a fetch, click cancel to abort the fetch, or click the fetch button multiple times to see that only the last fetch is used.
</p>
<p>The logic code for this example lives in <code>src/users/logic.js</code>. The logic middleware setup and runtime dependencies injected into logic are in <code>src/configureStore.js</code>
</p>
<p>Note: fetching has an artificial 4s delay to allow for interacting with the cancellation and take latest functionality.
</p>
</div>
<div className="main">
<Users arrUsers={ users } fetchStatus={ fetchStatus }
onFetch={ usersFetch }
onCancelFetch={ usersFetchCancel } />
</div>
</div>
</div>
);
}
const enhance = connect(
state => ({
users: usersSel.users(state),
fetchStatus: usersSel.fetchStatus(state)
}),
{
usersFetch,
usersFetchCancel
}
);
export default enhance(App);