addStoryKnob<T extends KnobNodeBase> method

T addStoryKnob<T extends KnobNodeBase>(
  1. String storyKey, {
  2. required String knobKey,
  3. required T knobNode,
})

Adds knob to story by storyKey.

Implementation

T addStoryKnob<T extends KnobNodeBase>(
  /// Key of the [Story].
  String storyKey, {

  /// Knob node key.
  required String knobKey,

  /// Knob node value.
  required T knobNode,
}) {
  if (_value.containsKey(storyKey)) {
    final knobs = _value[storyKey]!;

    if (!knobs.containsKey(knobKey)) {
      knobs[knobKey] = knobNode;
    }
  } else {
    _value[storyKey] = {
      knobKey: knobNode,
    };
  }

  return _value[storyKey]![knobKey]! as T;
}