Skip to content

Instantly share code, notes, and snippets.

@morten-olsen
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save morten-olsen/e1283c5b69da6b1cc1c5 to your computer and use it in GitHub Desktop.

Select an option

Save morten-olsen/e1283c5b69da6b1cc1c5 to your computer and use it in GitHub Desktop.
Very minimal function primer... and a pub sub system, which fit inside a tweet, just for god messure
<html>
<head>
<script src="primer.js"></script>
</head>
<body>
<button p-click="demo|notYetReady('test')">Try</button>
<script>
setTimeout(function () {
window.notYetReady = function (msg) {
alert(msg)
};
p.r('demo');
}, 5000);
</script>
</body>
</html>
var p = {
m: {},
f: function (a, b) {
return b ? b.attributes[a] ? b : p.f(a, b.parentElement) : null
},
r: function (a) {
p.m[a] && p.m[a].map(function (a) {
eval(a)
});
p.m[a] = !0
},
h: function (a) {
var b = p.f("p-" + a.type, a.target);
b && (a = b.attributes["p-" + a.type].value.split("|"),
p.m[a[0]] = p.m[a[0]] || [],
!0 === p.m[a[0]] ? eval(a[1]) : p.m[a[0]].push(a[1]))
}
};
["click"].map(function (a) {
document.documentElement.addEventListener(a, p.h)
});
var ps = {
c : {},
sub: function (a, b) {
ps.c[a] || (ps.c[a] = []);
ps.c[a].push(b)
},
pub: function (a, b) {
ps.c[a] && ps.c[a].forEach(function (a) {
a(b)
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment