В этом классе я использую инициализированное логическое состояние для выполнения Mobx.autorun. В противном случае «это» не присваивается полностью и приводит к ошибкам. Есть ли другой/более чистый способ сделать это?
class GameMaster{
private _initialized:boolean = false;
private _store:IDomainStore;
private _moveDisposer:Lambda;
/**
*
* @param store - client or server store
*/
constructor(store:IDomainStore){
this._store = store;
console.log(this._store);
//todo abstract services to decouple client device from GameMaster because it is also used on the server.
this._moveDisposer = autorun(()=>{
// prevent firing in the constructor
if(this._initialized) {
this.present(
<IIntent>{
fromId: 'GeoLocation.service',
toIds: [Meteor.userId()],
wish: actions.playerActions.types.CHANGE_PLAYER_GEO_COORDINATES,
data: [System.GeolocationService.coordinates.lng, System.GeolocationService.coordinates.lat]
});
}
});
this._initialized = true;
}
public present(intent:IIntent):boolean{
...
}
...
}
Это моя наблюдаемая в другом файле:
@observable coordinates = {
lng:0,
lat:0
};
coordinates
, вероятно, действительно срабатывает во время построения или, может быть, автозапуск запускается один раз для целей инициализации? - person dagatsoin   schedule 04.05.2016