css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="content"></div>
              div#content { 
  margin-left: auto; 
  margin-right: auto; 
  width: 100px;

button {
  margin: 0 10px;
  border: none;
  color: white;
  font-weight: bold;
  background-color: #6CA2C8;
  width: 20px; 

              // The Counter component
function Counter(sources) {
  // INTENT: Listen to increment and decrement clicks.
  const increment$ = sources.DOM.select('.increment').events('click').map(() => +1);
  const decrement$ = sources.DOM.select('.decrement').events('click').map(() => -1);
    MODEL: The count$ stream represents the current count of the counter.
    The state is kept by merging the increment$ and decrement$ streams,
    and then 'scanning' them on the current count.
    Let's say the user clicks decrement, then increment, and then
    the decrement again. The marble graph of the streams 
    to visually see what is happening:
    increment$: === -1 ======= -1 ===
    decrement$: ========= +1 ========
    merged:     ====-1 == +1 = -1 ===
    scan:       ==== -1 == 0 = -1 ===
    The 'scan' operator takes the current count, which starts at
    0 thanks to 'startsWith' and each time a new 'merged' value
    is available runs the function. In this case the function simply
    takes the current count and adds the modifier on top of it. The
    value that is returend from 'scan' is the next count.
    In ascii form:

    | count | modifier | result |
    |   0   |    -1    |   -1   |
    |   -1  |    +1    |   0    |
    |   0   |    -1    |   -1   |
  const count$ = Rx.Observable
    .merge(increment$, decrement$)                // Merge the clicks from both buttons into one stream
    .startWith(0)                                 // Start the count at zero.
    .scan((count, modifier) => count + modifier); // Take the current count and perform either -1 or + 1 on it.
    VIEW: Create a stream which represents the UI of the counter.
    Each time the count$ produces a new value the UI should be
    vtree$ stands for 'virtual DOM tree' a Virtual DOM is a structure
    representing a DOM structure but is not the actual DOM. Cycle.js
    uses a Virtual DOM to check what the difference is with the actual
    real DOM. When things differ only the differences are patched back
    to the actual DOM minimizing the DOM operations needed.
    A video about what a Virtual DOM is: https://www.youtube.com/watch?v=a21b-KDHG-Q
  const vtree$ = count$.map(counter =>
      CycleDOM.button('.decrement', '-'),
      CycleDOM.button('.increment', '+')
  const sinks = {
    DOM: vtree$
  return sinks;

  Here Cycle.js will actually make sure our Counter app
  is run. Cycle.run takes the Counter function so it can
  and executes it so it can take the 'sinks' which it passes
  to the CycleDOM driver. A driver takes a 'sink' and performs
  an operation with side effects. The DOM driver will take a
  stream of DOM (vtree$) and renders it into an actual DOM element,
  in this case the #content <div>.
Cycle.run(Counter, {
  DOM: CycleDOM.makeDOMDriver('#content')

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................