2017-01-18 02:41:53 +01:00
|
|
|
// per http://redux.js.org/docs/recipes/ComputingDerivedData.html
|
2016-11-23 22:58:48 +01:00
|
|
|
|
|
|
|
import { createSelector } from 'reselect'
|
|
|
|
|
2016-11-28 18:47:47 +01:00
|
|
|
import React from 'react'
|
|
|
|
|
2016-12-14 19:02:27 +01:00
|
|
|
import {Format, Show} from './constants'
|
2016-11-28 18:47:47 +01:00
|
|
|
|
2016-11-30 20:57:35 +01:00
|
|
|
import * as Dubdiff from './util/dubdiff'
|
|
|
|
|
2016-11-23 22:58:48 +01:00
|
|
|
const input = (state) => state.input
|
2016-11-28 18:47:47 +01:00
|
|
|
const format = (state) => state.format
|
2017-01-18 02:41:53 +01:00
|
|
|
const show = (state) => state.show
|
2016-11-23 22:58:48 +01:00
|
|
|
|
|
|
|
export const safeInput = createSelector(
|
|
|
|
[input],
|
|
|
|
(input) => {
|
2017-01-18 02:41:53 +01:00
|
|
|
//! !! sanitize the input here and return
|
2016-11-23 22:58:48 +01:00
|
|
|
return input
|
|
|
|
}
|
2016-11-28 18:47:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
export const isMarkdownFormat = createSelector(
|
|
|
|
[format],
|
|
|
|
(format) => {
|
2017-01-18 02:41:53 +01:00
|
|
|
return format === Format.MARKDOWN
|
2016-11-28 18:47:47 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const isShow = (type) => createSelector(
|
|
|
|
[show],
|
|
|
|
(show) => {
|
2017-01-18 02:41:53 +01:00
|
|
|
return show === type
|
2016-11-28 18:47:47 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const isShowOriginal = isShow(Show.ORIGINAL)
|
|
|
|
export const isShowFinal = isShow(Show.FINAL)
|
2017-01-18 02:41:53 +01:00
|
|
|
export const isShowDifference = isShow(Show.DIFFERENCE)
|
2016-11-28 18:47:47 +01:00
|
|
|
|
|
|
|
export const diff = createSelector(
|
2016-12-15 01:06:14 +01:00
|
|
|
[format, safeInput],
|
|
|
|
(format, safeInput) => {
|
2017-01-18 02:41:53 +01:00
|
|
|
if (format === Format.PLAINTEXT) {
|
2017-01-05 23:18:03 +01:00
|
|
|
return Dubdiff.plaintextDiff(safeInput.original, safeInput.final)
|
2017-01-18 02:41:53 +01:00
|
|
|
} else if (format === Format.MARKDOWN) {
|
2017-01-05 23:18:03 +01:00
|
|
|
return Dubdiff.markdownDiff(safeInput.original, safeInput.final)
|
2017-01-18 02:41:53 +01:00
|
|
|
}
|
2016-11-28 18:47:47 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
html diff
|
|
|
|
---
|
|
|
|
|
|
|
|
diffHtml(parentOriginal, parentFinal) {
|
2017-01-18 02:41:53 +01:00
|
|
|
create stringOriginal, stringFinal consisting of
|
2016-11-28 18:47:47 +01:00
|
|
|
}
|
2017-01-18 02:41:53 +01:00
|
|
|
*/
|