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.

Better control over runnable examples

See original GitHub issue

Right now, the JS script in the page relies on a test to define if the code of an example should be runnable or not: contains search.addWidget? or /function renderFn\(\S+(, isFirstRendering)?\) {/g.test(exampleContent)?

This gives poor control over what’s runnable or not, which seems magical and also lead to inconsistent experience like the new calendar guide. In this guide, we have one runnable example while the others are not. Given the context, none should be runnable in the guide.

Options could be:

  • have a way to specify runnable js
  • have a front matter option for setting if the js examples on the page should be runnable

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
francoischalifourcommented, Feb 5, 2018

Here are the solutions that I see with their pros and cons:

1. In the frontmatter

Example

---
title: My guide
runnable: false
---

Pros

  • Easy to set up

Cons

  • Make all code samples in the page not runnable (we might want to only disable one)

2. As a comment/annotation in the code itself

Example

```javascript
@runnable
// code...
```

Pros

  • Enable/disable a unique code sample

Cons

  • We need to parse and remove it (not sure how easy it is yet)

3. As a new Markdown language

We can create an extension to our Markdown parser to create a runnable JavaScript language.

Example

```runnable-javascript
// My code
```

Pros

  • Enable/disable a unique code sample

Cons

  • Need to create another parser
  • We lose the IDE syntax highlighting

4. As an HTML Element

Example

<pre class="runnable">
  <code>
    // my code
  </code>
</pre>

Pros

  • Enable/disable a unique code sample

Cons

  • We lose all IDE syntax highlighting
  • We lose syntax highlighting in the browser (since we cannot specify the language anymore as far as I know)

For now, I’d say that the frontmatter solution (1) is the easiest to implement.

1reaction
francoischalifourcommented, Mar 3, 2018

Yes! What default behavior do we want? (runnable or not runnable)

Having it not runnable by default would be annoying as we’d have to update most of the guides and docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing a Runnable vs Extending a Thread | Baeldung
Learn why implementing Runnable is a better approach than extending Thread class.
Read more >
Java Runnable Example - Examples Java Code Geeks - 2022
In this example, we will take a look into the Runnable interface in Java, and how it can be used in association with...
Read more >
Write Asynchronous Code in Java using Runnable Threads ...
Creating and deciding when to run our threads gives you more control over what your application does. That may not sound intuitive, ...
Read more >
"implements Runnable" vs "extends Thread" in Java
Yes: implements Runnable is the preferred way to do it, IMO. You're not really specialising the thread's behaviour. You're just giving it ...
Read more >
Runnable Interface in Java - Javatpoint
The runnable class is used to perform multi-thread programming, especially in server-side as a server may be getting several requests from different clients....
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