Skip to content

Commit e9b7253

Browse files
nmay231gitbook-bot
authored andcommitted
GitBook: [master] 10 pages modified
1 parent 9a05150 commit e9b7253

File tree

7 files changed

+65
-54
lines changed

7 files changed

+65
-54
lines changed

docs/examples/readme.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/main/examples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Examples
2+
3+
* [Undoing/redoing actions in batches](undo-redo-batch-actions.md)
4+

docs/examples/undo-redo-batch-actions.md renamed to docs/main/examples/undo-redo-batch-actions.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
## Undo-redo batch actions with custom groupBy
1+
# Undoing/redoing batches of actions at a time
22

33
This is an example of how to use custom groupBy to undo-redo a batch of actions at the same time.
44

55
This method remains the ability to group by action types but also enables us to group a batch of actions.
6-
- [x] Group by action types by default
7-
- [x] Group batch actions on demand, with `start()` and `end()`
86

9-
For example, an `onClick` event handler may dispatch a batch of actions. My way is to surround the batch of actions with `start()` and `end()`.
10-
```js
7+
* [x] Group by action types by default
8+
* [x] Group batch actions on demand, with `start()` and `end()`
9+
10+
For example, an `onClick` event handler may dispatch a batch of actions. My way is to surround the batch of actions with `start()` and `end()`.
11+
12+
```javascript
1113
import { batchGroupBy } from './batchGroupBy'
1214

1315
const mapDispatchToProps = (dispatch, ownProps) => ({
@@ -17,15 +19,15 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
1719
dispatch(action1)
1820
dispatch(action2)
1921
dispatch(action3)
20-
22+
2123
batchGroupBy.end()
2224
}
2325
});
2426
```
2527

2628
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.
2729

28-
```js
30+
```javascript
2931
// batchGroupBy.js
3032

3133
import { groupByActionTypes } from 'redux-undo'
@@ -44,10 +46,12 @@ export const batchGroupBy = {
4446
}
4547
};
4648
```
49+
4750
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.
4851

4952
Then we can config the reducer like below:
50-
```js
53+
54+
```javascript
5155
import { batchGroupBy } from './batchGroupBy'
5256

5357
const rootReducer = combineReducers({
@@ -57,4 +61,6 @@ const rootReducer = combineReducers({
5761
}),
5862
});
5963
```
60-
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()`.
66+

docs/faq.md renamed to docs/main/faq.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
### Table of Contents
44

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)
1515

1616
## Where can I get help using `redux-undo`?
1717

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).
1919

2020
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)!
2121

@@ -25,18 +25,18 @@ If it seems you have found a bug or you are itching for a new feature, go ahead
2525

2626
Look at the `examples/` directory of the project folder. The `todos-with-undo/` is a good project to start messing with.
2727

28-
```sh
28+
```bash
2929
$ git clone https://github.com/omnidan/redux-undo.git
3030
$ cd redux-undo/examples/todos-with-undo
3131
$ npm install
3232
$ npm start
3333
```
3434

35-
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!
3636

3737
## How do I prevent cluttering up history with rapidly changing state?
3838

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`\).
4040

4141
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'])`
4242

@@ -46,7 +46,7 @@ For more complex requirements, consider writing your own [custom filter](https:/
4646

4747
Yes you can! Simply wrap each reducer with its own `undoable()`.
4848

49-
```js
49+
```javascript
5050
const rootReducer = combineReducers({
5151
someData: undoable(dataReducer),
5252
otherData: undoable(otherDataReducer)
@@ -55,7 +55,7 @@ const rootReducer = combineReducers({
5555

5656
Do not forget to setup different undo/redo types to undo/redo each slice separately.
5757

58-
```js
58+
```javascript
5959
someData: undoable(dataReducer, {
6060
undoType: "DATA_UNDO",
6161
redoType: "DATA_REDO"
@@ -65,7 +65,7 @@ someData: undoable(dataReducer, {
6565

6666
If you wish to have a single conglomerate history that a user can undo one action at a time, you can wrap the root reducer with `undoable()`.
6767

68-
```js
68+
```javascript
6969
const rootReducer = undoable(
7070
combineReducers({
7171
someData: dataReducer,
@@ -83,7 +83,7 @@ If you are trying to prevent actions from changing state, **that is not what `fi
8383

8484
On the other hand, here is how to use the helper functions:
8585

86-
```js
86+
```javascript
8787
undoable(myReducer, {
8888
filter: combineFilters(
8989
// includeAction/excludeAction helpers take an array of action type strings
@@ -95,7 +95,7 @@ undoable(myReducer, {
9595

9696
When writing a custom filter, return `true` for actions that you want to keep in history.
9797

98-
```js
98+
```javascript
9999
function onlyEveryThird(action, newState, history) {
100100
// Access the whole history object
101101
let { past, present, future, limit } = history;
@@ -108,9 +108,9 @@ function onlyEveryThird(action, newState, history) {
108108

109109
### What is it?
110110

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.
112112

113-
```js
113+
```javascript
114114
// This action is filtered, so present cannot be pushed into past right away
115115
_latestUnfiltered = present;
116116
present = newState;
@@ -129,7 +129,7 @@ While there is a tad more overhead handling actions in the reducer, it is necess
129129

130130
If you are using redux-undo in a CommonJS or UMD environment, you need to add `.default` to your imports.
131131

132-
```js
132+
```javascript
133133
// CJS
134134
var undoable = require("redux-undo").default;
135135

@@ -139,8 +139,9 @@ var undoable = window.ReduxUndo.default;
139139

140140
ES6 imports should work without a hitch.
141141

142-
```js
142+
```javascript
143143
import undoable from "redux-undo";
144144
```
145145

146146
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).
147+

docs/upgrading-to-1.0.md renamed to docs/main/upgrading-to-1.0.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Upgrading redux-undo from 0.x to 1.0
1+
# Upgrading to 1.0
22

33
## Imports
44

55
CommonJS and UMD bundles now need a `.default` added to your imports.
66

7-
```js
7+
```javascript
88
// CJS
99
var undoable = require("redux-undo").default;
1010

@@ -14,19 +14,19 @@ var undoable = window.ReduxUndo.default;
1414

1515
ES6 imports should work as expected.
1616

17-
```js
17+
```javascript
1818
import undoable from "redux-undo";
1919
```
2020

2121
## `distinctState()` filter applied by default
2222

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.
2424

2525
## History API change in versions `< 0.4`
2626

2727
In versions 0.3 and earlier, the history state was stored in the form.
2828

29-
```js
29+
```javascript
3030
{
3131
currentState: {...currentStateHere...},
3232
history: {
@@ -39,7 +39,7 @@ In versions 0.3 and earlier, the history state was stored in the form.
3939

4040
In versions `0.4` and greater, the full history is exposed directly.
4141

42-
```js
42+
```javascript
4343
{
4444
past: [...pastStatesHere...],
4545
present: {...currentStateHere...},
@@ -51,7 +51,7 @@ In versions `0.4` and greater, the full history is exposed directly.
5151

5252
Before `1.0`, you would pass an `initialState` or `initialHistory` as a config option.
5353

54-
```js
54+
```javascript
5555
undoable(myReducer, {
5656
initialState: {
5757
myState: "initial",
@@ -63,7 +63,7 @@ undoable(myReducer, {
6363

6464
Now, these options are removed in favor of Redux's `preloadedState` parameter.
6565

66-
```js
66+
```javascript
6767
const rootReducer = combineReducers({
6868
myReducer: undoable(myReducer)
6969
});
@@ -76,11 +76,11 @@ const store = createStore(rootReducer, {
7676
});
7777
```
7878

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.
8080

8181
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.
8282

83-
```js
83+
```javascript
8484
const store = createStore(rootReducer, {
8585
myReducer: {
8686
past: ["from", "previous", "session"],
@@ -92,3 +92,4 @@ const store = createStore(rootReducer, {
9292
}
9393
});
9494
```
95+

docs/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Introduction
1+
# About
22

33
[![NPM version \(&amp;gt;=0.4\)](https://img.shields.io/npm/v/redux-undo.svg?style=flat-square)](https://www.npmjs.com/package/redux-undo) [![NPM Downloads](https://img.shields.io/npm/dm/redux-undo.svg?style=flat-square)](https://www.npmjs.com/package/redux-undo) [![Coverage Status](https://img.shields.io/coveralls/omnidan/redux-undo.svg?style=flat-square)](https://coveralls.io/r/omnidan/redux-undo) [![Dependencies](https://img.shields.io/david/omnidan/redux-undo.svg?style=flat-square)](https://david-dm.org/omnidan/redux-undo) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/omnidan/redux-undo/master/LICENSE.md)
44

@@ -8,7 +8,7 @@ _simple undo/redo functionality for redux state containers_
88

99
**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`.
1010

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).
1212

1313
**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])
1414

@@ -74,7 +74,7 @@ combineReducers({
7474
})
7575
```
7676

77-
A [configuration](./#configuration) can be passed like this:
77+
A [configuration](readme.md#configuration) can be passed like this:
7878

7979
```javascript
8080
combineReducers({

docs/summary.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# Table of Contents
1+
# Table of contents
2+
3+
* [About](readme.md)
24

35
## Main
46

5-
- [About](./readme.md)
6-
- [FAQ](./faq.md)
7-
- [Examples](examples/readme.md)
8-
- [Undoing/redoing batches of actions at a time](examples/undo-redo-batch-actions.md)
9-
- [Upgrading to 1.0](./upgrading-to-1.0.md)
7+
* [FAQ](main/faq.md)
8+
* [Examples](main/examples/README.md)
9+
* [Undoing/redoing batches of actions at a time](main/examples/undo-redo-batch-actions.md)
10+
* [Upgrading to 1.0](main/upgrading-to-1.0.md)
11+

0 commit comments

Comments
 (0)