Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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.


                <button class="incButton">Increment</button>
<button class="decButton">Decrement</button>
<button class="decaIncButton">Increment by 10 in 3 seconds</button>





                class ZeroFux {
  constructor(element) {
    if (element) {
      this.dispatcher = element;
    } else {
      this.dispatcher = document.querySelector('body');

  // The dipatch method takes an action argument
  // of the previously defined action type.
  dispatch(action) {
		  new CustomEvent(action.type, {
		    detail: action,
		    // In case you set a custom dispatcher element
		    // and want them to bubble.
		    bubbles: true,
		    // In case your custom dispatcher is in the
		    // Shadow DOM and you want them to bubble between
		    // the borders or Shadow DOM and regular DOM.
		    compose: true,

  // This method takes an array of action types
  // that can influence a component's state,
  // an object with reducers with the same names
	// as the action types and a reference
	// to the component on which we want to set
	// the state propery.
  setReducers(actionTypes, reducers, component) {
		actionTypes.forEach(actionType => {
			if (reducers[actionType]) {
				this.dispatcher.addEventListener(actionType, e => {
					const action = e.detail;
					component.state = reducers[actionType](component.state, action);
			} else {
				throw new Error(
					`Please add a reducer for the "${actionType}" action.`

const zeroFux = new ZeroFux();

const actionTypes = ['INCREMENT', 'DECREMENT', 'INCREMENT_X'];

const reducers = {
  'INCREMENT': (state, action) => parseInt(state) + 1,
  'DECREMENT': (state, action) => parseInt(state) - 1,
  'INCREMENT_X': (state, action) => parseInt(state) + action.payload,

// Update the counter with ZeroFux:
class Counter extends HTMLElement {
  constructor() {
    this.attachShadow({ mode: 'open' });
    this.state = 0;

  get state() {
    return this._state;

  set state(s) {
		this._state = s;

  connectedCallback() {
    zeroFux.setReducers(actionTypes, reducers, this);

  render() {
    const counterText = document.createTextNode(this.state);
    this.shadowRoot.innerHTML = '';

window.customElements.define('my-counter', Counter);

class SideEffects {
  run() {
    zeroFux.dispatcher.addEventListener('ADD_TEN_IN_THREE', () => {
      window.setTimeout(() => zeroFux.dispatch({
        type: 'INCREMENT_X',
        payload: 10
      }), 3000);

const sideEffects = new SideEffects();;

const incButton = document.querySelector('.incButton');
const decButton = document.querySelector('.decButton');
const decaIncButton = document.querySelector('.decaIncButton');

incButton.addEventListener('click', e => zeroFux.dispatch({ type: 'INCREMENT' }));
decButton.addEventListener('click', e => zeroFux.dispatch({ type: 'DECREMENT' }));
decaIncButton.addEventListener('click', e => zeroFux.dispatch({ type: 'ADD_TEN_IN_THREE' }));