Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(connection, channel) {
this.connection = connection
this.messageSubscription = this.connection.listen().subscribe(this.handleMessage)
this.myState = {}
this.states = new Map()
this.timestamps = new Map()
this.resendReportTimer = null
this.changeReportDebounceTimer = null
this.performPurgeTimer = setInterval(this.performPurge, 2000)
this.sessionId = UUID()
this.requestRollCall()
// List of functions that will be called with presence change notifications
this.subscriberCallbacks = []
}
function getIntentState(intentName, params, currentState, payload) {
const paneSegments = (currentState && currentState.panes) || []
const activePanes = state.activePanes || []
const editDocumentId = params.id || UUID()
const isTemplate = intentName === 'create' && params.template
// Loop through open panes and see if any of them can handle the intent
for (let i = activePanes.length - 1; i >= 0; i--) {
const pane = activePanes[i]
if (pane.canHandleIntent && pane.canHandleIntent(intentName, params, {pane, index: i})) {
const paneParams = isTemplate ? {template: params.template} : EMPTY_PARAMS
return {
panes: paneSegments
.slice(0, i)
.concat([[{id: editDocumentId, params: paneParams, payload}]])
}
}
}
return {intent: intentName, params, payload}
execute: ({snapshots}: OperationArgs, prepare = id) => {
const omitProps = ['_id', '_createdAt', '_updatedAt']
const source = snapshots.draft || snapshots.published
return client.create({_id: getDraftId(uuid()), ...omit(prepare(source), omitProps)})
}
}
function getNewRouterState({structure, documentType, params, payload, documentId, paneSegments}) {
const lastChild = structure[structure.length - 1] || {}
const lastGroup = paneSegments[paneSegments.length - 1]
const lastSibling = lastGroup[lastGroup.length - 1]
const terminatesInDocument = lastChild.type === 'document' && lastChild.options.id === documentId
const isTemplateCreate = params.template
const template = isTemplateCreate && getTemplateById(params.template)
const type = (template && template.schemaType) || documentType
const fallbackParameters = {type, template: params.template}
const newDocumentId = documentId === FALLBACK_ID ? UUID() : documentId
return terminatesInDocument
? paneSegments
.slice(0, -1)
.concat([lastGroup.slice(0, -1).concat({...lastSibling, id: newDocumentId})])
: [[{id: `__edit__${newDocumentId}`, params: fallbackParameters, payload}]]
}
const documentId = id || FALLBACK_ID
const {documentType, isLoaded} = useDocumentType(documentId, specifiedSchemaType)
const paneSegments = documentType
? [[{id: documentType, params: {}}], [{id: documentId, params: otherParams, payload}]]
: undefined
const {structure, error} = useStructure(paneSegments, {silent: true})
if (error) {
return
}
if (!documentType) {
return isLoaded ? (
) : (
)
}
const isLoading = !structure || structure.some(item => item === LOADING_PANE)
if (isLoading) {
return
}
const panes = getNewRouterState({
structure,
documentType,
params: otherParams,
payload,
paneSegments,