Skip to content

Commit

Permalink
Merge beb4b55 into 9c18edb
Browse files Browse the repository at this point in the history
  • Loading branch information
nmay231 committed Jan 7, 2020
2 parents 9c18edb + beb4b55 commit 9377ef6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 59 deletions.
28 changes: 17 additions & 11 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
<!-- Source: https://github.com/stevemao/github-issue-templates/tree/master/conversational -->

**Note: for support questions, please ask questions on the gitter chat**. This repository's issues are reserved for feature requests and bug reports. Visit the gitter chat [here](https://gitter.im/omnidan/redux-undo).
**Note: for support questions about the usage of the library, please ask questions on the gitter chat**. The issue tracker is reserved for feature requests, bug reports and similar issues. Visit the gitter chat [here](https://gitter.im/omnidan/redux-undo).

* **I'm submitting a ...**
- [ ] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
#### I'm submitting a ...
- [ ] Bug report
- [ ] Feature request
- [ ] Docs update
- [ ] Support request => Please do not submit support requests here, see note at the top of this template.

* **What is the current behavior?**

<!-- If this is a doc change, uncomment the following line, describe what needs to change, and then remove the other sections -->
<!-- #### What docs need to be added/updated? -->


* **What is the expected/desired behavior?**
#### What is the current behavior/state of the project?



* **If this is a feature request, what is the use case for changing the behavior?**
#### What is the desired behavior?



* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via a gist or similar.**
#### If this is a feature request, what is the use case for changing the behavior?



* **Please tell us about your environment:**
#### If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via a gist or similar.



#### Please tell us about your environment:

- Library version: 1.0.0
- Redux version: 4.0.0
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Edge XX]
- Language: [all | TypeScript X.X | ES6/7 | ES5]


* **Other information**
#### Other information

(e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Expand Down
26 changes: 14 additions & 12 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<!-- Source: https://github.com/stevemao/github-issue-templates/tree/master/conversational -->

* **Please check if the PR fulfills these requirements**
- [ ] The commit message(s) are descriptive of the changes made
- [ ] The PR contains changes that are focused and differs from other PRs
- For bug fixes or features:
- [ ] Tests for the changes have been added where needed
- [ ] Docs have been added / updated
#### Please check if the PR fulfills these requirements
- Is this just a doc change? (yes/no)

- If no, then check that:
- [ ] The commit message(s) are descriptive of the changes made
- [ ] The PR contains changes that are focused and differs from other PRs
- [ ] Tests for the changes have been added where needed
- [ ] Docs have been added / updated

* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)

#### What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

<!-- If this is a simple doc change, remove the following lines -->

<!-- If this is a simple doc change, describe the changes and then remove the following sections -->

* **What is the current behavior?** (You can also link to an open issue here)

#### What is the current behavior? (You can also link to an open issue here)


* **What is the new behavior (if this is a feature change)?**

#### What is the new behavior?


* **Does this PR introduce a breaking change?** (What changes might users need to make in their application due to this PR?)

#### Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)


* **Other information**:

#### Other information:


74 changes: 38 additions & 36 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ function createHistory (state, ignoreInitialState) {
return history
}

// lengthWithoutFuture: get length of history
function lengthWithoutFuture (history) {
return history.past.length + 1
}

// insert: insert `state` into history, which means adding the current state
// into `past`, setting the new `state` as `present` and erasing
// the `future`.
function insert (history, state, limit, group) {
const lengthWithoutFuture = history.past.length + 1

debug.log('inserting', state)
debug.log('new free: ', limit - lengthWithoutFuture(history))
debug.log('new free: ', limit - lengthWithoutFuture)

const { past, _latestUnfiltered } = history
const historyOverflow = limit && lengthWithoutFuture(history) >= limit
const isHistoryOverflow = limit && limit <= lengthWithoutFuture

const pastSliced = past.slice(historyOverflow ? 1 : 0)
const pastSliced = past.slice(isHistoryOverflow ? 1 : 0)
const newPast = _latestUnfiltered != null
? [
...pastSliced,
Expand Down Expand Up @@ -82,25 +79,36 @@ export default function undoable (reducer, rawConfig = {}) {
debug.set(rawConfig.debug)

const config = {
limit: undefined,
filter: () => true,
groupBy: () => null,
undoType: ActionTypes.UNDO,
redoType: ActionTypes.REDO,
jumpToPastType: ActionTypes.JUMP_TO_PAST,
jumpToFutureType: ActionTypes.JUMP_TO_FUTURE,
jumpType: ActionTypes.JUMP,
neverSkipReducer: false,
ignoreInitialState: false,
syncFilter: false,

...rawConfig,

initTypes: parseActions(rawConfig.initTypes, ['@@redux-undo/INIT']),
limit: rawConfig.limit,
filter: rawConfig.filter || (() => true),
groupBy: rawConfig.groupBy || (() => null),
undoType: rawConfig.undoType || ActionTypes.UNDO,
redoType: rawConfig.redoType || ActionTypes.REDO,
jumpToPastType: rawConfig.jumpToPastType || ActionTypes.JUMP_TO_PAST,
jumpToFutureType: rawConfig.jumpToFutureType || ActionTypes.JUMP_TO_FUTURE,
jumpType: rawConfig.jumpType || ActionTypes.JUMP,
clearHistoryType:
Array.isArray(rawConfig.clearHistoryType)
? rawConfig.clearHistoryType
: [rawConfig.clearHistoryType || ActionTypes.CLEAR_HISTORY],
neverSkipReducer: rawConfig.neverSkipReducer || false,
ignoreInitialState: rawConfig.ignoreInitialState || false,
syncFilter: rawConfig.syncFilter || false
clearHistoryType: parseActions(
rawConfig.clearHistoryType,
[ActionTypes.CLEAR_HISTORY]
)
}

let initialState = config.history
// Allows the user to call the reducer with redux-undo specific actions
const skipReducer = config.neverSkipReducer
? (res, action, ...slices) => ({
...res,
present: reducer(res.present, action, ...slices)
})
: (res) => res

let initialState
return (state = initialState, action = {}, ...slices) => {
debug.start(action, state)

Expand Down Expand Up @@ -143,12 +151,6 @@ export default function undoable (reducer, rawConfig = {}) {
}
}

const skipReducer = (res) => config.neverSkipReducer
? {
...res,
present: reducer(res.present, action, ...slices)
} : res

let res
switch (action.type) {
case undefined:
Expand All @@ -158,37 +160,37 @@ export default function undoable (reducer, rawConfig = {}) {
res = jump(history, -1)
debug.log('perform undo')
debug.end(res)
return skipReducer(res)
return skipReducer(res, action, ...slices)

case config.redoType:
res = jump(history, 1)
debug.log('perform redo')
debug.end(res)
return skipReducer(res)
return skipReducer(res, action, ...slices)

case config.jumpToPastType:
res = jumpToPast(history, action.index)
debug.log(`perform jumpToPast to ${action.index}`)
debug.end(res)
return skipReducer(res)
return skipReducer(res, action, ...slices)

case config.jumpToFutureType:
res = jumpToFuture(history, action.index)
debug.log(`perform jumpToFuture to ${action.index}`)
debug.end(res)
return skipReducer(res)
return skipReducer(res, action, ...slices)

case config.jumpType:
res = jump(history, action.index)
debug.log(`perform jump to ${action.index}`)
debug.end(res)
return skipReducer(res)
return skipReducer(res, action, ...slices)

case actionTypeAmongClearHistoryType(action.type, config.clearHistoryType):
res = createHistory(history.present, config.ignoreInitialState)
debug.log('perform clearHistory')
debug.end(res)
return skipReducer(res)
return skipReducer(res, action, ...slices)

default:
res = reducer(
Expand Down

0 comments on commit 9377ef6

Please sign in to comment.