-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
501 lines (413 loc) · 17.3 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>listate Index</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.spacelab.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top ">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">listate</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="topNavigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="module-listate.html">listate</a></li><li><a href="module-listate_extra.html">listate/extra</a></li>
</ul>
</li>
</ul>
<div class="col-sm-3 col-md-3">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
<div class="input-group-btn">
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container" id="toc-content">
<div class="row">
<div class="col-md-8">
<div id="main">
<section class="readme-section">
<article><h1>listate <a name="start"></a></h1><p>Library to listen/observe/watch changes of Redux store state.</p>
<p><a href="http://badge.fury.io/js/listate"><img src="https://badge.fury.io/js/listate.png" alt="NPM version"></a>
<a href="http://travis-ci.org/gamtiq/listate"><img src="https://secure.travis-ci.org/gamtiq/listate.png?branch=master" alt="Build Status"></a></p>
<h2>Table of contents</h2><ul>
<li><a href="#install">Installation</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#api">API</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
</ul>
<h2>Installation <a name="install"></a> <a href="#start">↑</a></h2><h3>Node</h3><pre class="prettyprint source"><code>npm install listate</code></pre><h3><a href="http://bower.io">Bower</a></h3><pre class="prettyprint source"><code>bower install listate</code></pre><h3>AMD, <script></h3><p>Use <code>dist/listate.js</code> or <code>dist/listate.min.js</code> (minified version).
Use <code>dist/extra.js</code> or <code>dist/extra.min.js</code> (minified version) to apply extra functions.</p>
<h2>Usage <a name="usage"></a> <a href="#start">↑</a></h2><h3>ECMAScript 6</h3><pre class="prettyprint source lang-js"><code>import listen from 'listate';
// Or if you need extra functionality
import extListen from 'listate/extra';</code></pre><h3>Node</h3><pre class="prettyprint source lang-js"><code>const listen = require('listate').listen;
// Or if you need extra functionality
const extListen = require('listate/extra').listen;</code></pre><h3>AMD</h3><pre class="prettyprint source lang-js"><code>define(['path/to/dist/listate.js', 'path/to/dist/extra.js'], function(listate, extra) {
const listen = listate.listen;
// Import extra.js if you need extra functionality
const extListen = extra.listen;
});</code></pre><h3>Bower, <script></h3><pre class="prettyprint source lang-html"><code><!-- Use bower_components/listate/dist/listate.js and bower_components/listate/dist/extra.js if the library was installed by Bower -->
<script type="text/javascript" src="path/to/dist/listate.js"></script>
<!-- Or if you need extra functionality -->
<script type="text/javascript" src="path/to/dist/extra.js"></script>
<script type="text/javascript">
// listate is available via listate field of window object
const listen = listate.listen;
// Extra functionality is available inside extra namespace
const extListen = listate.extra.listen;
</script></code></pre><h3>Examples <a name="examples"></a> <a href="#start">↑</a></h3><pre class="prettyprint source lang-js"><code>import { createStore } from 'redux';
import listen from 'listate';
import extListen from 'listate/extra';
const initState = {
user: null,
section: '',
map: {
main: {}
}
};
function reducer(state, action) {
const { payload } = action;
let newState;
switch (action.type) {
case 'AUTH':
return Object.assign({}, state, {user: payload});
case 'SELECT_SECTION':
return Object.assign({}, state, {section: payload});
case 'SET_SECTION':
newState = Object.assign({}, state);
newState.map = Object.assign({}, state.map);
newState.map[payload.key] = payload.value;
return newState;
default:
return state;
}
}
const store = createStore(reducer, initState);
listen(store, {
data: 'main',
filter: (state) => state.user,
// One-time listener
once: true,
handle(data) {
// Dispatch any action
data.dispatch({
type: 'SELECT_SECTION',
// data.current === state.user, data.data === 'main'
payload: data.current.favoriteSection || localStorage.getItem('selectedSection') || data.data
});
}
});
listen(store, {
filter: (state) => state.section,
when: (current, prev) => current !== prev && current !== 'exit',
// Call the listener no more frequently than once per second
delay: 1000,
handle(data) {
// data.current === state.section
localStorage.setItem('selectedSection', data.current);
console.log('Saved section: ', data.current);
}
});
listen(store, {
description: 'map change listener',
context: true,
filter: (state) => state.map,
when: (current, prev, data) => current.stat && data.state.user && data.state.section === 'video',
handle(data) {
console.log('data.prev:', data.prev); // {main: {}}
console.log('data.current:', data.current); // {main: {}, stat: {a: 1}}
console.log('this.description:', this.description); // map change listener
}
});
extListen(store, {
filter: {s: 'section', main: 'map.main'},
handle(data) {
console.log('extListen: data.prev -', data.prev);
console.log('extListen: data.current -', data.current);
}
});
...
store.dispatch({
type: 'AUTH',
payload: {login: 'commander'}
});
...
store.dispatch({
type: 'SELECT_SECTION',
payload: 'video'
});
...
store.dispatch({
type: 'SET_SECTION',
payload: {
key: 'stat',
value: {
a: 1
}
}
});
...
store.dispatch({
type: 'SELECT_SECTION',
payload: 'news'
});
...
store.dispatch({
type: 'SET_SECTION',
payload: {
key: 'main',
value: {
content: 'text'
}
}
});</code></pre><h2>API <a name="api"></a> <a href="#start">↑</a></h2><h3>Base functionality (listate, dist/listate.js)</h3><h4>baseWhen(state, prevState): boolean</h4><p>Checks whether current value (state) is not equal previous value (state).</p>
<p>Returns value of the following comparison: <code>state !== prevState</code>.</p>
<h4>listen(store, listener): Function</h4><p>Adds/registers state change listener for the given store.</p>
<p>Arguments:</p>
<ul>
<li><p><code>store: object</code> - Store for which listener should be added/registered.</p>
</li>
<li><p><code>listener: Function | object</code> - Specifies listener that should be called on a state change.
Can be a function or an object that defines listener settings/details.</p>
</li>
<li><p><code>listener.handle: Function</code> - Listener that should be called on a state change.</p>
</li>
<li><p><code>listener.context: boolean | object</code> (optional) - Specifies object that should be used as <code>this</code> value when calling the listener.</p>
</li>
<li><p><code>listener.data: any</code> (optional) - Any data that should be passed into the listener.</p>
</li>
<li><p><code>listener.delay: number</code> (optional) - Specifies that listener should be called after the given number of milliseconds
have elapsed. Works similar to <code>debounce</code>: when several requests for the listener call arrive during the specified period
only the last one will be applied after the timeout. <code>0</code> means that the listener should be called asynchronuosly.</p>
</li>
<li><p><code>listener.filter: (state) => state.part</code> (optional) - Function (selector) to extract state part
which will be used inside <code>when</code> to determine whether the listener should be called.
By default the entire state will be used.</p>
</li>
<li><p><code>listener.once: boolean</code> (optional) - Whether the listener should be called just once (by default <code>false</code>).</p>
</li>
<li><p><code>listener.when: (current, prev, data) => boolean</code> (optional) - Function to determine
whether the listener should be called. By default <code>baseWhen</code> is used.
The listener will be called if the function returns true.
The following parameters will be passed into the function:</p>
<ul>
<li>The current state or a part of the current state if <code>filter</code> is set.</li>
<li>The previous state or a part of the previous state if <code>filter</code> is set.</li>
<li>An object that will be passed into listener.</li>
</ul>
</li>
</ul>
<p>Returns a function that removes/unsubscribes the listener.</p>
<p>An object with the following fileds will be passed as parameter into the listener:</p>
<ul>
<li><code>current: any</code> - The current state or a part of the current state if <code>filter</code> is set.</li>
<li><code>prev: any</code> - The previous state or a part of the previous state if <code>filter</code> is set.</li>
<li><code>state: object</code> - The current state.</li>
<li><code>prevState: object</code> - The previous state.</li>
<li><code>data: any</code> - The auxiliary data (value of <code>listener.data</code> parameter).</li>
<li><code>store: object</code> - The store for which listener is registered.</li>
<li><code>dispatch: Function</code> - Reference to <code>dispatch</code> method of the store.</li>
<li><code>unlisten: Function</code> - The function that removes/unsubscribes the listener.</li>
</ul>
<h3>Extra functionality (listate/extra, dist/extra.js)</h3><h4>getPathValue(obj, path): any</h4><p>Return value of specified field path inside given object.</p>
<pre class="prettyprint source lang-js"><code>import { getPathValue } from 'listate/extra';
const obj = {
a: {
b: {
c: 'value'
},
d: true
},
e: 4,
f: [1, 'z', null]
};
getPathValue(obj, 'a.b.c'); // 'value'
getPathValue(obj, 'a.c'); // undefined</code></pre><h4>getObjectPart(source, parts): object</h4><p>Create an object containing specified parts of the given object.</p>
<pre class="prettyprint source lang-js"><code>import { getObjectPart } from 'listate/extra';
const obj = {
a: {
b: {
c: 'value',
d: true
},
e: 4,
f: [1, 'z', null]
},
g: 7,
h: {
i: false,
j: 0
},
k: 'king',
l: 'last'
};
getObjectPart(obj, {f1: 'a.b.d', f2: 'a.f.1', f3: 'g', f4: 'h.j'}); // {f1: true, f2: 'z', f3: 7, f4: 0}</code></pre><h4>getFieldFilter(path): Function</h4><p>Return a function that extracts value of the specified field path inside a given object.</p>
<pre class="prettyprint source lang-js"><code>import { getFieldFilter } from 'listate/extra';
const filter = getFieldFilter('a.d');
const obj = {
a: {
b: {
c: 'value'
},
d: 17
},
e: 4,
f: [1, 'z', null]
};
filter(obj); // 17</code></pre><h4>getPartFilter(parts): Function</h4><p>Return a function that creates an object containing the specified parts of a given object.</p>
<pre class="prettyprint source lang-js"><code>import { getPartFilter } from 'listate/extra';
const filter = getPartFilter({f1: 'a.b.c', f2: 'h.j', f3: 'k'});
const obj = {
a: {
b: {
c: 'value',
d: true
},
e: 4,
f: [1, 'z', null]
},
g: 7,
h: {
i: false,
j: 0
},
k: 'king',
l: 'last'
};
filter(obj); // {f1: 'value', f2: 0, f3: 'king'}</code></pre><h4>unlike(state, prevState, deep): boolean</h4><p>Check whether current object (state) is not equal previous object (state) comparing values of their fields.</p>
<pre class="prettyprint source lang-js"><code>import { unlike } from 'listate/extra';
unlike({a: 1, b: 2}, {a: 1, b: 2}); // false
unlike({a: 1, b: {c: 3}}, {a: 1, b: {c: 3}}); // true
unlike({a: 1, b: {c: 3}}, {a: 1, b: {c: 3}}, true); // false</code></pre><h4>unlikeDeep(state, prevState): boolean</h4><p>Check whether current object (state) is not equal previous object (state) deeply comparing values of their fields.</p>
<p>The same as <code>unlike(state, prevState, true)</code>.</p>
<h4>listen(store, listener): Function</h4><p>Add/register state change listener for the given store.</p>
<p>It is a wrap around base <code>listate.listen</code> that supports the following enhanced listener settings:</p>
<ul>
<li><code>listener.filter</code>.
When an array or an object is passed, the used filter will be result of <code>getPartFilter(listener.filter)</code>.
When a string is passed, the used filter will be result of <code>getFieldFilter(listener.filter)</code>.</li>
<li><code>listener.when</code>. By default <code>unlike</code> is used.</li>
</ul>
<p>See <code>doc</code> folder for details.</p>
<h2>Contributing <a name="contributing"></a> <a href="#start">↑</a></h2><p>In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality.
Lint and test your code.</p>
<h2>License <a name="license"></a> <a href="#start">↑</a></h2><p>Copyright (c) 2017-2019 Denis Sikuler<br>Licensed under the MIT license.</p></article>
</section>
</div>
</div>
<div class="clearfix"></div>
<div class="col-md-3">
<div id="toc" class="col-md-3 hidden-xs hidden-sm hidden-md"></div>
</div>
</div>
</div>
<div class="modal fade" id="searchResults">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Search results</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<footer>
<span class="copyright">
Copyright (c) 2017-2019 Denis Sikuler
</span>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a>
on 2019-06-22T20:49:22+03:00
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>
<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
<script>
$( function () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
var $this = $( this );
var example = $this.find( "code" );
exampleText = example.html();
var lang = /{@lang (.*?)}/.exec( exampleText );
if ( lang && lang[1] ) {
exampleText = exampleText.replace( lang[0], "" );
example.html( exampleText );
lang = lang[1];
} else {
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
lang = langClassMatch ? langClassMatch[1] : "javascript";
}
if ( lang ) {
$this
.addClass( "sunlight-highlight-" + lang )
.addClass( "linenums" )
.html( example.html() );
}
} );
Sunlight.highlightAll( {
lineNumbers : true,
showMenu : true,
enableDoclinks : true
} );
$.catchAnchorLinks( {
navbarOffset: 10
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
showAndHide : false,
smoothScrolling: true
} );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
$( "table" ).each( function () {
var $this = $( this );
$this.addClass('table');
} );
} );
</script>
<!--Navigation and Symbol Display-->
<!--Google Analytics-->
<script type="text/javascript">
$(document).ready(function() {
SearcherDisplay.init();
});
</script>
</body>
</html>