Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <link href="//cdn.jsdelivr.net/picnicss/4.1.1/picnic.min.css" rel="stylesheet">
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <h1>Hello Mag.JS!</h1>
  <a target="_top" href="https://github.com/magnumjs/mag.js">GitHub</a>
  <hr/>
  <div id="demo">
    <h2>Boilerplate <span></span></h2>
    <div id="counter">
      <button>COUNTER
        <count></count>
      </button>
      <counter></counter>
    </div>
  </div>
  <script src="//rawgit.com/magnumjs/mag.js/master/mag-latest.min.js"></script>
  <script src="//rawgit.com/magnumjs/mag.js/master/dist/mag.addons.0.22.min.js"></script>
</body>
</html>
 
.hide {
  display: none;
}
a {
  display: block;
}
a:after {
  content: " \bb";
}
 
/* MagJS Example - Boilerplate v0.2 */
// independent component
var counter = mag.create('counter', {
  controller: function(props) {
    mag.show(this, 'visible')
    this.count = props.count || 1
  },
  view: function(state, props) {
    state.button = {
      count: state.count,
      _onclick: function() {
        state.count++;
        props.onClick(state.count)
      }
    }
    // two ways to show/hide state objects
    state.counter = {
      _text: state.count
    }
    mag.show(state.count % 2, state.counter)
    //     state.counter = mag.show(state.count % 2)
    //     state.counter._text = state.count
  }
})
var props = {
  greet: 'Hello'
}
// parent module
mag.module("demo", {
  controller: function(inprops) {
    this.h2 = {
      _text: inprops.greet,
      _onClick: function() {
        inprops.visible = !inprops.visible || false
      }
    }
  },
  view: function(state, outprops) {
    state.span = ' world!'
    var thing = counter({
      count: 10,
      visible: outprops.visible,
      onClick: function(count) {}
    })
  }
}, props);
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers