-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
390 lines (342 loc) · 18.2 KB
/
index.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Redux relax">
<meta name="author" content="Dimitris Saltaferis">
<link rel="apple-touch-icon" sizes="57x57" href="page/img/icos/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="page/img/icos/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="page/img/icos/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="page/img/icos/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="page/img/icos/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="page/img/icos/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="page/img/icos/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="page/img/icos/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="page/img/icos/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="page/img/icos/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="page/img/icos/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="page/img/icos/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="page/img/icos/favicon-16x16.png">
<link rel="manifest" href="page/img/icos/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="page/img/icos/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<title>Redux relax</title>
<!-- Bootstrap Core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
<!-- Theme CSS -->
<link href="page/css/agency.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js" integrity="sha384-0s5Pv64cNZJieYFkXYOTId2HMA2Lfb6q2nAcx2n0RTLUnCAoTTsS0nKEO27XyKcY" crossorigin="anonymous"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" integrity="sha384-ZoaMbDF+4LeFxg6WdScQ9nnR1QC2MIRxA1O9KWEXQwns1G8UNyIEZIQidzb0T1fo" crossorigin="anonymous"></script>
<![endif]-->
</head>
<body id="page-top" class="index">
<!-- Navigation -->
<nav id="mainNav" class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand page-scroll" href="#page-top">Redux Relax</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
<a href="#page-top"></a>
</li>
<li>
<a class="page-scroll" href="#why">Why</a>
</li>
<li>
<a class="page-scroll" href="#less-code">The Difference</a>
</li>
<li>
<a class="page-scroll" href="#installation">Installation</a>
</li>
<li>
<a class="page-scroll" href="#how">How</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<!-- Header -->
<header>
<div class="container">
<div class="intro-text">
<div class="intro-lead-in">Data loader for react & redux</div>
<div id="intro-typewriter"></div>
</div>
</div>
</header>
<!-- Services Section -->
<section id="why">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Why to use it?</h2>
</div>
</div>
<div class="row text-center">
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-bath fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">Easy to use</h4>
<p class="text-muted">You have to add your initial configurations and then you just ask what you need from the data store.</p>
</div>
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-refresh fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">Efficiency & Consistency</h4>
<p class="text-muted">This library fetch and stores your data on reducers normalized, keeping your data updated & consistent, avoiding duplicate entities.</p>
</div>
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-wrench fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">Customization</h4>
<p class="text-muted">You can always add custom logic on reducers or on saga middleware.</p>
</div>
</div>
</div>
</section>
<!-- Services Section -->
<section id="less-code">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Show me the difference</h2>
</div>
</div>
<div class="row text-center">
<div class="col-lg-6">
<h3 class="section-subheading text-muted">Saga </h3>
<div class="row">
From <a href="https://github.com/redux-saga/redux-saga/blob/master/examples/real-world/sagas/index.js" target="_blank"> <strong>130lines</strong> </a>
to ~> <a href="https://github.com/saltas888/redux-relax/blob/saga/real-world-saga/sagas/index.js" target="_blank"> <strong>23lines</strong> </a>
</div>
<div class="row">
From <a href="https://github.com/redux-saga/redux-saga/blob/master/examples/real-world/actions/index.js" target="_blank"> <strong>63lines</strong> </a>
to ~> <a href="https://github.com/saltas888/redux-relax/blob/saga/real-world-saga/sagas/index.js" target="_blank"> <strong>15lines</strong> </a>
</div>
</div>
<div class="col-lg-6">
<h3 class="section-subheading text-muted">Thunk </h3>
From <strong>121lines</strong>
to ~> <a href="https://github.com/saltas888/redux-relax/blob/thunk/real-world-thunk/src/actions/index.js" target="_blank"> <strong>9lines</strong> </a>
</div>
</div>
</div>
</section>
<!-- About Section -->
<section id="installation">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Installation</h2>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h3 class="section-subheading text-muted">If you use
<a href="https://github.com/redux-saga/redux-saga" target="_blank"> redux-saga </a>
</h3>
<pre><code class="bash">
npm i --save redux-relax-saga
</code></pre>
<h3 class="section-subheading text-muted">If you use <a href="https://github.com/gaearon/redux-thunk" target="_blank"> redux-thunk </a></h3>
<pre><code class="bash">
npm i --save redux-relax-thunk
</code></pre>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h3 class="section-subheading text-muted">Setting up </h3>
<pre><code class="javascript">
import { createStore } from 'redux';
import DevTools from '../containers/DevTools';
import rootReducer from '../reducers';
import ReduxRelaxEnchancer from 'redux-relax-thunk';
const configs = {
dev: true,
apiEndpoint: 'https://api.github.com/',//required
getHeaders: (state) => ({ }),
reducers: {
paginate: {
totalPageCountField: 'pages', //required
totalCountField: 'totalCount', //required
currentPageField: undefined //optional
},
},
entities: [
{
uniqueIdAttribute: 'login', // The field that is used as unique id - Required
name: 'users', // Name of the entities field in state- Required
itemsField: 'items', // the field on response payload that includes our data
singleApiUrl: login => `users/${login.toString()}` // The route to base endpoint to fetch a single entity - Required,
apiUrl: login => `repos/${login}/stargazers`, // The route to base endpoint to fetch multiple entities - Required,
paginationKey: 'login',
}, {
uniqueIdAttribute: 'fullName',
name: 'repos',
itemsField: 'items',
singleApiUrl: fullName => `repos/${fullName}`,
apiUrl: login => `users/${login}/starred`,
paginationKey: 'fullName',
},
]
}
const store = createStore(
rootReducer,
{},
ReduxRelaxEnchancer(configs, [DevTools.instrument()]),
);
export default store
</code></pre>
</div>
</div>
</div>
</section>
<!-- Portfolio Grid Section -->
<section id="how" class="bg-light-gray">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">How to use it?</h2>
</div>
</div>
<div class="row">
<pre><code class="javascript">
@multiple('repos', (state, ownProps) => {
const { login } = state.router.params; //The pagination key to get all repos for user with username = {login}
return { search: login};
})
@single('users', (state, ownProps) => {
const { login } = state.router.params; //The entities key to get user with id = {login}
return login;
})
class UserPage extends Component {
componentWillReceiveProps(nextProps) {
if (this.props.login !== nextProps.login) {
this.props.loadUser(nextProps.login) //You also have loadUser as prop since you asked for @single - users
this.props.loadRepos(nextProps.login) //You also have loadRepos as prop since you asked for @multiple - repos
}
}
handleLoadMoreClick() {
this.props.loadMoreRepos(this.props.login) // You also have loadMoreRepos as prop since you asked for multiple - repos
}
render() {
...
}
};
function mapStateToProps(state) {
const { login } = state.router.params
const {
entities: { users, repos }
} = state
return {
login,
user: users[login]
}
}
export default connect(mapStateToProps, {
})(UserPage)
</code></pre>
</div>
<h3 class="section-subheading text-muted">Or without decorators...</h3>
<div class="row">
<pre><code class="javascript">
class UserPage extends Component {
componentWillReceiveProps(nextProps) {
if (this.props.login !== nextProps.login) {
this.props.loadUser(nextProps.login) // You also have loadUser as prop since you asked for single - users
this.props.loadRepos(nextProps.login) // You also have loadRepos as prop since you asked for multiple - repos
}
}
handleLoadMoreClick() {
this.props.loadMoreRepos(this.props.login) // You also have loadMoreRepos as prop since you asked for multiple - repos
}
render() {
...
}
};
UserPage = multiple('repos', (state, ownProps) => {
const { login } = state.router.params; //The pagination key to get all repos for user with username = {login}
return { search: login };
})(UserPage);
UserPage = single('users', (state, ownProps) => {
const { login } = state.router.params; //The entities key to get user with id = {login}
return login;
})(UserPage)
function mapStateToProps(state) {
const { login } = state.router.params
const {
entities: { users, repos }
} = state
return {
login,
user: users[login]
}
}
export default connect(mapStateToProps, {
})(UserPage)
</code></pre>
</div>
</div>
</section>
<footer>
<div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<ul class="list-inline social-buttons">
<li><a href="https://github.com/saltas888/redux-relax"><i class="fa fa-github"></i></a>
</li>
</ul>
</div>
<div class="col-md-4">
<ul class="list-inline quicklinks">
</ul>
</div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" integrity="sha384-mE6eXfrb8jxl0rzJDBRanYqgBxtJ6Unn4/1F7q4xRRyIw7Vdg9jP4ycT7x1iVsgb" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/TypewriterJS/1.0.0/typewriter.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<!-- Contact Form JavaScript -->
<script src="page/js/jqBootstrapValidation.js"></script>
<!-- Theme JavaScript -->
<script src="page/js/agency.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>