Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db
74 changes: 49 additions & 25 deletions demo.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
<h1>Hi guys!</h1>

You can view the raw <a href="/feed">/feed</a>, or play with the UI below.

<h2>Feed</h2>
<pre id=feed-pre></pre>
<div id=feed-post></div>
<br>
<textarea id=subject placeholder=subject></textarea>
<textarea id=body placeholder=body></textarea>
<input type=button value='new post' onclick='make_new_post()' />


<script type=module>
import * as braid from 'https://esm.sh/braid-http@0.3.5'

var feed = []
function render () {
fetch_posts().then(posts =>
document.getElementById('feed-post').innerHTML =
posts.map(p =>
`<p><a href='${p.url}'><code style='font-size:10'>${p.url}</code></a><br>
<!DOCTYPE html>
<html>
<head>
<title>&lt;:-)</title>
<script async src="/public/vendor/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"@sillonious/module": "/public/module.js",
"braid-http": "https://esm.sh/braid-http@0.3.5",
"diffhtml": "https://esm.sh/diffhtml@1.0.0-beta.30",
"statebus": "/public/_statebus.js"
}
}
</script>

</head>
<body>
<h1>Hi guys!</h1>

You can view the raw <a href="/feed">/feed</a>, or play with the UI below.

<h2>Feed</h2>
<feed-post></feed-post>
<br>
<textarea id=subject placeholder=subject></textarea>
<textarea id=body placeholder=body></textarea>
<input type=button value='new post' onclick='make_new_post()' />

<script type=module>
import * as braid from 'braid-http'
import module from '@sillonious/module'

let feed = []
const $ = module('feed-post', { posts: [] })

$.draw(render)

function render (target) {
fetch_posts()
const { posts } = $.learn()
return posts.map(p =>
`<p><a href='${p.url}'><code style='font-size:10'>${p.url}</code></a><br>
<b>${p.subject || ''}</b><br>
${p.body}</p>`
).join('\n'))
).join('\n')
}

var update_feed = (update) => {
Expand Down Expand Up @@ -91,7 +112,7 @@ <h2>Feed</h2>
else
return undefined
}

async function fetch_posts () {
var result = []
for (var i=0; i<feed.length; i++) {
Expand All @@ -100,6 +121,7 @@ <h2>Feed</h2>
result.push({url: feed[i].link, ...JSON.parse(post)})
}

$.teach({ posts: result })
return result
}

Expand All @@ -120,4 +142,6 @@ <h2>Feed</h2>

window.make_new_post = make_new_post

</script>
</script>
</body>
</html>
5 changes: 4 additions & 1 deletion demo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
var fs = require('fs'),
app = require('express')(),
express = require('express'),
braidmail = require('./index.js')

var app = express()

app.use(free_the_cors)

// Host some simple HTML
sendfile = (f) => (req, res) => res.sendFile(f, {root:'.'})
app.get('/', sendfile('demo.html'))

app.use('/public', express.static('public'))
app.use(braidmail)

// Spin up the server
Expand Down
Loading