Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function logPatch(patch) {
const {type, path, ...rest} = patch
console.log(
// eslint-disable-line no-console
'%c%s%c %s =>',
'color:#2097ac',
type,
'color:inherit',
arrayToJSONMatchPath(path || []),
rest
)
}
// we received a new snapshot and already got an old one. When we receive a snapshot again
// it is usually because the connection has been down. Attempt to save pending changes (if any)
bufferedDocument.commit()
}
return createInitialBufferedDocument(listenerEvent.document || null)
}
if (bufferedDocument === null) {
// eslint-disable-next-line no-console
console.warn(
'Ignoring event of type "%s" since buffered document has not yet been set up with snapshot',
listenerEvent.type
)
return null
}
if (listenerEvent.type === 'mutation') {
bufferedDocument.arrive(new Mutation(listenerEvent))
} else if (listenerEvent.type !== 'reconnect') {
// eslint-disable-next-line no-console
console.warn('Received unexpected server event of type "%s"', listenerEvent.type)
}
return bufferedDocument
}, null),
publishReplay(1),
// we received a new snapshot and already got an old one. When we receive a snapshot again
// it is usually because the connection has been down. Attempt to save pending changes (if any)
bufferedDocument.commit()
}
return createInitialBufferedDocument(serverEvent.document || null)
}
if (!bufferedDocument) {
// eslint-disable-next-line no-console
console.warn(
'Ignoring event of type "%s" since buffered document has not yet been set up with snapshot',
serverEvent.type
)
return bufferedDocument
}
if (serverEvent.type === 'mutation') {
bufferedDocument.arrive(new Mutation(serverEvent))
} else if (serverEvent.type !== 'reconnect') {
// eslint-disable-next-line no-console
console.warn('Received unexpected server event of type "%s"', serverEvent.type)
}
return bufferedDocument
}, null),
publishReplay(1),
getAttribute(attr) {
// TODO
return new ImmutableAccessor(this.node)
}
mutate: (id, mutations) => {
const current = get(id)
const target = current.isLiveEdit ? current.published : current.draft
const nextDoc = new Mutation({
mutations: mutations.map(setPatchId(target._id))
}).apply(target)
return update(id, {
...current,
published: current.isLiveEdit ? nextDoc : current.published,
draft: current.isLiveEdit ? current.draft : nextDoc,
deleted: false
})
},
duplicate: (id, dupeId, prepare) => {
tap(([action, bufferedDocument]) => {
if (action.type === 'mutation') {
bufferedDocument.add(new Mutation({mutations: action.mutations}))
}
if (action.type === 'commit') {
bufferedDocument.commit()
}
}),
mergeMapTo(NEVER),
map(([action, bufferedDocument]) => {
if (action.type === 'mutation') {
bufferedDocument.add(new Mutation({mutations: action.mutations}))
}
if (action.type === 'commit') {
bufferedDocument.commit()
}
return null
}),
filter(Boolean),
getAttribute(key) {
return new ImmutableAccessor(this.value[key])
}
getAttribute(key) {
if (key === '_key') {
return new ImmutableAccessor(this.key)
}
if (key === '_id') {
return new ImmutableAccessor(this.value._id)
}
return this.value[key]
}
getAttribute(attr) {
if (attr === '_type') {
return new ImmutableAccessor('textspan')
}
if (attr === 'content') {
return new ImmutableAccessor(this.content)
}
if (attr === 'marks') {
return new ImmutableAccessor(this.marks)
}
throw new Error(`Unknown key "${attr}"`)
}