question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@storybook/angular] [Knobs] forceRerender doesn't trigger Constructor

See original GitHub issue

There seems to be no ability to force a story to use Knobs to modify the constructor of its component. Various issues have been opened about this, but they all inevitably become stale, then closed without resolution.

To Reproduce Steps to reproduce the behavior:

  1. Create a component and story with the following code:
@Component({
  selector: 'mybutton',
  template:'<div>Sample</div>',
})
export class ButtonComponent implements OnInit {
  @Input() myText?: string;
  constructor() {
    console.log('I"m under construction!');
    console.log('Text is: ', this.myText);
  }
  ngOnInit() {
    console.log('I"m being initialized!');
    console.log('Text is: ', this.myText);
  }
}

import { FORCE_RE_RENDER } from '@storybook/core-events';
import { addons } from '@storybook/addons';
import { text, withKnobs, button } from '@storybook/addon-knobs';
import { ButtonComponent } from '../somewhere/component.ts';

export default { 
  title: 'Banner',
  decorators: [
    withKnobs
  ]
}
export const Sample = () => ({
  component: ButtonComponent,
  props: {
    myText: text('myText', 'Main Title'),
    button: button('Refresh', () => {
      console.log('Attempting to trigger refresh');
      addons.getChannel().emit(FORCE_RE_RENDER);
    })
  },
});

Expected Result There should be a console.log with the current value of the Knob input for both the constructor and ngOnInit every time ForceRender is run.

Failing that, there should be some way to trigger the constructor if desired, using the current value of the knobs.

System: Environment Info: System: OS: Windows Server 2016 10.0.14393 CPU: (4) x64 Intel® Xeon® CPU E5-2673 v4 @ 2.30GHz Binaries: Node: 10.16.0 - C:\Program Files\nodejs\node.EXE npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD

Package.json: “@storybook/addon-actions”: “^5.2.8”, “@storybook/addon-links”: “^5.2.8”, “@storybook/addon-notes”: “^5.2.8”, “@storybook/addons”: “^5.2.8”, “@storybook/angular”: “^5.2.8”, “@storybook/addon-knobs”: “^5.2.8”, “@storybook/cli”: “^5.2.8”, Angular CLI: 8.3.20 Angular: 8.2.14 @angular-devkit/architect 0.803.20 @angular-devkit/build-angular 0.803.21 @angular-devkit/build-ng-packagr 0.803.21 @angular-devkit/build-optimizer 0.803.21 @angular-devkit/build-webpack 0.803.21 @angular-devkit/core 8.3.20 @angular-devkit/schematics 8.3.20 @angular/cdk 8.2.3 @angular/cli 8.3.20 @angular/flex-layout 8.0.0-beta.27 @angular/material 8.2.3 @ngtools/webpack 8.3.21 @schematics/angular 8.3.20 @schematics/update 0.803.20 ng-packagr 5.7.1 rxjs 6.4.0 typescript 3.5.3 webpack 4.39.2

Additional context It seems there has been some discussion about this in the past, but it inevitably ends in a “Stale” tag and the thread being locked.

https://github.com/storybookjs/storybook/issues/7002 https://github.com/storybookjs/storybook/issues/4760

Not a duplicate of:

https://github.com/storybookjs/storybook/issues/8825 https://github.com/storybookjs/storybook/issues/1736

Seems to be directly related to (Or even caused by): https://github.com/storybookjs/storybook/pull/6094

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
dfagan2commented, Jan 6, 2020

Running into the same thing

1reaction
shilmancommented, Jun 11, 2020

FYI, we’ve just released addon-controls in 6.0-beta! Controls are portable, auto-generated knobs that are intended to replace addon-knobs long term.

Please upgrade and try them out today. Thanks for your help and support getting this stable for release!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storybook: Changing the value of the control doesnot rerender ...
I am using Angular based Storybook . All I wanted to do is to re-render the chart based on the values given in...
Read more >
storybookjs/storybook (Raised $170.00) - Issuehunt
[Bug]: Actions via the handles parameter don't fire after navigating to the docs page and returning to the component in Storybook v7.0.0 beta....
Read more >
Actions - Storybook - JS.ORG
Actions work via supplying special Storybook-generated “action” arguments (referred to as "args" for short) to your stories. There are two ways to get...
Read more >
Dictionary
... Actium activate activated activates activating activation activations ... anguilliform anguine anguish anguished angular angularity angularization ...
Read more >
cXD - ALBA.Net
Belchior cantor 2012, Uralac am 352, Start mixed media art journal, Nike roshe run mid ... 2605 lakevale drive vienna va, Denver doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found