简体   繁体   English

渲染前后的海边挂钩

[英]Seaside hooks before and after rendering

I wanted to see if there is a hook in Seaside that is called before rendering, and one after rendering.我想看看 Seaside 中是否有一个在渲染之前调用的钩子,以及一个在渲染之后调用的钩子。 It happens to me that I want to show a notification on the screen, and I would like that once the rendering is finished, this component is modified so that the next time the rendering is done, it is no longer displayed.碰巧我想在屏幕上显示一个通知,我希望一旦渲染完成,修改这个组件,以便下次渲染完成时不再显示它。

Thanks and regards!谢谢并恭祝安康!

Instead of 'hooks', Seaside has component decorations that you can wrap around a component to change their behaviour. Seaside 没有“钩子”,而是具有组件装饰,您可以将其包裹在组件周围以更改其行为。 If you wrap your root component, you can implement a decoration that invokes hooks before and after rendering on your entire component tree.如果你包装你的根组件,你可以实现一个装饰,在整个组件树上渲染之前和之后调用钩子。

However, changing the state of your components while rendering will break the state backtracking behavior that Seaside offers you.但是,在渲染时更改组件的 state 将破坏 Seaside 为您提供的 state 回溯行为。 The state changes should happen in the action callbacks. state 更改应该发生在操作回调中。 So, there is no 'after rendering' phase where you can change the state of your component (well, you can, but it will lead to subtle problems ).因此,没有“渲染后”阶段,您可以在其中更改组件的 state(当然可以,但会导致一些细微的问题)。 Instead, use the action phase (ie callbacks) to change the state of your component such that the next time the rendering phase is invoked, your component is not displayed.相反,使用操作阶段(即回调)来更改组件的 state 以便下次调用渲染阶段时,不会显示您的组件。

I'm assuming that when you say 'the next time the rendering is done', this means after the user has clicked a link or done some other action.我假设当您说“下一次渲染完成”时,这意味着在用户单击链接或执行其他操作之后。 This means you can change state while executing the action callback and arrange the state of your rendering tree such that the concerned component is no longer shown.这意味着您可以在执行操作回调时更改 state 并安排渲染树的 state 以便不再显示相关组件。 If you do it like this, the user will see the component again when he clicks the back button in the browser.如果您这样做,用户将在单击浏览器中的后退按钮时再次看到该组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM