Last active
August 29, 2015 14:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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