Rename state constant names

This commit is contained in:
josdejong 2020-06-02 14:13:33 +02:00
parent e5ec845d4f
commit 55ee6361d6
4 changed files with 30 additions and 30 deletions

View File

@ -2,8 +2,8 @@
import { tick } from 'svelte'
import {
DEFAULT_LIMIT,
EXPANDED_PROPERTY,
LIMIT_PROPERTY,
STATE_EXPANDED,
STATE_LIMIT,
SCROLL_DURATION
} from './constants.js'
import SearchBox from './SearchBox.svelte'
@ -26,7 +26,7 @@
}
const INITIAL_STATE = {
[EXPANDED_PROPERTY]: true
[STATE_EXPANDED]: true
}
let state = INITIAL_STATE
@ -196,7 +196,7 @@
* @param {boolean} expanded
*/
function handleExpand (path, expanded) {
state = setIn(state, path.concat(EXPANDED_PROPERTY), expanded)
state = setIn(state, path.concat(STATE_EXPANDED), expanded)
}
/**
@ -205,7 +205,7 @@
* @param {boolean} limit
*/
function handleLimit (path, limit) {
state = setIn(state, path.concat(LIMIT_PROPERTY), limit)
state = setIn(state, path.concat(STATE_LIMIT), limit)
}
/**
@ -215,15 +215,15 @@
function expandPath (path) {
for (let i = 1; i < path.length; i++) {
const partialPath = path.slice(0, i)
state = setIn(state, partialPath.concat(EXPANDED_PROPERTY), true)
state = setIn(state, partialPath.concat(STATE_EXPANDED), true)
// if needed, enlarge the limit such that the search result becomes visible
const key = path[i]
if (isNumber(key)) {
const limit = getIn(state, partialPath.concat(LIMIT_PROPERTY)) || DEFAULT_LIMIT
const limit = getIn(state, partialPath.concat(STATE_LIMIT)) || DEFAULT_LIMIT
if (key > limit) {
const newLimit = Math.ceil(key / DEFAULT_LIMIT) * DEFAULT_LIMIT
state = setIn(state, partialPath.concat(LIMIT_PROPERTY), newLimit)
state = setIn(state, partialPath.concat(STATE_LIMIT), newLimit)
}
}
}

View File

@ -1,9 +1,9 @@
<script>
import {
DEBOUNCE_DELAY, DEFAULT_LIMIT,
EXPANDED_PROPERTY, LIMIT_PROPERTY,
SEARCH_PROPERTY,
SEARCH_VALUE
STATE_EXPANDED, STATE_LIMIT,
STATE_SEARCH_PROPERTY,
STATE_SEARCH_VALUE
} from './constants.js'
import { getPlainText, setPlainText } from './utils/domUtils.js'
import Icon from 'svelte-awesome'
@ -25,8 +25,8 @@
export let onExpand
export let onLimit
$: expanded = state && state[EXPANDED_PROPERTY]
$: limit = state && state[LIMIT_PROPERTY] || DEFAULT_LIMIT
$: expanded = state && state[STATE_EXPANDED]
$: limit = state && state[STATE_LIMIT] || DEFAULT_LIMIT
const escapeUnicode = false // TODO: pass via options
@ -79,14 +79,14 @@
function getValueClass (value, searchResult) {
const type = valueType (value)
return classnames('value', type, searchResult && searchResult[SEARCH_VALUE], {
return classnames('value', type, searchResult && searchResult[STATE_SEARCH_VALUE], {
url: isUrl(value),
empty: typeof value === 'string' && value.length === 0,
})
}
function getKeyClass(key, searchResult) {
return classnames('key', searchResult && searchResult[SEARCH_PROPERTY], {
return classnames('key', searchResult && searchResult[STATE_SEARCH_PROPERTY], {
empty: key === ''
})
}
@ -224,7 +224,7 @@
{#if typeof key === 'string'}
<div
class={keyClass}
data-path={compileJSONPointer(path.concat(SEARCH_PROPERTY))}
data-path={compileJSONPointer(path.concat(STATE_SEARCH_PROPERTY))}
contenteditable="true"
spellcheck="false"
on:input={handleKeyInput}
@ -278,7 +278,7 @@
{#if typeof key === 'string'}
<div
class={keyClass}
data-path={compileJSONPointer(path.concat(SEARCH_PROPERTY))}
data-path={compileJSONPointer(path.concat(STATE_SEARCH_PROPERTY))}
contenteditable="true"
spellcheck="false"
on:input={handleKeyInput}
@ -320,7 +320,7 @@
{#if typeof key === 'string'}
<div
class={keyClass}
data-path={compileJSONPointer(path.concat(SEARCH_PROPERTY))}
data-path={compileJSONPointer(path.concat(STATE_SEARCH_PROPERTY))}
contenteditable="true"
spellcheck="false"
on:input={handleKeyInput}
@ -331,7 +331,7 @@
{/if}
<div
class={valueClass}
data-path={compileJSONPointer(path.concat(SEARCH_VALUE))}
data-path={compileJSONPointer(path.concat(STATE_SEARCH_VALUE))}
contenteditable="true"
spellcheck="false"
on:input={handleValueInput}

View File

@ -1,8 +1,8 @@
export const EXPANDED_PROPERTY = '$jse:expanded'
export const LIMIT_PROPERTY = '$jse:limit'
export const SEARCH_PROPERTY = '$jse:search:property'
export const SEARCH_VALUE = '$jse:search:value'
export const STATE_EXPANDED = '$jse:expanded'
export const STATE_LIMIT = '$jse:limit'
export const STATE_SEARCH_PROPERTY = '$jse:search:property'
export const STATE_SEARCH_VALUE = '$jse:search:value'
export const SCROLL_DURATION = 300 // ms
export const DEBOUNCE_DELAY = 300

View File

@ -1,12 +1,12 @@
import { isNumber } from 'lodash-es'
import { SEARCH_PROPERTY, SEARCH_VALUE } from '../constants.js'
import { STATE_SEARCH_PROPERTY, STATE_SEARCH_VALUE } from '../constants.js'
import { valueType } from './typeUtils.js'
export function search (key, value, searchText) {
let results = undefined
if (typeof key === 'string' && containsCaseInsensitive(key, searchText)) {
results = createOrAdd(results, SEARCH_PROPERTY, 'search')
results = createOrAdd(results, STATE_SEARCH_PROPERTY, 'search')
}
const type = valueType(value)
@ -26,7 +26,7 @@ export function search (key, value, searchText) {
})
} else { // type is a value
if (containsCaseInsensitive(value, searchText)) {
results = createOrAdd(results, SEARCH_VALUE, 'search')
results = createOrAdd(results, STATE_SEARCH_VALUE, 'search')
}
}
@ -38,15 +38,15 @@ export function flattenSearch (searchResult) {
function _flattenSearch (value, path) {
if (value) {
if (value[SEARCH_PROPERTY]) {
if (value[STATE_SEARCH_PROPERTY]) {
resultArray.push({
what: SEARCH_PROPERTY,
what: STATE_SEARCH_PROPERTY,
path
})
}
if (value[SEARCH_VALUE]) {
if (value[STATE_SEARCH_VALUE]) {
resultArray.push({
what: SEARCH_VALUE,
what: STATE_SEARCH_VALUE,
path
})
}