@@ -136,41 +136,40 @@ export default class Project {
136136 * 当前 project 内的 document 变更事件
137137 */
138138 onChangeDocument ( fn : ( doc : DocumentModel ) => void ) {
139+ const offFn = this [ projectSymbol ] . onCurrentDocumentChange ( ( originalDoc ) => {
140+ fn ( DocumentModel . create ( originalDoc ) ! ) ;
141+ } ) ;
139142 if ( this [ projectSymbol ] . currentDocument ) {
140143 fn ( DocumentModel . create ( this [ projectSymbol ] . currentDocument ) ! ) ;
141- return ( ) => { } ;
142144 }
143- return this [ projectSymbol ] . onCurrentDocumentChange ( ( originalDoc ) => {
144- fn ( DocumentModel . create ( originalDoc ) ! ) ;
145- } ) ;
145+ return offFn ;
146146 }
147147
148148 /**
149149 * 当前 project 的模拟器 ready 事件
150150 */
151151 onSimulatorHostReady ( fn : ( host : SimulatorHost ) => void ) {
152- if ( this [ simulatorHostSymbol ] ) {
153- fn ( SimulatorHost . create ( this [ simulatorHostSymbol ] ) ! ) ;
154- return ( ) => { } ;
155- }
156- return this [ projectSymbol ] . onSimulatorReady ( ( simulator : BuiltinSimulatorHost ) => {
152+ const offFn = this [ projectSymbol ] . onSimulatorReady ( ( simulator : BuiltinSimulatorHost ) => {
157153 this [ simulatorHostSymbol ] = simulator ;
158154 fn ( SimulatorHost . create ( simulator ) ! ) ;
159155 } ) ;
156+ if ( this [ simulatorHostSymbol ] ) {
157+ fn ( SimulatorHost . create ( this [ simulatorHostSymbol ] ) ! ) ;
158+ }
159+ return offFn ;
160160 }
161161
162162 /**
163163 * 当前 project 的渲染器 ready 事件
164164 */
165165 onSimulatorRendererReady ( fn : ( ) => void ) {
166- if ( this [ simulatorRendererSymbol ] ) {
167- fn ( ) ;
168- return ( ) => { } ;
169- }
170- // TODO: 补充 renderer 实例
171- return this [ projectSymbol ] . onRendererReady ( ( renderer : any ) => {
166+ const offFn = this [ projectSymbol ] . onRendererReady ( ( renderer : any ) => {
172167 this [ simulatorRendererSymbol ] = renderer ;
173168 fn ( ) ;
174169 } ) ;
170+ if ( this [ simulatorRendererSymbol ] ) {
171+ fn ( ) ;
172+ }
173+ return offFn ;
175174 }
176175}
0 commit comments