Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions api/browser/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,39 @@ class Selection {
return
}
this.#client = newValue
this.#setup()
}

constructor (props) {
this.#props = props
}

async #setup () {
/*
Only listen to changes to
the _serverSelection key
and set the selection in this
thread when it changes

Typically the API shouldn't
attach event listeners itself
as it may force data to be pushed
even though it's not used by the client

- but make an exception here as
this code is only run in the renderer
thread and listeners on state.change
are required anyway
*/
this.#props.Events.on('state.change', (state, set) => {
if (!set?._connections?.[this.#client.getIdentity()]?._serverSelection) {
return
}
const newSelection = state?._connections?.[this.#client.getIdentity()]?._serverSelection
this.setSelection(newSelection)
})
}

/**
* Select an item,
* will replace the
Expand Down
2 changes: 1 addition & 1 deletion api/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class State {
this.applyLocally(set)
}

return this.#state
return [this.#state, set]
})
}

Expand Down
7 changes: 6 additions & 1 deletion plugins/rundown/lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ async function selectItem (id) {
bridge.state.apply({
_connections: {
[mainClientId]: {
selection: { $replace: [id] }
/*
Use a key that the
client can listen to
and act on
*/
_serverSelection: { $replace: [id] }
}
}
})
Expand Down