# Tag Variable Hoisting (Round 2) ## Hoisting from Conditional Body ```jsx <if=show> <const/hoisted = "hi"/> </if> -- ${hoisted} ``` `hoisted` is rendered _once_ with `undefined` if `show` is falsy or `hi` if `show` is truthy. ```jsx <if=show> <const/hoisted = "hi"/> </if> -- ${hoisted} <button onClick() { show = !show } /> ``` ## Hoisting from Repeated Body ```jsx <for|i| until=10> <const/hoisted=i/> </for> -- ${Array.from(hosited)} ``` `hosited` is rend ## Hoisting from Async Body ### Same Async Context _child.marko_ ```jsx <${input.renderBody}("sync")/> <await|value| = Promise.resolve("async")> <${input.renderBody}(value)/> </await> ``` _parent.marko_ ```jsx <child|value|> <const/hoisted = value/> </child> -- ${Array.from(hoisted)} ``` `hoisted` is rendered _once_ with `["sync", "async"]` ### Separate Async Context (1) _child.marko_ ```jsx <${input.renderBody}("sync")/> <try> <await|value| = Promise.resolve("async")> <${input.renderBody}(value)/> </await> </try> <placeholder> Loading... </placeholder> ``` _parent.marko_ ```jsx <child|value|> <const/hoisted = value/> </child> -- ${Array.from(hoisted)} ``` `hoisted` is rendered _twice_ with `["sync"]` first and then `["sync", "async"]` ### Separate Async Context (2) _child.marko_ ```jsx <try> <${input.renderBody}("sync")/> <await|value| = Promise.resolve("async")> <${input.renderBody}(value)/> </await> </try> <placeholder> Loading... </placeholder> ``` _parent.marko_ ```jsx <child|value|> <const/hoisted = value/> </child> -- ${Array.from(hoisted)} ``` `hoisted` is rendered _twice_ with `undefined` first and then `["sync", "async"]`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up