0
「export default AvatarStore;」としてクラスをエクスポートすると、 「デフォルトの新しいAvatarStore()をエクスポート」と対比他のクラスでそのメソッドを使用しようとして、次のエラーが表示されます...新しい構文を使用して正しいですか?ここReact Nativeは「関数ではありません」
import { List } from 'immutable';
import EventEmitter from 'events';
import Utils from '../utils/Utils.js'
import RestService from '../services/RestService'
import RestCallStatus from '../constants/RestCallStatus'
import Avatar from '../models/Avatar'
const CHANGE_EVENT = 'change';
const TAG = 'AvatarStore';
class AvatarStore extends EventEmitter {
constructor() {
super();
this._populateRestCallStatus = RestCallStatus.NOT_REQUESTED;
this._populated = false;
this._dataStore = List();
}
populate(){
RestService.getAllAvatars(this.handleSuccess.bind(this), this.handleFailure.bind(this));
this._populateRestCallStatus = RestCallStatus.STARTED
}
handleSuccess(serviceName, jsonData){
Utils.logMethod(TAG, 'handleSuccess ' + serviceName);
if(jsonData.length > 0){ this._dataStore = List().clear(); }
jsonData.forEach((entity) => {
this._dataStore = this._dataStore.push(new Avatar(entity))
});
this._populated = true;
this._populateRestCallStatus = RestCallStatus.SUCCESS;
this.emitChange();
}
handleFailure(serviceName, error){
Utils.logMethod(TAG, 'handleFailure');
this._populateRestCallStatus = RestCallStatus.FAILED
console.error(`Server call ${serviceName} failed with error: ${serviceName}!`)
}
getItems(){
//Utils.logMethod(TAG, 'getItems');
return this._dataStore;
}
getItemById(itemId){
return Utils.findArrayElementById(this._dataStore, itemId);
}
getPopulated(){
return this._populated;
}
addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
}
removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
}
emitChange() {
Utils.logMethod(TAG, 'emitChange');
this.emit(CHANGE_EVENT);
}
}
export default new AvatarStore();