-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
149 additions
and
144 deletions.
There are no files selected for viewing
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
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
77 changes: 77 additions & 0 deletions
77
packages/core/pluggableElementTypes/renderers/LayoutSession.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import deepEqual from 'fast-deep-equal' | ||
|
||
import { readConfObject } from '../../configuration' | ||
import GranularRectLayout from '../../util/layouts/GranularRectLayout' | ||
import MultiLayout from '../../util/layouts/MultiLayout' | ||
|
||
import type { AnyConfigurationModel } from '../../configuration' | ||
import type SerializableFilterChain from './util/serializableFilterChain' | ||
|
||
export interface LayoutSessionProps { | ||
config: AnyConfigurationModel | ||
bpPerPx: number | ||
filters?: SerializableFilterChain | ||
} | ||
|
||
export type MyMultiLayout = MultiLayout<GranularRectLayout<unknown>, unknown> | ||
|
||
export interface CachedLayout { | ||
layout: MyMultiLayout | ||
config: AnyConfigurationModel | ||
filters?: SerializableFilterChain | ||
} | ||
|
||
export class LayoutSession implements LayoutSessionProps { | ||
config: AnyConfigurationModel | ||
|
||
bpPerPx: number | ||
|
||
filters?: SerializableFilterChain | ||
|
||
constructor(args: LayoutSessionProps) { | ||
this.config = args.config | ||
this.bpPerPx = args.bpPerPx | ||
this.filters = args.filters | ||
} | ||
|
||
update(args: LayoutSessionProps) { | ||
this.config = args.config | ||
this.bpPerPx = args.bpPerPx | ||
this.filters = args.filters | ||
return this | ||
} | ||
|
||
makeLayout() { | ||
return new MultiLayout(GranularRectLayout, { | ||
maxHeight: readConfObject(this.config, 'maxHeight'), | ||
displayMode: readConfObject(this.config, 'displayMode'), | ||
pitchX: this.bpPerPx, | ||
pitchY: readConfObject(this.config, 'noSpacing') ? 1 : 3, | ||
}) | ||
} | ||
|
||
/** | ||
* @param layout - | ||
* @returns true if the given layout is a valid one to use for this session | ||
*/ | ||
cachedLayoutIsValid(cachedLayout: CachedLayout) { | ||
return ( | ||
cachedLayout.layout.subLayoutConstructorArgs.pitchX === this.bpPerPx && | ||
deepEqual(readConfObject(this.config), cachedLayout.config) && | ||
deepEqual(this.filters, cachedLayout.filters) | ||
) | ||
} | ||
|
||
cachedLayout: CachedLayout | undefined | ||
|
||
get layout(): MyMultiLayout { | ||
if (!this.cachedLayout || !this.cachedLayoutIsValid(this.cachedLayout)) { | ||
this.cachedLayout = { | ||
layout: this.makeLayout(), | ||
config: readConfObject(this.config), | ||
filters: this.filters, | ||
} | ||
} | ||
return this.cachedLayout.layout | ||
} | ||
} |
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
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
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
Oops, something went wrong.