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

              
                <h1></h1>
<div id="main">
  <div id="clickDiv">
    <p><b>Click anywhere in this panel.</b><br />Open the console to see the event time displayed.</p>
  </div>

  <button id="btnPromise">Promise</button>&nbsp;&nbsp;&nbsp;&nbsp;
  <button id="btnObservable">Observable</button>
  <p><button id="multiple">Subscribe to multiple values</button></p>
  <p><button id="merge">Merge 2 subscriptions</button></p>
</div>
              
            
!

CSS

              
                #clickDiv {
  height: 100px;
  border: thin black solid;
  padding: 3px;
  text-align:center;
  margin: 15px;
}

#main {
  width: 320px;
  text-align:center;
}
              
            
!

JS

              
                //create observable that emits click events
const doc = Rx.Observable.fromEvent(document.getElementById('clickDiv'), 'click');
//map to string with given event timestamp
const example = doc.map(event => `Event time: ${event.timeStamp}`)
//output (example): 'Event time: 7276.390000000001'
const subscribe = example.subscribe(val => console.log(val));

//create observable that emits click events
const promise = Rx.Observable.fromEvent(document.getElementById('btnPromise'), 'click');
promise.subscribe(event => {
  const promise = new Promise(resolve => {
    setTimeout(() => {
      resolve('Hello from a Promise!');
    }, 2000);
  });

  promise.then(value => console.log(value));
});

//create observable that emits click events
const observable = Rx.Observable.fromEvent(document.getElementById('btnObservable'), 'click');
observable.subscribe(event => {
  alert(val);
  const observable = new Rx.Observable(observer => {
    setTimeout(() => {
      observer.next('Hello from an Observable!');
    }, 2000);
  });
  observable.subscribe(value => console.log(value));
});

const multiple = Rx.Observable.fromEvent(document.getElementById('multiple'), 'click');
const interval = Rx.Observable.interval(1000);
multiple.subscribe(val => {
  interval.take(5).subscribe(value => console.log(value));
});


const merge = Rx.Observable.fromEvent(document.getElementById('merge'), 'click');
merge.subscribe(val => {
   const interval2 = Rx.Observable.interval(2000);
   interval2.merge(interval).take(20).subscribe(value => console.log(value));
}); 
              
            
!
999px

Console