marko-js / fastify

Render Marko templates in a Fastify application.
MIT License
10 stars 1 forks source link

out in component.js #4

Closed mbykov closed 3 years ago

mbykov commented 3 years ago

Description

In template.marko ${out.global} works perfect.

But how can I get global out in component.js?

I've tried

console.log(window.locals); console.log(window.out);

and so on, but alas...

DylanPiercey commented 3 years ago

You can access out (and thus out.global) in the onCreate, onInput and onRender lifecycles. https://markojs.com/docs/class-components/#lifecycle-event-methods

One thing to note is that out.global is scoped to the current render, and is lost when rerendering in the browser. You can tell Marko to persist a subset of the out.global properties during the initial hydration using an allow list (see serializedGlobals here: https://markojs.com/docs/rendering/#global-data). If you want that data to be long lived in the browser though you'll need to copy it somewhere else during app hydration.

mbykov commented 3 years ago

Thank you!