If you re doing just loading, like Jacob, I would also suggest a library that handles loading
If the case of a more complicated situation like mixing loaders and other event listeners, I would suggest using an event that fires whenever there is any change to any of the dependencies. In addition all the objects/classes would have a state.
然后,我将设立一个听众,为需要履行职能或启动职能的那一类人增加职能,这具有3个参数。
- object with event dispatcher (assuming they all use the same update event) ie.
assetLoader
- name of object state ie.
headerLoaded
- state value s desired ie.
true
the function would add the listener to a chain of listeners, and any time any of the listeners fires, all objects would check if the state value.
这样做也会使退步(例如当用户使用一个顿语时,内容开始装货,而用户则取消,即使所有资产装载,一个物体的状态都是假的,从而不允许该项目完成) 如果你使用柜台,那就等于是增加,而不是拉平,但更可靠。