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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <ol id="log"></ol>
              
            
!

CSS

              
                ol {
  list-style-type: none;
  padding: 0;
}
              
            
!

JS

              
                const { Observable, Observer, Subject } = rxjs;

const logEl = document.getElementById('log');
function log(message) {
  const li = document.createElement('li');
  const text = document.createTextNode(message);
  li.appendChild(text);
  logEl.appendChild(li);
}

const tapRefCount = (onChange) => (source) => {
  let refCount = 0;

  // mute the operator if it has nothing to do
  if (typeof onChange !== 'function') {
    return source;
  }
  
  // mute errors from side-effects
  const safeOnChange = (refCount, prevRefCount) => {
    try {
      onChange(refCount, prevRefCount);
    } catch (e) {
      console.error(e);
    }
  };
  
  // spy on subscribe
  return Observable.create((observer) => {
    const subscription = source.subscribe(observer);
    const prevRefCount = refCount;
    refCount++;
    safeOnChange(refCount, prevRefCount);
    
    // spy on unsubscribe
    return () => {
      subscription.unsubscribe();
      const prevRefCount = refCount;
      refCount--;
      safeOnChange(refCount, prevRefCount);
    };
  });
};

console.clear();
const subject = new Subject();
const stream = subject.pipe(
  tapRefCount((refCount, prevRefCount) => {
    log(JSON.stringify({ refCount, prevRefCount }));
  })
);

let subIntCount = 0;
const subscriptions = [];
const subInt = setInterval(() => {
  let subscription;
  subIntCount++;
  
  // stop
  if (subIntCount == 10) {
    while(subscription = subscriptions.pop()) {
      log('[unsubscribe]');
      subscription.unsubscribe();
    }
    clearInterval(subInt);
    log('[done]');
  }
  
  // unsubscribe... maybe
  if (subscriptions.length > 0 && Math.random() > 0.5) {
    log('[unsubscribe]');
    subscription = subscriptions.pop();
    subscription.unsubscribe();
    return;
  }
  
  // subscribe
  log('[subscribe]');
  subscription = stream.subscribe();
  subscriptions.push(subscription);
}, 1000);
              
            
!
999px

Console