<!DOCTYPE html>
<html>
<head>
<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>Lots of Things!</h2>
</header>
<footer>
<!-- REPEATER -->
<div id="repeater">
<h1>Riot <button>Reverse</button> <timeTaken></timeTaken></h1>
<div id="data"> Loading..
<span id="magjsappMountNode2">
<timeTaken></timeTaken>
<h2 class="magjsdata hide">Line #<span class="num"></span></h2>
</span>
</div>
</div>
<!-- REPEATER -->
<hr/>
</footer>
</article>
<script src="//rawgit.com/magnumjs/mag.js/master/mag-latest.min.js"></script>
<script src="app.js"></script>
</body>
</html>
var items = [];
for (var i = 0; i < 5000; i++) {
items.push({
num: i
});
}
var magjsdataNode = {
controller: function(props) {
this.h2 = {
_class: "magjsdata"
}
this.willload = function(node) {
this.startTime = performance.now()
}
this.didload = function(node) {
var msg = node.id + ': - Loading ' + props.items.length + ' rows took ' + (performance.now() - this.startTime).toFixed(2) + 'ms';
this.state.timeTaken = msg;
}
this.willupdate = function(node) {
if (this.props.isReversing) this.startTime = performance.now()
}
this.didupdate = function(node) {
if (this.props.isReversing) {
var msg = node.id + ': - Reversing ' + props.items.length + ' rows took ' + (performance.now() - this.startTime).toFixed(2) + 'ms';
this.state.timeTaken = msg;
}
}
},
view: function(state, props) {
state.magjsdata = props.items.map(function(data) {
return {
num: data.num
}
});
}
}
var data = mag("magjsappMountNode2", magjsdataNode, {
key: 55
});
var demo = {};
demo.controller = function(props) {
this.button = {}
this.items = props.items.slice();
this.willload = function(node) {
this.startTime = performance.now()
}
this.didload = function(node) {
var msg = node.id + ': - Loading ' + this.state.items.length + ' rows took ' + (performance.now() - this.startTime).toFixed(2) + 'ms';
this.state.timeTaken = msg;
}
this.willupdate = function(node) {
if (this.state.button._disabled) this.startTime = performance.now()
}
this.didupdate = function(node) {
if (this.state.button._disabled) {
var msg = node.id + ': - Reversing ' + this.state.items.length + ' rows took ' + (performance.now() - this.startTime).toFixed(2) + 'ms';
this.state.timeTaken = msg;
this.state.button._disabled = false;
}
}
}
demo.view = function(state, props) {
state.data = data({
items: state.items,
isReversing: state.button._disabled
})
state.button._onclick = function() {
state.button._disabled = true;
state.items.reverse();
}
}
var props = {
items: items
}
mag.rafBounce=1
mag.module("repeater", demo, props)
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
## plunk boilerplate of "Things"
Basic Mag.JS boilerplate to count and create a list of things dynamically.