Fix too many useless angular detection changes

pull/6402/head
Chocobozzz 2024-05-15 15:38:50 +02:00
parent 2177995056
commit b6dd016601
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 27 additions and 25 deletions

View File

@ -1,6 +1,6 @@
// Thanks to https://github.com/brtnshrdr/angular2-hotkeys // Thanks to https://github.com/brtnshrdr/angular2-hotkeys
import { Injectable } from '@angular/core' import { Injectable, NgZone } from '@angular/core'
import { Hotkey } from './hotkey.model' import { Hotkey } from './hotkey.model'
import { Subject } from 'rxjs' import { Subject } from 'rxjs'
import { tinykeys } from 'tinykeys' import { tinykeys } from 'tinykeys'
@ -19,7 +19,7 @@ export class HotkeysService {
private removeTinyKeysStore = new Map<Hotkey, (() => void)[]>() private removeTinyKeysStore = new Map<Hotkey, (() => void)[]>()
constructor () { constructor (private zone: NgZone) {
this.initCheatSheet() this.initCheatSheet()
} }
@ -54,31 +54,33 @@ export class HotkeysService {
for (const combo of hotkey.combo) { for (const combo of hotkey.combo) {
debugLogger('Adding hotkey ' + hotkey.formatted) debugLogger('Adding hotkey ' + hotkey.formatted)
const removeTinyKey = tinykeys(window, { this.zone.runOutsideAngular(() => {
[combo]: event => { const removeTinyKey = tinykeys(window, {
if (this.disabled) return [combo]: event => {
if (this.disabled) return
const target = event.target as Element const target = event.target as Element
const nodeName: string = target.nodeName.toUpperCase() const nodeName: string = target.nodeName.toUpperCase()
if (this.preventIn.includes(nodeName)) { if (this.preventIn.includes(nodeName)) {
return return
}
const result = hotkey.callback.apply(this, [ event, combo ])
if (result === false) {
event.preventDefault()
event.stopPropagation()
}
} }
})
const result = hotkey.callback.apply(this, [ event, combo ]) if (!this.removeTinyKeysStore.has(hotkey)) {
this.removeTinyKeysStore.set(hotkey, [])
if (result === false) {
event.preventDefault()
event.stopPropagation()
}
} }
this.removeTinyKeysStore.get(hotkey).push(removeTinyKey)
}) })
if (!this.removeTinyKeysStore.has(hotkey)) {
this.removeTinyKeysStore.set(hotkey, [])
}
this.removeTinyKeysStore.get(hotkey).push(removeTinyKey)
} }
return hotkey return hotkey

View File

@ -1,6 +1,6 @@
import { uniq } from 'lodash-es' import { uniq } from 'lodash-es'
import { Observable } from 'rxjs' import { Observable, timer } from 'rxjs'
import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators' import { buffer, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators'
function buildBulkObservable <P extends number | string, R> (options: { function buildBulkObservable <P extends number | string, R> (options: {
notifierObservable: Observable<P> notifierObservable: Observable<P>
@ -11,7 +11,7 @@ function buildBulkObservable <P extends number | string, R> (options: {
return notifierObservable.pipe( return notifierObservable.pipe(
distinctUntilChanged(), distinctUntilChanged(),
bufferTime(time), buffer(timer(time)),
filter(params => params.length !== 0), filter(params => params.length !== 0),
map(params => uniq(params)), map(params => uniq(params)),
switchMap(params => { switchMap(params => {

View File

@ -136,7 +136,7 @@ export class FindInBulkService {
notifier, notifier,
result: buildBulkObservable({ result: buildBulkObservable({
time: 500, time: 100,
bulkGet, bulkGet,
notifierObservable: notifier.asObservable() notifierObservable: notifier.asObservable()
}) })