refactoring

This commit is contained in:
Hans Pagel 2020-10-28 11:52:10 +01:00
parent 0f9c705ee0
commit 228ef24424
2 changed files with 8 additions and 10 deletions

View File

@ -1,15 +1,13 @@
import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import getMarkAttrs from './getMarkAttrs'
import { AnyObject } from '../types'
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: { [key: string]: any }): boolean {
if (attrs === undefined || Object.keys(attrs).length === 0) {
return true
}
export default function markHasAttributes(state: EditorState, type: MarkType, attrs: AnyObject) {
const originalAttrs = getMarkAttrs(state, type)
const originalAttrs: { [key: string]: any } = getMarkAttrs(state, type)
return Object.keys(attrs).filter((key: string) => {
return attrs[key] === originalAttrs[key]
}).length > 0
return !!Object
.keys(attrs)
.filter(key => attrs[key] === originalAttrs[key])
.length
}

View File

@ -2,7 +2,7 @@ import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import markHasAttributes from './markHasAttributes'
export default function markIsActive(state: EditorState, type: MarkType, attrs?: {}) {
export default function markIsActive(state: EditorState, type: MarkType, attrs = {}) {
const {
from,
$from,