Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-knobs: Add disableForceUpdate option #9447

Merged
merged 5 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/knobs/src/KnobManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function escapeStrings(obj: any): any {
interface KnobManagerOptions {
escapeHTML?: boolean;
disableDebounce?: boolean;
disableForceUpdate?: boolean;
}

export default class KnobManager {
Expand Down
10 changes: 6 additions & 4 deletions addons/knobs/src/registerKnobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ function knobChanged(change: KnobStoreKnob) {
const knobOptions = knobStore.get(name);
knobOptions.value = value;

if (!manager.options.disableDebounce) {
debouncedResetAndForceUpdate();
} else {
resetAndForceUpdate();
if (!manager.options.disableForceUpdate && !knobOptions.disableForceUpdate) {
if (!manager.options.disableDebounce && !knobOptions.disableDebounce) {
atanasster marked this conversation as resolved.
Show resolved Hide resolved
debouncedResetAndForceUpdate();
} else {
resetAndForceUpdate();
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion addons/knobs/src/type-defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export type Mutable<T> = {
-readonly [P in keyof T]: T[P] extends readonly (infer U)[] ? U[] : T[P];
};

type KnobPlus<T extends KnobType, K> = K & { type: T; groupId?: string };
type KnobPlus<T extends KnobType, K> = K & {
type: T;
groupId?: string;
disableDebounce?: boolean;
disableForceUpdate?: boolean;
};

export type Knob<T extends KnobType = any> = T extends 'text'
? KnobPlus<T, Pick<TextTypeKnob, 'value'>>
Expand Down