Skip to content

Commit

Permalink
Merge pull request #9447 from novli/patch-3
Browse files Browse the repository at this point in the history
Addon-knobs: Add `disableForceUpdate` option
  • Loading branch information
shilman authored Feb 21, 2020
2 parents 151d28a + a234c2c commit 461837d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions addons/knobs/src/KnobManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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) {
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

0 comments on commit 461837d

Please sign in to comment.