<!DOCTYPE html>
<html>

<head>
  <link href="//cdn.jsdelivr.net/picnicss/4.1.1/picnic.min.css" rel="stylesheet">
  <link rel="stylesheet" href="style.css">
  <meta charset="utf-8">
  <title>Mag.JS</title>
</head>

<body>

  <nav>
    <h1>Hello Mag.JS!</h1>
    <a target="_tab" href="https://github.com/magnumjs/mag.js">GitHub</a>
  </nav>

  <article class="card">
    <header>
      <h2>BoilerPlate Things!</h2>
    </header>

    <footer>
      <div id="app" class="hide">
        <button class="mainButton">Boilerplate:
          <count></count>
        </button>
        My things:
        <count></count>
        <ul>
          <li></li>
        </ul>
      </div>
    </footer>
  </article>


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

  <script src="parent-mod.js"></script>
  <script src="child-mod.js"></script>

  <script src="app-init.js"></script>

</body>

</html>


// initialize mag module reference

mag.mods.demo.parent({ things: []});
li:empty,
.hide {
  display: none;
}

a {
  display: block;
}

a:after {
  content: " \bb";
}

.mainButton {
  font-size: 1.5em;
}

nav a {
  float: right;
  margin-top: -50px;
}

body {
  background: #fff;
  text-align: left;
  width: 90%;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 0 0;
}

nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3em;
  padding: 0 .6em;
  background: #fff;
  box-shadow: 0 0 0.2em rgba(17, 17, 17, 0.2);
  z-index: 10000;
  transition: all .3s;
  transform-style: preserve-3d;
}

header {
  font-weight: bold;
  position: relative;
  border-bottom: 1px solid #eee;
  padding: .6em .8em;
}

footer {
  padding: .8em;
}

article {
  top: 100px;
}

.card {
  max-width: 100%;
  display: block;
  position: relative;
  box-shadow: 0;
  border-radius: .2em;
  border: 1px solid #ccc;
  overflow: hidden;
  text-align: left;
  background: #fff;
  margin-bottom: .6em;
  padding: 6px;
  transition: all .3s ease;
}
#Mag.JS Modular namespacing
  

Best practice in creating objects

1. always have one global top level namespace
  e.g. var MyCoolApp = MyCoolApp || {};

2. That is included on every page 

3.All sub modules are based on that
  But they use local vars and return in functions
  
  4. Always have a top parent moduel container
  5. components are reusable within modules

                
(function(namespace) {

  var props = {
    onThingClick: function(things) {}
  }

  var mod = {
    view: function(state, props) {

      state.button = {
        _onclick: function() {
          state.count = state.count + 1 || 1
          props.things.push(state.count)
          props.onThingClick(props.things)
        }
      }
    }
  }


  namespace.child = mag.create('app', mod, props);

})(mag.namespace('mods.demo'));
(function(namespace) {

  var mod = {}

  // default props to be over ridden
  var props = {
    things: []
  }

  mod.controller = function(props) {

    mag.show(this)
    this.li = props.things
    this.button ='My MagJS mod!'

  }

  mod.view = function(state, props) {

    mag.mods.demo.child({
      key: "things",
      things: props.things,
      onThingClick: function(things) {
        state.li = things
      }
    });

  }


  namespace.parent = mag.create('app', mod, props);

})(mag.namespace('mods.demo'));