Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rendered function has no gmap parameter #31

Open
pythoneer opened this issue Jul 7, 2015 · 6 comments
Open

rendered function has no gmap parameter #31

pythoneer opened this issue Jul 7, 2015 · 6 comments

Comments

@pythoneer
Copy link

If i set a function for the rendered option this function is like called 15 times and every time the map object is undefined.

location: {
        type: String,
        autoform: {
            type: 'map',
            afFieldInput: {
                defaultLat: "52.520645",
                defaultLng: "13.409779",
                geolocation: true,
                searchBox: true,
                autolocate: false,
                zoom:15,
                height: "400px",
                rendered: function (gmap) {
                    console.log("set current gmap");
                    console.log(gmap) ;
                    Session.set("currentGoogleMap", gmap);
                }
            }
        }
    },

i looked through your code and can't find an obvious error.

if typeof @data.atts.rendered == 'function'
        @data.atts.rendered @data.map

looks fine to me, but the map is undefined :/

OT: i would love to debug this myself, but i can't find the place to alter the code of your installed package.

@pythoneer
Copy link
Author

ok i found a way to debug this

console.log("check");
console.log(typeof this);
console.log(typeof this.data);
console.log(typeof this.data.atts);
console.log(typeof this.data.atts.rendered);
if (typeof this.data.atts.rendered === 'function') {
  console.log("call rendered");
  this.data.atts.rendered(this.data.map);
} else { 
  console.log("rendered is undef"); 
}

this outputs

check
object
object
object
undefined
rendered is undef

ok i guess that was the wrong place to lock at?

@pythoneer
Copy link
Author

Ah, now i am getting a feel of it whats happening. Your code gets never to the point (if clause) to call my callback function and pass the map as an argument. BUT somehow my callback is invoked anyway! I can choose any arbitrary property name for my callback function but its called anyway.

location: {
        type: String,
        autoform: {
            type: 'map',
            afFieldInput: {
                <left out>,
                absdfXXX: function (gmap) {
                    console.log("set current gmap");
                    console.log(gmap) ;
                    Session.set("currentGoogleMap", gmap);
                }
            }
        }
    },

So obviously i am doing something wrong but the fact that the functions is called anyway made me believe it was right in the first place.

EDIT:
if i log the this.data.atts its showing me, that whatever function name i set its undefined. But that function is called (but maybe erased after?)

EDIT2:
Ok now i am pretty much stuck. After all i would guess your code is right, in a sense that if it ever worked before.I would guess the error is in Autoform itself cuz i can never find a place in your code where the rendered (or whatever i named the function) is not undefined. I could only guess where the toplevel entrypoint of the values passed by Autoform is (either in Template.afMap.created or Template.afMap.rendered i would vote for the last cuz you starting to handle the data here) but all places i found rendered with a function undefined. Im starting to believe, that Autoform is messing this up and for whatever reason calling any function present and destroying it by setting it undefined.

EDIT3:
I havn't looked through the code of Autoform but i believe this is happening. If you set a property as function the function is invoked by Autoform and the returnvalue is saved into the property and passed by. Thats why every arbitrary named property with a function is called but undefined is left over – cuz my function did not return any value. If i do something like this:

location: {
    type: String,
    autoform: {
        type: 'map',
        afFieldInput: {
            <left out>,
            rendered: function () {
                return function(gmap) {
                    console.log("set current gmap");
                    console.log(gmap) ;
                    Session.set("currentGoogleMap", gmap);
                }
            }
        }
    }
}, 

it seems to work but i'll get this error message

Exception from Tracker recompute function:
RangeError: Maximum call stack size exceeded

@mpowaga
Copy link
Collaborator

mpowaga commented Jul 9, 2015

Hmmm... really strange but I guess it's autoform messing up. It seems to work only when you put the rendered callback in afFieldInput and it will return the callback function, e.g.

location: {
  type: String,
  autoform: {
    type: 'map',
    afFieldInput: {
      rendered: function () {
        return function (map) {
          console.log(map);
        };
      }
    }
  }
}

@pythoneer
Copy link
Author

Yes, as i mentioned in my last edit in my third post: if i do that i'll get an exception

Exception from Tracker recompute function:
RangeError: Maximum call stack size exceeded

obviously Autoform is trying to evaluate this recursively, no matter what, until the jsVM stack get overflown.

@mpowaga
Copy link
Collaborator

mpowaga commented Jul 9, 2015

It may be caused by other property. For me it worked. At least on Chrome. I've came across this error on Firefox several times.

@pythoneer
Copy link
Author

I tried it again and surprisingly the exception did not happen but the "outter" function is called 15 times. Regardless of this, you should consider to update your docs or investigating whats causing that quirk (API change of Autoform?) after this i would consider this issue closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants