Created
August 10, 2019 11:09
-
-
Save barneycarroll/112642de6f43ce6f30858c820319b729 to your computer and use it in GitHub Desktop.
This file contains 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
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