What is a good way to know when all surfaces had been initially rendered in famo.us?

筅森魡賤 提交于 2020-01-14 03:07:28

问题


I would like to be able to know when all views have been rendered in a layout. The reason I want to do this is because I need to be able to reference positions of rendered views in the layout, so that I may animate views relative to other views that had already been rendered.

I have read this: Surface render events in famo.us

One way I can think of is to count views that have been rendered and after all had been rendered (based on a known count), I can then assume all have been rendered. Obviously this would not work if there's an unknown number of views to render.

So another way to achieve this would be to have the layout fire a custom event when all of its managed surfaces have completed rendering. It seems like a good place to do this would be in a function shim in the given layout. For example, in SequentialLayout it would be SequentialLayout.prototype.commit. But, I am not 100% certain on whether that's the right approach, because it looks like the Engine or Entity manages the rendering. So, what that smells like to me is that this approach wouldn't actually fire the event I want fired at the right time.

Are there any best practices for this?


回答1:


The best way in your use case may be to listen for the deploy on each surface (renderable) in each view

surface.on('deploy', function() {...});

and once all of the surfaces have been deployed emit a custom event to the view

thisView._eventOutput.emit('completed-deploy', {data: someData});

You can then listen to each view to know when the renderables are deployed

view.on('completed-deploy', function(data) {....});

Although this does take care of the fact that the renderable is deployed to the DOM, it will not let you know if it is done with any transition of a modifier. In the case you would also need to have a function for flagging when transition is complete in your views, if that is what you need.



来源:https://stackoverflow.com/questions/27681117/what-is-a-good-way-to-know-when-all-surfaces-had-been-initially-rendered-in-famo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!