This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private checkPressedKeys(keyboardEvents: KeyboardEvent[], pressedKeysSize: number) { | |
if (pressedKeysSize === 0) { | |
// all keys have been released by "keyup" => inform subscribers | |
return true; | |
} else if (keyboardEvents.length === pressedKeysSize) { | |
// check for the exactly count of pressed shortcut keys is important | |
// also the sequence of the key presses is important => check the order | |
const sorted = [...keyboardEvents] | |
.sort((event1, event2) => (event1.timeStamp < event2.timeStamp ? -1 : 1)) | |
.map(event1 => event1.code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private singleShortcut$(keyCodes: string[]): Observable<KeyboardEvent[] | undefined> { | |
const keyEvents$: Observable<KeyboardEvent> = this.createKeyEvents(); | |
const pressedKeys = new Set<string>(); | |
// create event stream for every shortcut key | |
const shortcutKeys$: Observable<KeyboardEvent>[] = keyCodes.map(keyCode => keyEvents$ | |
.pipe( | |
filter(keyboardEvent => keyboardEvent.code === keyCode), | |
tap(keyboardEvent => { | |
if (keyboardEvent.type === 'keydown') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates cartesian product of given iterables. | |
*/ | |
private* cartesianIterator(items: string[][]): Generator<string[]> { | |
const remainder = items.length > 1 ? this.cartesianIterator(items.slice(1)) : [[]]; | |
for (const r of remainder) { | |
for (const h of items.at(0)!) { | |
yield [h, ...r]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ShortcutKey { | |
static readonly A = new ShortcutKey('KeyA'); | |
static readonly B = new ShortcutKey('KeyB'); | |
... | |
static readonly Digit0 = new ShortcutKey('Digit0'); | |
static readonly Digit1 = new ShortcutKey('Digit1'); | |
... | |
static readonly F1 = new ShortcutKey('F1'); | |
static readonly F2 = new ShortcutKey('F2'); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// register Shift key as shortcut | |
this._shortcutManager.shortcut$(ShortcutKey.Shift) | |
.pipe(takeUntil(this._destroy$$)) | |
.subscribe(keyboardEvents => this.updateRoute(keyboardEvents)); | |
// register W key as shortcut | |
this._subscription = this._shortcutManager.shortcut$(ShortcutKey.W) | |
.pipe( | |
// we're only interested in "keydown" | |
filter(keyboardEvents => keyboardEvents != null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shortcut$(ShortcutKey.Ctrl, ShortcutKey.F) | |
.pipe(takeUntilDestroyed()) | |
.subscribe(keyboardEvents => this.doSomething(keyboardEvents)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shortcut$(...shortcutKeys: ShortcutKey[]): Observable<KeyboardEvent[] | undefined> { | |
const keyCodes: string[][] = shortcutKeys.map(shortcutKey => | |
Array.isArray(shortcutKey.keyCode) ? shortcutKey.keyCode : [shortcutKey.keyCode]); | |
if (keyCodes.length === 1 && keyCodes[0].length === 1) { | |
// small optimization for a single key binding | |
return this.singleShortcut$(keyCodes[0]); | |
} | |
const keyCodesAsCartesianProduct = [...this.cartesianIterator(keyCodes)]; | |
const arr$: Observable<KeyboardEvent[] | undefined>[] = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@Slf4j | |
@RequiredArgsConstructor | |
public class SspDefinitionenStore implements SspDefinitionConsumer { | |
private CacheMono<VersionedId, SspDefinition, SspDefinition> sspDefinitionCache; | |
private FluxSink<SspDefinition> sspDefinitionSink; | |
@PostConstruct | |
public void initialize() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@Slf4j | |
@RequiredArgsConstructor | |
public class TopologyRepository { | |
private final CacheMono<TopologyRef, TopologyDto, TopologyDto> cache; | |
private final TopologyLoader topologyLoader; | |
private final TopologyCreator topologyCreator; | |
@Autowired |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets cached values as Java Stream. Returned stream is not sorted. | |
*/ | |
public Stream<OVALUE> getValues() { | |
final Lock readLock = lock.readLock(); | |
readLock.lock(); | |
try { | |
return cache.values().stream().flatMap(cachedValue -> cachedValue.getValue().stream()); | |
} finally { | |
readLock.unlock(); |
NewerOlder