Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                const root = document.getElementById('root')
const bus = new Bulb.Bus()

// A signal that searches for books by ISBN and emits the result as a new state.
const searchSignal = bus
  // Don't bother searching for empty queries.
  .filter(a => a !== '')

  // Search for the book using the API.
  .concatMap(findBook)

  // Create a new state.
  .map(result => ({ result, loading: false }))

// A signal that emits a loading state while the request is processing.
const loadingSignal = bus.always({ result: null, loading: true })

// Start with the default state and re-render the view when the other signals emit values.
Bulb.Signal.of({ result: null, loading: false })
  .merge(searchSignal, loadingSignal)
  .subscribe(
    state => ReactDOM.render(<RootView bus={bus} loading={state.loading} result={state.result} />, root)
  )

// Returns a signal that emits the result of the search request to the API.
function findBook (isbn) {
  const url = `https://www.googleapis.com/books/v1/volumes?q=isbn:${isbn}`
  return Bulb.Signal
    .fromPromise(fetch(url).then(response => response.json()))
    .map(
      data => data.totalItems > 0 ? data.items[0].volumeInfo.title : null
    )
}

function RootView ({ bus, loading, result }) {
  const [query, setQuery] = React.useState('')

  return (
    <div className='jumbotron jumbotron-fluid'>
      <div className='container'>
        <h1>Book Search 📚</h1>
        <p className='lead'>This example demonstrates using a signal to handle an AJAX request.</p>
        <p>Enter an ISBN to find on Google Books (e.g. 0747532699).</p>
        <div class='input-group mb-3'>
          <input className='form-control' onChange={event => setQuery(event.target.value)} placeholder='ISBN' type='text' />
          <div className='input-group-append'>
            <Button disabled={loading} onClick={() => bus.next(query)}>
              {loading ? <Spinner /> : null}
              Search
            </Button>
          </div>
        </div>
        {result ? <pre>{result}</pre> : null}
      </div>
    </div>
  )
}

function Button ({ children, disabled, onClick }) {
  return (
    <button className='btn btn-primary' disabled={disabled} onClick={onClick}>{children}</button>
  )
}

function Spinner () {
  return (
    <React.Fragment>
      <span className='spinner-grow spinner-grow-sm' role='status' aria-hidden='true'></span>
      &nbsp;
    </React.Fragment>
  )
}
              
            
!
999px

Console