Last active
September 25, 2018 19:31
-
-
Save ara4n/d69797f29f316e56bc22cd5688b46b37 to your computer and use it in GitHub Desktop.
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> | |
<script src="https://cdn.jsdelivr.net/npm/preact/dist/preact.min.js"></script> | |
<script type="text/javascript"> | |
const h = preact.h; | |
class Timeline extends preact.Component { | |
render() { | |
return ( // we manually convert JSX into h() to avoid depending on babel or similar | |
h('ol', null, | |
this.props.events.map((ev)=> | |
h('li', null, [ | |
h('span', { className: "sender" }, ev.sender + " " ), | |
h('span', { className: "body" }, ev.contents.formatted_body || ev.contents.body ), | |
]) | |
) | |
) | |
); | |
} | |
} | |
let events = []; | |
function setEvents(args) { | |
events = args.append ? events.concat(args.events) : args.events; | |
preact.render(h(Timeline, { events }), document.body, document.body.lastChild); | |
} | |
</script> | |
<script type="text/javascript"> | |
// Fake client pretending to be Swift | |
setTimeout(()=>{ | |
setEvents({ | |
events: [ | |
{ sender: "@matthew:matrix.org", contents: { body: "Hello world!" } }, | |
{ sender: "@matthew:matrix.org", contents: { formatted_body: "I am a fish" } }, | |
], | |
}); | |
}, 0); | |
setTimeout(()=>{ | |
setEvents({ | |
events: [ | |
{ sender: "@neil:sandbox.modular.im", contents: { body: "Mr Flibble is very cross!" } }, | |
], | |
append: true, | |
}); | |
}, 1000); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment