<!DOCTYPE html>
<html>

<head>
  <link href="//cdn.jsdelivr.net/picnicss/4.1.1/picnic.min.css" rel="stylesheet">
  <link href="style.css" rel="stylesheet">
</head>

<body>

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

  <div id="app">
    <status>Loading ..</status>
    <counter></counter>
    <counter2></counter2>
    <ul>
      <li></li>
    </ul>
  </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>
  <script src="//rawgit.com/magnumjs/mag.js/master/src/addons/mag-importer.js"></script>

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

</body>

</html>
// initialize mag module reference

mag.mods.demo.container({
  things: []
})
/* Styles go here */

li:empty, .hide {
  display:none;
}
#Components

##Inner component
Reusable, self contained, called by others

###Example-counter
*Separate html&javascript file definition
*counter.html includes counter.js

##Outer component
Loads and instantiate other components

###Example multiple counters 
*Load counter module definition
*Attach to dom

**Clone, create instance, attach clone, run instance
(function(namespace) {

  var defaultProps = {
    onButtonClick: things => {}
  }

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

      state.button = {
        _onClick: function() {
          state.count = state.count + 1 || props.count || 1
          props.numbers.push(state.count)
          props.onButtonClick(props.numbers)
        }
      }
    }
  }


  namespace.counter = mag.create('counter', mod, defaultProps)

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

  var mod = {}

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

  mod.controller = function(props) {
    this.li = props.things
    props.loaded = false;

    mag.importer('counter.html', 'counter')
      .then(() => props.loaded = true)


    mag.importer('counter.html', 'counter2')
      .then(() => props.loaded2 = true)

  }

  mod.view = function(state, props) {

    mag.show(!props.loaded, state.status = {});

    if (props.loaded) {

      mag.mods.demo.counter({
        key: "things",
        numbers: props.things,
        onButtonClick: function(numbers) {
          state.li = numbers
        }
      });

    }

    if (props.loaded2) {

      mag.mods.demo.counter('counter2', {
        key: "otherThings",
        numbers: props.things,
        onButtonClick: function(numbers) {
          state.li = numbers
        }
      });

    }

  }


  namespace.container = mag.create('app', mod, defaultProps)

})(mag.namespace('mods.demo'))
<counter>
  <div id="counter">
    <button>+</button>
    <count></count>
  </div>
  <link href="counter.css" rel="stylesheet">
  <script src="counter.js"></script>
</counter>
button {
  background-color:red;
}