Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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),
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),