feat: strart refactoring types

This commit is contained in:
cudr 2019-11-03 11:32:52 +03:00
parent a805d2476a
commit 0f98915909
7 changed files with 16 additions and 14 deletions

View File

@ -8,7 +8,7 @@ import annotation from './annotation'
const setSelection = doc => doc
const setValue = doc => doc
const opType: any = {
const opType = {
...text,
...annotation,
...node,

View File

@ -1,13 +1,13 @@
import * as Automerge from 'automerge'
import { toSlateOp } from './index'
import { createDoc, cloneDoc, createBlockJSON, toJS } from '../utils'
import { createDoc, cloneDoc, createBlockJSON } from '../utils'
describe('convert operations to slatejs model', () => {
it('convert insert operations', () => {
const doc1 = createDoc()
const doc2 = cloneDoc(doc1)
const change = Automerge.change(doc1, 'change', (d: any) => {
const change = Automerge.change(doc1, 'change', d => {
d.document.nodes.push(createBlockJSON('paragraph', 'hello!'))
d.document.nodes[1].nodes[0].text = 'hello!'
})
@ -33,7 +33,7 @@ describe('convert operations to slatejs model', () => {
})
it('convert remove operations', () => {
const doc1 = Automerge.change(createDoc(), 'change', (d: any) => {
const doc1 = Automerge.change(createDoc(), 'change', d => {
d.document.nodes.push(createBlockJSON('paragraph', 'hello!'))
d.document.nodes.push(createBlockJSON('paragraph', 'hello twice!'))
d.document.nodes[1].nodes[0].text = 'hello!'
@ -41,7 +41,7 @@ describe('convert operations to slatejs model', () => {
const doc2 = cloneDoc(doc1)
const change = Automerge.change(doc1, 'change', (d: any) => {
const change = Automerge.change(doc1, 'change', d => {
delete d.document.nodes[1]
delete d.document.nodes[0].nodes[0]
})

View File

@ -12,7 +12,7 @@ const insertTextOp = ({ index, path, value }: Automerge.Diff) => () => ({
const insertNodeOp = ({ value, obj, index, path }: Automerge.Diff) => map => {
const ops = []
const inserate = ({ nodes, ...json }: any, path) => {
const iterate = ({ nodes, ...json }, path) => {
const node = nodes ? { ...json, nodes: [] } : json
if (node.object) {
@ -31,12 +31,12 @@ const insertNodeOp = ({ value, obj, index, path }: Automerge.Diff) => map => {
}
}
nodes && nodes.forEach((n, i) => inserate(n, [...path, i]))
nodes && nodes.forEach((n, i) => iterate(n, [...path, i]))
}
const source = map[value] || (map[obj] && toJS(map[obj]))
source && inserate(source, [...toSlatePath(path), index])
source && iterate(source, [...toSlatePath(path), index])
return ops
}

View File

@ -51,7 +51,7 @@ export const removeCursor = (doc: SyncDoc, key: CursorKey) => {
return doc
}
export const cursorOpFilter = (ops: any, type: string): any =>
export const cursorOpFilter = (ops, type: string) =>
ops.filter(op => {
if (op.type === 'set_annotation') {
return !(

View File

@ -1,3 +1,5 @@
import { ValueJSON } from 'slate'
export type CursorKey = string
export type SyncDoc = any
export interface SyncDoc extends ValueJSON {}

View File

@ -1,5 +1,5 @@
import * as Automerge from 'automerge'
import { ValueJSON, TextJSON, NodeJSON } from 'slate'
import { TextJSON } from 'slate'
export const createTextJSON = (text: string = ''): TextJSON => ({
object: 'text',
@ -10,13 +10,13 @@ export const createTextJSON = (text: string = ''): TextJSON => ({
export const createBlockJSON = (
type: string = 'paragraph',
text: string = ''
): NodeJSON => ({
) => ({
object: 'block',
type,
nodes: [createTextJSON(text)]
})
export const createValueJSON = (): ValueJSON => ({
export const createValueJSON = () => ({
document: {
nodes: [createBlockJSON()]
}

View File

@ -1,6 +1,6 @@
import * as Automerge from 'automerge'
const toSync = (node: any): any => {
const toSync = node => {
if (!node) {
return
}