Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created April 20, 2019 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/55b970019549e6fd4d1aec954dea9126 to your computer and use it in GitHub Desktop.
Save barneycarroll/55b970019549e6fd4d1aec954dea9126 to your computer and use it in GitHub Desktop.
import {m} from './deps.js'
import Refresher from './Refresher.js'
const model = window.model = {}
m.mount(document.body, {
view: v => [
m('#Config',
m(Refresher, refresh =>
m('input[type=file]', {
onchange: e => {
const {target: {files: [source]}} = e
if(!source) {}
else if(source.type != 'text/xml'){
alert(badFile)
refresh()
}
else {
const reader = Object.assign(new FileReader()
reader.onload = () => {
model.source = (new DOMParser()).parseFromString(
reader.result,
'application/xml',
)
alert('Success!')
}
reader.onerror = () => {
alert(badFile)
}
reader.readAsText(source)
}
},
}),
),
),
],
})
export const m = window.m
export const O = window.O
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>
Charfinder
</title>
<link rel=stylesheet src=./styles.css/>
</head>
<body>
<script src=//unpkg.com/mithril></script>
<script src=//unpkg.com/patchinko/immutable.js></script>
<script type=module src=./deps.js></script>
<script type=module src=./app.js></script>
</body>
</html>
import {m} from './deps.js'
import viewOf from './viewOf.js'
// View component exposing a single function:
// Once invoked, the function causes the subtree to be reinitialised
export default () => {
let timestamp
const refresh = () => {
timestamp = Date.now()
}
return {
view: v => [
m.fragment({
key: timestamp,
}, [
viewOf(v)(refresh),
]),
],
}
}
export default v => (
typeof v.attrs.view == 'function'
?
v.attrs.view
:
typeof v.children[0] == 'function'
?
v.children[0]
:
typeof v.children[0].children == 'function'
?
v.children[0].children
:
() => v.children
)
@barneycarroll
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment