From 967a3e9a2715d8f3a835b1cf9a78f85353dc5b0c Mon Sep 17 00:00:00 2001 From: Vladimir Novikov Date: Tue, 14 Jan 2020 19:07:46 +0300 Subject: [PATCH 1/4] addon-knobs disableForceUpdate option --- addons/knobs/src/registerKnobs.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/knobs/src/registerKnobs.ts b/addons/knobs/src/registerKnobs.ts index 0c2be7e5b105..1dee9de26b8b 100644 --- a/addons/knobs/src/registerKnobs.ts +++ b/addons/knobs/src/registerKnobs.ts @@ -22,7 +22,9 @@ function setPaneKnobs(timestamp: boolean | number = +new Date()) { const resetAndForceUpdate = () => { knobStore.markAllUnused(); - forceReRender(); + if (!manager.options.disableForceUpdate) { + forceReRender(); + } }; // Increase performance by reducing how frequently the story is recreated during knob changes From 9fea73ab4babd8602c2906f6d894aba65a65e6e0 Mon Sep 17 00:00:00 2001 From: Vladimir Novikov Date: Sun, 19 Jan 2020 01:27:34 +0300 Subject: [PATCH 2/4] allow disabling force-update and debounce by knob options --- addons/knobs/src/registerKnobs.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/knobs/src/registerKnobs.ts b/addons/knobs/src/registerKnobs.ts index 1dee9de26b8b..40980934e736 100644 --- a/addons/knobs/src/registerKnobs.ts +++ b/addons/knobs/src/registerKnobs.ts @@ -22,9 +22,7 @@ function setPaneKnobs(timestamp: boolean | number = +new Date()) { const resetAndForceUpdate = () => { knobStore.markAllUnused(); - if (!manager.options.disableForceUpdate) { - forceReRender(); - } + forceReRender(); }; // Increase performance by reducing how frequently the story is recreated during knob changes @@ -39,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(); + } } } From f5a14a5ee5865ff395a62e685d3faa693027363b Mon Sep 17 00:00:00 2001 From: Vladimir Novikov Date: Sun, 19 Jan 2020 01:30:27 +0300 Subject: [PATCH 3/4] update typings for disableDebounce and disableForceUpdate knob options --- addons/knobs/src/type-defs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/knobs/src/type-defs.ts b/addons/knobs/src/type-defs.ts index ddc8c2de34e3..a2fd1e4b5b4a 100644 --- a/addons/knobs/src/type-defs.ts +++ b/addons/knobs/src/type-defs.ts @@ -18,7 +18,7 @@ export type Mutable = { -readonly [P in keyof T]: T[P] extends readonly (infer U)[] ? U[] : T[P]; }; -type KnobPlus = K & { type: T; groupId?: string }; +type KnobPlus = K & { type: T; groupId?: string; disableDebounce?: boolean; disableForceUpdate?: boolean }; export type Knob = T extends 'text' ? KnobPlus> From a234c2ccc769f1881da557188a05282e3fd16ef0 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sat, 1 Feb 2020 19:27:40 +0800 Subject: [PATCH 4/4] Addon-knobs: Fix typescript types for disableForceUpdate --- addons/knobs/src/KnobManager.ts | 1 + addons/knobs/src/type-defs.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/knobs/src/KnobManager.ts b/addons/knobs/src/KnobManager.ts index f59430f73e37..8ef58c373fda 100644 --- a/addons/knobs/src/KnobManager.ts +++ b/addons/knobs/src/KnobManager.ts @@ -49,6 +49,7 @@ function escapeStrings(obj: any): any { interface KnobManagerOptions { escapeHTML?: boolean; disableDebounce?: boolean; + disableForceUpdate?: boolean; } export default class KnobManager { diff --git a/addons/knobs/src/type-defs.ts b/addons/knobs/src/type-defs.ts index a2fd1e4b5b4a..469dbdc6f83b 100644 --- a/addons/knobs/src/type-defs.ts +++ b/addons/knobs/src/type-defs.ts @@ -18,7 +18,12 @@ export type Mutable = { -readonly [P in keyof T]: T[P] extends readonly (infer U)[] ? U[] : T[P]; }; -type KnobPlus = K & { type: T; groupId?: string; disableDebounce?: boolean; disableForceUpdate?: boolean }; +type KnobPlus = K & { + type: T; + groupId?: string; + disableDebounce?: boolean; + disableForceUpdate?: boolean; +}; export type Knob = T extends 'text' ? KnobPlus>