You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The basic idea is that once `batch.start()`, all the subsequent actions will return the same group value until meet `batch.end()`. Then `redux-undo` will automatically save them in one group, without inserting a new state in the `past` array.
27
29
28
-
```js
30
+
```javascript
29
31
// batchGroupBy.js
30
32
31
33
import { groupByActionTypes } from'redux-undo'
@@ -44,10 +46,12 @@ export const batchGroupBy = {
44
46
}
45
47
};
46
48
```
49
+
47
50
Note that we create a unique id whenever we call `batch.start()`. In such case, if two batches are called back-to-back, they have different group values so that they will be stored in two states, rather than one state.
An array of action types can be passed into `init()`, which keeps the ability of grouping by action types if they are not within the scope of `start()` and `end()`.
64
+
65
+
An array of action types can be passed into `init()`, which keeps the ability of grouping by action types if they are not within the scope of `start()` and `end()`.
Copy file name to clipboardExpand all lines: docs/main/faq.md
+24-23Lines changed: 24 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,20 +2,20 @@
2
2
3
3
### Table of Contents
4
4
5
-
-[Where can I get help using `redux-undo`?](#where-can-I-get-help-using-redux-undo)
6
-
-[Where can I find examples of how to use `redux-undo`?](#where-can-i-find-examples-of-how-to-use-redux-undo)
7
-
-[How do I prevent cluttering up history with rapidly changing state?](#how-do-I-prevent-cluttering-up-history-with-rapidly-changing-state)
8
-
-[Can I have multiple, separate undoable functions?](#can-i-have-multiple-separate-undoable-functions)
9
-
-[Why are my actions not being filtered?](#why-are-my-actions-not-being-filtered)
10
-
-[What is `_latestUnfiltered`? Can I remove it?](#what-is-_latestUnfiltered-can-i-remove-it)
11
-
-[Why am I getting `Cannot find module 'redux-undo'`?](#why-am-i-getting-cannot-find-module-redux-undo)
12
-
-[How do I set an initial state/history?](upgrading-to-1.0.md#initialstate)
13
-
-[How do I upgrade from 0.X to 1.0?](upgrading-to-1.0.md)
14
-
-[How can I Undo or Redo a batch of actions at the same time ?](examples/undo-redo-batch-actions.md)
5
+
*[Where can I get help using `redux-undo`?](faq.md#where-can-I-get-help-using-redux-undo)
6
+
*[Where can I find examples of how to use `redux-undo`?](faq.md#where-can-i-find-examples-of-how-to-use-redux-undo)
7
+
*[How do I prevent cluttering up history with rapidly changing state?](faq.md#how-do-I-prevent-cluttering-up-history-with-rapidly-changing-state)
8
+
*[Can I have multiple, separate undoable functions?](faq.md#can-i-have-multiple-separate-undoable-functions)
9
+
*[Why are my actions not being filtered?](faq.md#why-are-my-actions-not-being-filtered)
10
+
*[What is `_latestUnfiltered`? Can I remove it?](faq.md#what-is-_latestUnfiltered-can-i-remove-it)
11
+
*[Why am I getting `Cannot find module 'redux-undo'`?](faq.md#why-am-i-getting-cannot-find-module-redux-undo)
12
+
*[How do I set an initial state/history?](upgrading-to-1.0.md#initialstate)
13
+
*[How do I upgrade from 0.X to 1.0?](upgrading-to-1.0.md)
14
+
*[How can I Undo or Redo a batch of actions at the same time ?](examples/undo-redo-batch-actions.md)
15
15
16
16
## Where can I get help using `redux-undo`?
17
17
18
-
To get an understanding of the basics, read through the [README](/README.md) and checkout some [examples](#where-can-i-find-examples-of-how-to-use-redux-undo).
18
+
To get an understanding of the basics, read through the [README](https://github.com/omnidan/redux-undo/tree/9a05150d6bcd3f71e56c3d9cb5e8669ac3d5c1dd/README.md) and checkout some [examples](faq.md#where-can-i-find-examples-of-how-to-use-redux-undo).
19
19
20
20
To get help with a specific use case, see if there is already an example in these docs or the examples. If not, ask for help in the [gitter chat](https://gitter.im/omnidan/redux-undo)!
21
21
@@ -25,18 +25,18 @@ If it seems you have found a bug or you are itching for a new feature, go ahead
25
25
26
26
Look at the `examples/` directory of the project folder. The `todos-with-undo/` is a good project to start messing with.
Just open http://localhost:3000 and you are good to go!
35
+
Just open [http://localhost:3000](http://localhost:3000) and you are good to go!
36
36
37
37
## How do I prevent cluttering up history with rapidly changing state?
38
38
39
-
The `throttled-drag/` project found the `examples/` directory gives a good demonstration of how to debounce undos (the filter is in `util/undoFilter.js`).
39
+
The `throttled-drag/` project found the `examples/` directory gives a good demonstration of how to debounce undos \(the filter is in `util/undoFilter.js`\).
40
40
41
41
This general question has different solutions depending on your exact problem. Let's say you have one or more rapidly dispatched actions, for example `MOVE_CURSOR` and `UPDATE_OBJECT_POS`, that ends with a lone action `PLACE_OBJECT`, and you only want to record the end state after `PLACE_OBJECT`. Then you can simply use a filter `excludeAction(['MOVE_CURSOR', 'UPDATE_OBJECT_POS'])`
42
42
@@ -46,7 +46,7 @@ For more complex requirements, consider writing your own [custom filter](https:/
46
46
47
47
Yes you can! Simply wrap each reducer with its own `undoable()`.
@@ -108,9 +108,9 @@ function onlyEveryThird(action, newState, history) {
108
108
109
109
### What is it?
110
110
111
-
State wrapped by `undoable()` contains the field `_latestUnfiltered` alongside `past`, `present`, etc. This field is used to keep track of state that should be put in the history but cannot yet because the previous action(s) were filtered. It is basically a temporary variable between filtered actions.
111
+
State wrapped by `undoable()` contains the field `_latestUnfiltered` alongside `past`, `present`, etc. This field is used to keep track of state that should be put in the history but cannot yet because the previous action\(s\) were filtered. It is basically a temporary variable between filtered actions.
112
112
113
-
```js
113
+
```javascript
114
114
// This action is filtered, so present cannot be pushed into past right away
115
115
_latestUnfiltered = present;
116
116
present = newState;
@@ -129,7 +129,7 @@ While there is a tad more overhead handling actions in the reducer, it is necess
129
129
130
130
If you are using redux-undo in a CommonJS or UMD environment, you need to add `.default` to your imports.
131
131
132
-
```js
132
+
```javascript
133
133
// CJS
134
134
var undoable =require("redux-undo").default;
135
135
@@ -139,8 +139,9 @@ var undoable = window.ReduxUndo.default;
139
139
140
140
ES6 imports should work without a hitch.
141
141
142
-
```js
142
+
```javascript
143
143
importundoablefrom"redux-undo";
144
144
```
145
145
146
146
If this fixed your issue, you might also want to checkout how to [upgrade from 0.6 to 1.0](upgrading-to-1.0.md).
Copy file name to clipboardExpand all lines: docs/main/upgrading-to-1.0.md
+11-10Lines changed: 11 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# Upgrading redux-undo from 0.x to 1.0
1
+
# Upgrading to 1.0
2
2
3
3
## Imports
4
4
5
5
CommonJS and UMD bundles now need a `.default` added to your imports.
6
6
7
-
```js
7
+
```javascript
8
8
// CJS
9
9
var undoable =require("redux-undo").default;
10
10
@@ -14,19 +14,19 @@ var undoable = window.ReduxUndo.default;
14
14
15
15
ES6 imports should work as expected.
16
16
17
-
```js
17
+
```javascript
18
18
importundoablefrom"redux-undo";
19
19
```
20
20
21
21
## `distinctState()` filter applied by default
22
22
23
-
In 1.0 and greater, state is only added to history if it is different than the previous state (checked by object reference equality `===`). The `distinctState()` filter is now deprecated and removed as there is no need for it.
23
+
In 1.0 and greater, state is only added to history if it is different than the previous state \(checked by object reference equality `===`\). The `distinctState()` filter is now deprecated and removed as there is no need for it.
24
24
25
25
## History API change in versions `< 0.4`
26
26
27
27
In versions 0.3 and earlier, the history state was stored in the form.
28
28
29
-
```js
29
+
```javascript
30
30
{
31
31
currentState: {...currentStateHere...},
32
32
history: {
@@ -39,7 +39,7 @@ In versions 0.3 and earlier, the history state was stored in the form.
39
39
40
40
In versions `0.4` and greater, the full history is exposed directly.
41
41
42
-
```js
42
+
```javascript
43
43
{
44
44
past: [...pastStatesHere...],
45
45
present: {...currentStateHere...},
@@ -51,7 +51,7 @@ In versions `0.4` and greater, the full history is exposed directly.
51
51
52
52
Before `1.0`, you would pass an `initialState` or `initialHistory` as a config option.
53
53
54
-
```js
54
+
```javascript
55
55
undoable(myReducer, {
56
56
initialState: {
57
57
myState:"initial",
@@ -63,7 +63,7 @@ undoable(myReducer, {
63
63
64
64
Now, these options are removed in favor of Redux's `preloadedState` parameter.
65
65
66
-
```js
66
+
```javascript
67
67
constrootReducer=combineReducers({
68
68
myReducer:undoable(myReducer)
69
69
});
@@ -76,11 +76,11 @@ const store = createStore(rootReducer, {
76
76
});
77
77
```
78
78
79
-
When providing initial state, redux-undo will automatically detect whether or not it is a complete history (with `past`, `present`, `future`) or not. If it is not, it will automatically convert it to one.
79
+
When providing initial state, redux-undo will automatically detect whether or not it is a complete history \(with `past`, `present`, `future`\) or not. If it is not, it will automatically convert it to one.
80
80
81
81
If you wish to provide an initial history, e.g. you want to prefill `past` to recover a previous session, you **must** provide the three fields for redux-undo to recognize it as a history object.
82
82
83
-
```js
83
+
```javascript
84
84
conststore=createStore(rootReducer, {
85
85
myReducer: {
86
86
past: ["from", "previous", "session"],
@@ -92,3 +92,4 @@ const store = createStore(rootReducer, {
Copy file name to clipboardExpand all lines: docs/readme.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Introduction
1
+
# About
2
2
3
3
[](https://www.npmjs.com/package/redux-undo)[](https://www.npmjs.com/package/redux-undo)[](https://coveralls.io/r/omnidan/redux-undo)[](https://david-dm.org/omnidan/redux-undo)[](http://standardjs.com/)[](https://raw.githubusercontent.com/omnidan/redux-undo/master/LICENSE.md)
4
4
@@ -8,7 +8,7 @@ _simple undo/redo functionality for redux state containers_
8
8
9
9
**Protip:** Check out the [todos-with-undo example](https://github.com/omnidan/redux-undo/tree/master/examples/todos-with-undo) or the [redux-undo-boilerplate](https://github.com/omnidan/redux-undo-boilerplate) to quickly get started with `redux-undo`.
10
10
11
-
**Switching from 0.x to 1.0:** Make sure to update your programs to the [latest History API](./#history-api).
11
+
**Switching from 0.x to 1.0:** Make sure to update your programs to the [latest History API](readme.md#history-api).
12
12
13
13
**Help wanted:** We are looking for volunteers to maintain this project, if you are interested, feel free to contact me at [[email protected]](mailto:[email protected])
14
14
@@ -74,7 +74,7 @@ combineReducers({
74
74
})
75
75
```
76
76
77
-
A [configuration](./#configuration) can be passed like this:
77
+
A [configuration](readme.md#configuration) can be passed like this:
0 commit comments