このクラスでは、初期化されたブール状態を使用してMobx.autorunの実行を行います。 Otherwize 'this'は完全に割り当てられておらず、エラーにつながります。これを行う別の方法がありますか?クラスコンストラクタでの発火を防ぐために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
};
どの変数が観察可能なものとして装飾されているかを指定できますか?私はオートランがあなたの現在のセットアップではまったく起動しないと期待します。 – mweststrate
そして、 'coordinates'はおそらく建設中に実際に起動されるか、あるいは自動実行が初期化目的のために一度実行されるのでしょうか? – dagatsoin