feat: revamped keybinding implementation
This commit is contained in:
14
helpers/utils/clipboard.ts
Normal file
14
helpers/utils/clipboard.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copies a given string to the clipboard using
|
||||
* the legacy exec method
|
||||
*
|
||||
* @param content The content to be copied
|
||||
*/
|
||||
export function copyToClipboard(content: string) {
|
||||
const dummy = document.createElement("input")
|
||||
document.body.appendChild(dummy)
|
||||
dummy.value = content
|
||||
dummy.select()
|
||||
document.execCommand("copy")
|
||||
document.body.removeChild(dummy)
|
||||
}
|
||||
@@ -88,3 +88,35 @@ export function pluckRef<T, K extends keyof T>(ref: Ref<T>, key: K): Ref<T[K]> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* A composable that listens to the stream and fires update callbacks
|
||||
* but respects the component lifecycle
|
||||
*
|
||||
* @param stream The stream to subscribe to
|
||||
* @param next Callback called on value emission
|
||||
* @param error Callback called on stream error
|
||||
* @param complete Callback called on stream completion
|
||||
*/
|
||||
export function subscribeToStream<T>(
|
||||
stream: Observable<T>,
|
||||
next: (value: T) => void,
|
||||
error: (e: any) => void,
|
||||
complete: () => void
|
||||
) {
|
||||
let sub: Subscription | null = null
|
||||
|
||||
// Don't perform anymore updates if the component is
|
||||
// gonna unmount
|
||||
onBeforeUnmount(() => {
|
||||
if (sub) {
|
||||
sub.unsubscribe()
|
||||
}
|
||||
})
|
||||
|
||||
sub = stream.subscribe({
|
||||
next,
|
||||
error,
|
||||
complete,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user