cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Xgxqqb

A Pen By Captain Anonymous

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <h1>xūs todos demo</h1>

<div id="main">
  <div>
    <form onsubmit="add">
      <input type="text" id="input" />
      <input type="submit" value="Add task" />
    </form>
    <p>You have completed <b>{completedCount}</b> of your tasks. Congratulations!</p>
    <p><b>Click on more tasks to finish them!</b><p>
    <ul>
      {#todos}
      <li class="{#done}finished{/done}" onClick="toggle">{title}</li>
      {/todos}
    </ul>
   <div>
  </div>
    <p><a href="https://github.com/tetsuo/xus/blob/master/examples/demo.html">source</a></p>
    <p><a href="https://tetsuo.github.io/xus/">xūs API homepage</a></p>
    
            
          
!
            
              const types = mobxStateTree.types

const Todo = types.model("Todo", {
  title: types.string,
  done: true
}, {
  toggle() {
    this.done = !this.done
  }
})

const State = types.model("State", {
  todos: types.array(Todo),
  get completedCount() {
    return this.todos.reduce((count, todo) => (todo.done ? count + 1 : count), 0)
  }
}, {
  add(event) {
    event.preventDefault()

    const currentTarget = event.currentTarget
    const input = currentTarget.querySelector("input[type=text]")

    if (!input.value.length) {
      return
    }

    this.todos.unshift({
      title: input.value,
      done: false
    })

    input.value = ""
  }
})

const state = State.create({
  todos: [
    { title: "Get coffee", done: false },
    { title: "Wake up", done: true }
  ]
})

var targetElement = document.getElementById("main")

var options = {
  createElement: React.createElement,
  observer: mobxReact.observer
}

// ...aaand, action!
xus(targetElement.innerHTML, state, options, (er, newElement) => {
  if (er) throw er

  ReactDOM.render(newElement, targetElement)

  document.getElementById("input").focus()
})
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console