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


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


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.


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.


                <p><strong>Be sure to open the console to see script output.</strong></p>
<p>If you find this demo useful, please consider <a href="" target="_blank">donating $1 dollar</a> (secure PayPal link) for a coffee or purchasing one of my songs from <a href="" target="_blank"></a> or <a href="" target="_blank"></a> for only 0.99 cents each.</p>
<p>Rob uses and recommends <a href="" target="_blank">MochaHost</a>, which provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!</p>




                import { Observable, timer } from "";
import { retryWhen, tap, delayWhen, take } from "";

type UserSettings = { 
  settings: {
    viewType: number, 
    isLimited?: boolean 

enum ViewSelectionValues {

class UserSettingsException extends Error {
  constructor(status: number, message: String) {
    // Ensure the name of this error is the same as the class name =;
    this.status = status;
    // Set the prototype explicitly.
    Object.setPrototypeOf(this, UserSettingsException.prototype);

class UserService {
  constructor() {
    this.userSettingsMap = new Map([
          settings: {
            isLimited: false
          settings: {
            viewType: ViewSelectionValues.table,
            isLimited: true

  getSettings(userid: String) {
    return new Observable(observable => {
      setTimeout(() => {
        if (userid === "9999") {
          console.log("Throwing error.");
            new UserSettingsException(999, "An error occured!")
        } else if (userid === "retry") {
          console.log("Throwing error for retry.");
            new UserSettingsException(666, "An error occured!")
        } else if (this.userSettingsMap.has(userid)) {
        } else {
          console.log("User not found.");
            new UserSettingsException(404, "User " + userid + " not found.")
      }, 2000);

class Client {
  constructor(userid) {
    this.userid = userid;
    this.userService = new UserService();

  setViewType() {
    let retryAttempts = 0;
      retryWhen(errors => 
          delayWhen(() => {
            console.log(`Retry attempt #${++retryAttempts}`);
            return timer(2000);
    .subscribe(userSettings => {
      console.log(userSettings.settings.viewType, userSettings.settings.isLimited);
      this.viewType = 
        userSettings.settings['viewType'] ||;
      console.log("Got viewType: " + this.viewType);
    error => {
      this.viewType =;
      if (error.status && error.status !== 404) {
        throw error;
console.log("Starting demo.");
console.log("Creating client 1234.");
let client = new Client('1234');

console.log("Creating new client with no settings yet.");
client = new Client('4444');

console.log("Creating client 3456.");
client = new Client('3456');

console.log("Creating error client.");
client = new Client('9999');

console.log("Creating retry client.");
client = new Client('retry');