-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create reusable selector factory for Encoder
- Loading branch information
1 parent
52d120a
commit 852b9e6
Showing
5 changed files
with
38 additions
and
44 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
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
19 changes: 19 additions & 0 deletions
19
...t-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/createEncoderSelector.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,19 @@ | ||
import { createSelector } from 'reselect'; | ||
import { PartialSpec, BaseOptions } from './types/Specification'; | ||
import AbstractEncoder from './AbstractEncoder'; | ||
import { ChannelType } from './types/Channel'; | ||
import { ChannelDef } from './types/ChannelDef'; | ||
import { MayBeArray } from './types/Base'; | ||
|
||
export default function createEncoderSelector< | ||
EncoderConstructor extends AbstractEncoder<ChannelTypes, Encoding, Options>, | ||
ChannelTypes extends Record<string, ChannelType>, | ||
Encoding extends Record<keyof ChannelTypes, MayBeArray<ChannelDef>>, | ||
Options extends BaseOptions = BaseOptions | ||
>(EncoderConstructor: new (spec: PartialSpec<Encoding, Options>) => EncoderConstructor) { | ||
return createSelector( | ||
(spec: PartialSpec<Encoding, Options>) => spec.encoding, | ||
spec => spec.options, | ||
(encoding, options) => new EncoderConstructor({ encoding, options }), | ||
); | ||
} |