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

Added config to debounce preview rendering while live editing #227

Merged
merged 4 commits into from
Nov 15, 2016

Conversation

cef62
Copy link
Collaborator

@cef62 cef62 commented Nov 14, 2016

This is something I've often loved to have using react-styleguidist. Basically it enables to write code in codemirror without having tens of updates on the preview panel. As side-effect is also less probable that while writing the preview will crash because of incomplete expressions.

Is this something you'd like to add to the project?

Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

Please merge master into your branch — it should fix Travis.

@@ -108,6 +108,10 @@ You can change settings in the `styleguide.config.js` file in your project’s r
Type: `String`, default: `base16-light`<br>
[CodeMirror theme](http://codemirror.net/demo/theme.html) name to use for syntax highlighting in examples.

* **`previewDelay`**<br>
Type: `Number`, default: 0<br>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use some non-zero default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if you liked the idea, I'll set to 500ms. It's fast enough to not bother user not interested in it and enough to let other user benefit from the feature.

const { previewDelay, showCode } = context.config;

// `previewDelay` may not be defined or have an invalid value, by defayult is disabled.
this.previewDelay = isFinite(previewDelay) && previewDelay > 0 ? previewDelay : 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previewDelay > 0 check looks unnecessary for me. And it’s better to do all validation in validateConfig() in config.js.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it :) I wasn't aware of validateConfig()


if (this.previewDelay) {
// if previewDelay is enabled debounce the code
this.queuedChange = debounce(queuedChange, 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you should use previewDelay here instead of 1000 ;-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops, my bad sorry!

@cef62
Copy link
Collaborator Author

cef62 commented Nov 14, 2016

I've rebased upon master and fixed as you asked.
If Travis is happy let me know if there's anything else I can improve or if is ok for you ;)

@cef62
Copy link
Collaborator Author

cef62 commented Nov 15, 2016

I'm not sure of why Travis is failing only in one task of one build... any suggestions?

@sapegin
Copy link
Member

sapegin commented Nov 15, 2016

It happens sometimes. Restarting the job usually helps.

Thanks! I’m merging it.

@sapegin sapegin merged commit 3ba27e9 into master Nov 15, 2016
@sapegin sapegin deleted the delayed-preview-rendering branch November 15, 2016 08:40
sapegin added a commit that referenced this pull request Nov 15, 2016
## New features

### Isolated mode for examples

Now you can open single example (not a whole component) in isolated mode:

![](http://wow.sapegin.me/2037140t1y0O/Image%202016-11-14%20at%206.19.19%20PM.png)

(#225 by @cef62)

### Config option to debounce preview rendering while live editing

Default value is 500. That means you’ll not see that annoying red error message box while you’re typing.

(#227 by @cef62)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants