Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created August 10, 2019 11:09
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/112642de6f43ce6f30858c820319b729 to your computer and use it in GitHub Desktop.
Save barneycarroll/112642de6f43ce6f30858c820319b729 to your computer and use it in GitHub Desktop.
export default () => {
const queue = []
let then
return {
onbeforeupdate : () => !blocker,
oncreate : resolve,
onupdate : resolve,
view : ({
instance,
children: [now],
attrs : {onchange = () => {}},
}) => {
let output = [[now]]
onchange({
now,
then,
go: guard(async directive => {
output = [[then], [now]]
await queue(directive)
}),
})
return output
},
}
function resolve(now){
if(resolution)
resolution(now.dom)
}
function guard(directive){
return async () => {
if(resolution)
return console.error(
`Resolution directives must be executed synchronously.`
)
if(blocker)
return console.error(
`Resolution directives are mutually exclusive.`
)
blocker = directive
await directive()
blocker = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment