paku
1
Hi all,
Trying to define the class like that:
export class Map {
constructor(parentTemplate, mapName, images, defaultLocation) {
this.mapInstance = {};
this.state = new ReactiveDict();
GoogleMaps.ready(mapName, this.onMapReady); <<call back
}
onMapReady(map) {
this.mapInstance = map;
this.state.set('mapField', this.getField()); <<state is undefined (???)
}
getField() {
return {'fsfsdfsfdsdf'};
}
but the ‘state’ var is undefined on callback call.
Any ideas ?
Oh I’ve been so blind. Sorry!
Ok so the reason is that you pass in a function but you need to bind it’s context do it like this:
GoogleMaps.ready(mapName, this.onMapReady.bind(this));
paku
6
Have to ask again,
My constructor consumes reactive var later inside the tracker call
constructor( .....
...
...
Tracker.autorun(() => {
console.log('loadMapMarkers triggered');
Meteor.subscribe('xxx', this.state.get('yyyy'));
this.loadMapMarkers(); << THIS CALL FAIL
});
where loadMapMarkers is the same object method and then calls other method (of the same object again):
loadMapMarkers() {
this.defMapMarker(); << BECAUSE THAT ONE is undefined
}
defMapMarker() {
console.log('never run');
}
So the problem is the call of the second nested method.
reoh
7
Bind your methods:
constructor () {
this.defMapMarker = this.defMapMarker.bind(this);
}
or
defMapMarker = () => {
...
}
paku
8
and then
depMapMarker (){
something;
}
???
It’s working without given constructor line.
Edit:
Solved after found that one of the inner forEach loops was not converted into new syntax, instead of
xxx.forEach((yyyy) => {})
it was:
xxx.forEach( function (yyyy) {})
I had to be blind …