File size: 2,426 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Action Log

**A Redux [store enhancer](https://github.com/reactjs/redux/blob/HEAD/docs/Glossary.md#store-enhancer)**

The Action Log is a Redux store enhancer which records the most recently dispatched Redux action so
they can be inspected in the development environment for debugging and interactive design.

## Purpose

Like the [Redux DevTools](https://github.com/zalmoxisus/redux-devtools-extension), the action log
is useful to track and inspect actions flowing through the store.

## Methods

- `actionLog.start()`
  Enable action recording to history. It is enabled by default.

- `actionLog.stop()`
  Disable action recording to history.

- `actionLog.setSize( size )`
  Set the desired action history size. The history will be flushed periodically to prevent unbounded
  growth.

- `actionLog.history`
  Return the current history. The history is an array of action objects.

- `actionLog.filter( query )`
  Return a filtered history of actions matching the query. See [Query](#query).

- `actionLog.watch( query )`
  Watch flow of matching actions real-time in the console. Only the single, most recent watch will
  have effect. See [Query](#query).

- `actionLog.unwatch()`
  Disable action watching.

## Query

The `actionLog.filter( query )` and `actionLog.watch( query )` accept a `query`. The following types
are valid queries which are useful for different situations:

- `string`: `actionLog.filter( "COMMENTS_LIKE" )` - Match actions whose type exactly matches the
  string.

- `RexExp`: `actionLog.filter( /^comments_/i )` - Match actions whose type is matched by the RegExp.

- `PredicateFunction :: action -> bool`:
  `actionLog.filter( action => action.siteId === interestingSiteId)` - A predicate function that
  accepts an action and returns `true` if the action matches.

## Examples

The following examples represent commands and code actually run inside the browser console. These
are not snippets of bundled JavaScript from Calypso.

```js
// return the list of recorded actions
actionLog.history;

// return a subset of the recorded actions filtering on the `action.type`
actionLog.filter( 'COMMENTS_LIKE' );

// Watch actions in the console by string, RegExp or Predicate Function.
// The same types of query arguments may be used with `actionLog.filter`.
actionLog.watch( 'SITE_RECEIVE' );

actionLog.watch( /post/i );

actionLog.watch( ( action ) => action.siteId === myFavoriteSiteId );
```