问题
UPDATE: The problem is NOT in spark - Although I misunderstood what was going on, and thus the question is somewhat poorly formed, I am leaving this question up just in case it benefits others.
I'm getting the following error:
Exception from Deps recompute: TypeError: Cannot read property 'nodeName' of null
at Patcher.match (http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:1540:12)
When I click on the link at the second line, it directs me to the following section of spark.js where the error is:
// Look at tags of parents until we hit parent of last-kept, // 229
// which we know is ok. // 230
for(var a=tgt.parentNode, b=src.parentNode; // 231
a !== (starting ? this.tgtParent : lastKeptTgt.parentNode); // 232
a = a.parentNode, b = b.parentNode) { // 233
if (b === (starting ? this.srcParent : lastKeptSrc.parentNode)) // 234
return false; // src is shallower, b hit top first // 235
if (a.nodeName !== b.nodeName) // 236
return false; // tag names don't match // 237
}
The offending line is this one: if (a.nodeName !== b.nodeName)
. I want to debug this... how do I modify the spark.js file? I would like to put in statements just as console.log(a)
, and would like to check whether a
or b
has the property nodeName
.
Questions on StackOverflow that are relevant to this one are:
How to investigate "Exception form Deps recompute" what are the clues?
How can I modify the Meteor (meteorite) that is running?
The first one wasn't really answered. The second one included advice on how to add a package to meteor so that you can modify it. But that didn't work for me - my modifications either didn't show up (if I followed the advice in link #2 above) or generated an error saying that meteor could not find spark.js (if I tried to modify the spark.js file in the client folder of a packages folder in either ~/.meteor/ or the .meteor/ directory of my project.
Would anyone have any advice on how I can modify the spark.js file (the client version) for my meteor project?
Thanks!
UPDATE 09-Nov-2013:
The reason I get these errors is because I am trying to store the results of an asynchronous call to the google maps geocoder.geocode() object/method in a reactive session variable:
SessionAmplify = _.extend({}, Session, {
keys: _.object(_.map(amplify.store(), function(value, key) {
return [key, JSON.stringify(value)]
})),
set: function (key, value) {
Session.set.apply(this, arguments);
amplify.store(key, value);
},
});
setLocation = function (e) {
e.preventDefault;
var address = e.target.value;
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
$('.found-address').html(results[0].formatted_address);
SessionAmplify.set('pos', results[0].geometry.location);
SessionAmplify.set('formatted_address', results[0].formatted_address);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
return true;
};
The problem lines are SessionAmplify.set('pos', results[0].geometry.location);
and SessionAmplify.set('formatted_address', results[0].formatted_address);
. It seems that the results
variable does not arrive in time for me to set the session variable - this is strange because that block of code should not run unless the status
variable arrives, which I would think should arrive concurrently with the results
variable.
I looked into using Meteor._wrapAsync()
(I watched the eventedmind tutorial: https://www.eventedmind.com/feed/Ww3rQrHJo8FLgK7FF), but I can't figure out how to use Meteor._wrapAsync()
with geocoder.geocode()
. One problem is that Meteor._wrapAsync()
requires the callback function to have the form function(error, result), but the geocode call back's function has the form function(result, status)
. Any advice anyone?
回答1:
Ok, that's not a Spark problem / exception. In fact your templates use some objects var that are not fully initialized. It's a really common mistakes. So in your template javascript files you have to pay attention at those object and you don't have to forget to check that they are available before using them :
if (_.contains(myObject, ['prop1', 'prop2])) {
// your function template code here
}
Another point in meteor app : usually when your app load on client you don't have recevied all datas (user is not logged per example) but your templates will be rendered once. Then, with your subscription, datas will be receveid by the client and your template will be rerendered...
I hope it will help you.
[edit] here is a sample with request :
// your npm async lib
var stdRequest = Npm.require('request');
// your anonymous func that wrap the async lib (you can do what you want here
var requestGetAsync = function(url, options, cb) {
stdRequest.get(url, options, function (err, response, body) {
cb && cb(null, response);
});
};
// the final wraping to make it sync
requestGetSync = Meteor._wrapAsync(requestGetAsync);
if you don't want to custom the async lib using a personal ano func you can just do this :
// the only wraping required
requestGetSync = Meteor._wrapAsync(request);
To use it you just have to do this :
requestGetSync(/* standard params of original func */);
回答2:
The error is not probably in Spark. I often get similar error when I add new code in Meteor app. So if I see this error in console, I try to comment new code and find the problematic line/s and try to change it.
来源:https://stackoverflow.com/questions/19754196/how-do-i-modify-spark-js-im-getting-the-following-error-exception-from-deps-r