forked from pavol-brunclik-m2ms/fragalysis-frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/origin/#524' into allfunctionality
- Loading branch information
Showing
12 changed files
with
493 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export const ActionTypes = { | ||
UNDO: '@@redux-undo/UNDO', | ||
REDO: '@@redux-undo/REDO', | ||
JUMP_TO_FUTURE: '@@redux-undo/JUMP_TO_FUTURE', | ||
JUMP_TO_PAST: '@@redux-undo/JUMP_TO_PAST', | ||
JUMP: '@@redux-undo/JUMP', | ||
CLEAR_HISTORY: '@@redux-undo/CLEAR_HISTORY', | ||
REMOVE_LAST_PAST: '@@redux-undo/REMOVE_LAST_PAST' | ||
} | ||
|
||
export const ActionCreators = { | ||
undo () { | ||
return { type: ActionTypes.UNDO } | ||
}, | ||
redo () { | ||
return { type: ActionTypes.REDO } | ||
}, | ||
jumpToFuture (index) { | ||
return { type: ActionTypes.JUMP_TO_FUTURE, index } | ||
}, | ||
jumpToPast (index) { | ||
return { type: ActionTypes.JUMP_TO_PAST, index } | ||
}, | ||
jump (index) { | ||
return { type: ActionTypes.JUMP, index } | ||
}, | ||
clearHistory () { | ||
return { type: ActionTypes.CLEAR_HISTORY } | ||
}, | ||
removeLastPast() { | ||
return {type: ActionTypes.REMOVE_LAST_PAST} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
let __DEBUG__ | ||
let displayBuffer | ||
|
||
const colors = { | ||
prevState: '#9E9E9E', | ||
action: '#03A9F4', | ||
nextState: '#4CAF50' | ||
} | ||
|
||
/* istanbul ignore next: debug messaging is not tested */ | ||
function initBuffer () { | ||
displayBuffer = { | ||
header: [], | ||
prev: [], | ||
action: [], | ||
next: [], | ||
msgs: [] | ||
} | ||
} | ||
|
||
/* istanbul ignore next: debug messaging is not tested */ | ||
function printBuffer () { | ||
const { header, prev, next, action, msgs } = displayBuffer | ||
if (console.group) { | ||
console.groupCollapsed(...header) | ||
console.log(...prev) | ||
console.log(...action) | ||
console.log(...next) | ||
console.log(...msgs) | ||
console.groupEnd() | ||
} else { | ||
console.log(...header) | ||
console.log(...prev) | ||
console.log(...action) | ||
console.log(...next) | ||
console.log(...msgs) | ||
} | ||
} | ||
|
||
/* istanbul ignore next: debug messaging is not tested */ | ||
function colorFormat (text, color, obj) { | ||
return [ | ||
`%c${text}`, | ||
`color: ${color}; font-weight: bold`, | ||
obj | ||
] | ||
} | ||
|
||
/* istanbul ignore next: debug messaging is not tested */ | ||
function start (action, state) { | ||
initBuffer() | ||
if (__DEBUG__) { | ||
if (console.group) { | ||
displayBuffer.header = ['%credux-undo', 'font-style: italic', 'action', action.type] | ||
displayBuffer.action = colorFormat('action', colors.action, action) | ||
displayBuffer.prev = colorFormat('prev history', colors.prevState, state) | ||
} else { | ||
displayBuffer.header = ['redux-undo action', action.type] | ||
displayBuffer.action = ['action', action] | ||
displayBuffer.prev = ['prev history', state] | ||
} | ||
} | ||
} | ||
|
||
/* istanbul ignore next: debug messaging is not tested */ | ||
function end (nextState) { | ||
if (__DEBUG__) { | ||
if (console.group) { | ||
displayBuffer.next = colorFormat('next history', colors.nextState, nextState) | ||
} else { | ||
displayBuffer.next = ['next history', nextState] | ||
} | ||
printBuffer() | ||
} | ||
} | ||
|
||
/* istanbul ignore next: debug messaging is not tested */ | ||
function log (...args) { | ||
if (__DEBUG__) { | ||
displayBuffer.msgs = displayBuffer.msgs | ||
.concat([...args, '\n']) | ||
} | ||
} | ||
|
||
/* istanbul ignore next: debug messaging is not tested */ | ||
function set (debug) { | ||
__DEBUG__ = debug | ||
} | ||
|
||
export { set, start, end, log } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// parseActions helper: takes a string (or array) | ||
// and makes it an array if it isn't yet | ||
export function parseActions (rawActions, defaultValue = []) { | ||
if (Array.isArray(rawActions)) { | ||
return rawActions | ||
} else if (typeof rawActions === 'string') { | ||
return [rawActions] | ||
} | ||
return defaultValue | ||
} | ||
|
||
// isHistory helper: check for a valid history object | ||
export function isHistory (history) { | ||
return typeof history.present !== 'undefined' && | ||
typeof history.future !== 'undefined' && | ||
typeof history.past !== 'undefined' && | ||
Array.isArray(history.future) && | ||
Array.isArray(history.past) | ||
} | ||
|
||
// includeAction helper: whitelist actions to be added to the history | ||
export function includeAction (rawActions) { | ||
const actions = parseActions(rawActions) | ||
return (action) => actions.indexOf(action.type) >= 0 | ||
} | ||
|
||
// excludeAction helper: blacklist actions from being added to the history | ||
export function excludeAction (rawActions) { | ||
const actions = parseActions(rawActions) | ||
return (action) => actions.indexOf(action.type) < 0 | ||
} | ||
|
||
// combineFilters helper: combine multiple filters to one | ||
export function combineFilters (...filters) { | ||
return filters.reduce((prev, curr) => | ||
(action, currentState, previousHistory) => | ||
prev(action, currentState, previousHistory) && | ||
curr(action, currentState, previousHistory) | ||
, () => true) | ||
} | ||
|
||
export function groupByActionTypes (rawActions) { | ||
const actions = parseActions(rawActions) | ||
return (action) => actions.indexOf(action.type) >= 0 ? action.type : null | ||
} | ||
|
||
export function newHistory (past, present, future, group = null) { | ||
return { | ||
past, | ||
present, | ||
future, | ||
group, | ||
_latestUnfiltered: present, | ||
index: past.length, | ||
limit: past.length + future.length + 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export { ActionTypes, ActionCreators } from './actions' | ||
export { | ||
parseActions, isHistory, | ||
includeAction, excludeAction, | ||
combineFilters, groupByActionTypes, newHistory | ||
} from './helpers' | ||
|
||
export { default } from './reducer' |
Oops, something went wrong.