【问题标题】:How do I modify spark.js? I'm getting the following error: Exception from Deps recompute: TypeError: Cannot read property 'nodeName' of null如何修改 spark.js?我收到以下错误:Deps 重新计算异常:TypeError:无法读取 null 的属性“nodeName”
【发布时间】:2014-08-16 20:25:52
【问题描述】:

更新:问题不在于火花 - 尽管我误解了正在发生的事情,因此问题的形成有些不正确,但我将这个问题留在了以防万一它有利于其他人。

我收到以下错误:

Exception from Deps recompute: TypeError: Cannot read property 'nodeName' of null
at Patcher.match (http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:1540:12)

当我点击第二行的链接时,它会将我引导到 spark.js 的以下部分,其中错误是:

// 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
}          

违规行是这一行:if (a.nodeName !== b.nodeName)。我想调试这个...如何修改 spark.js 文件?我想像console.log(a)一样输入语句,并想检查ab是否具有属性nodeName

StackOverflow 上与此相关的问题是:

How to investigate "Exception form Deps recompute" what are the clues?

How can I modify the Meteor (meteorite) that is running?

第一个没有真正回答。第二个包括有关如何将包添加到流星以便您可以修改它的建议。但这对我不起作用 - 我的修改要么没有显示(如果我遵循上面链接 #2 中的建议),要么生成了一个错误,说流星找不到 spark.js(如果我试图修改 spark在 ~/.meteor/ 或我的项目的 .meteor/ 目录中的包文件夹的客户端文件夹中的 .js 文件。

有人对我如何修改我的流星项目的 spark.js 文件(客户端版本)有任何建议吗?

谢谢!

2013 年 11 月 9 日更新:

我收到这些错误的原因是因为我试图将异步调用谷歌地图 geocoder.geocode() 对象/方法的结果存储在反应会话变量中:

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;
};

问题行是SessionAmplify.set('pos', results[0].geometry.location);SessionAmplify.set('formatted_address', results[0].formatted_address);。似乎results 变量没有及时到达让我设置会话变量-这很奇怪,因为除非status 变量到达,否则该代码块不应运行,我认为它应该与@ 同时到达987654337@变量。

我研究过使用Meteor._wrapAsync()(我观看了eventedmind 教程:https://www.eventedmind.com/feed/Ww3rQrHJo8FLgK7FF),但我不知道如何将Meteor._wrapAsync()geocoder.geocode() 一起使用。一个问题是Meteor._wrapAsync() 要求回调函数具有形式函数(错误,结果),但地理编码回调的函数具有形式function(result, status)。有什么建议吗?

【问题讨论】:

标签: meteor


【解决方案1】:

好的,这不是 Spark 问题/异常。事实上,您的模板使用了一些未完全初始化的对象 var。这是一个非常常见的错误。因此,在您的模板 javascript 文件中,您必须注意这些对象,并且您不必忘记在使用它们之前检查它们是否可用:

if (_.contains(myObject, ['prop1', 'prop2])) {
    // your function template code here
}

meteor 应用程序的另一点:通常当您的应用程序加载到客户端时,您还没有收到所有数据(每个示例都没有记录用户),但您的模板将被渲染一次。然后,通过您的订阅,客户端将接收数据,并且您的模板将被重新呈现...

希望对你有帮助。

[编辑] 这是一个带有请求的示例:

  // 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);

如果您不想使用个人 ano func 自定义异步库,您可以这样做:

  // the only wraping required
  requestGetSync = Meteor._wrapAsync(request);

要使用它,您只需这样做:

  requestGetSync(/* standard params of original func */);

【讨论】:

  • 你好@Rebelon,谢谢。经过大量调查,事实证明您是对的,尽管事情更复杂。我正在调用 Google Maps API,这些调用是异步的。因此,代码在代码所依赖的谷歌地图数据到达之前执行。我不知道如何解决这个问题,所以我想我现在只尝试在 Django python 中构建这个站点,然后当我更擅长使用 Meteor 时重新使用它。谢谢!
  • 也许你可以使用 Meteor._wrapAsync(yourFuncHere)。它是非官方的,但它解释了如何使用它。我没有在客户端使用它,但在服务器端我用它来包装一些异步功能。它可能会解决您的问题。
  • @Rebelon,非常感谢。我研究过使用Meteor._wrapAsync()。我已经编辑了上面的问题,以提供有关我的申请的更多详细信息。您能否建议我如何将Meteor._wrapAsync() 与 geocoder.geocode() 一起使用?
【解决方案2】:

错误可能不在 Spark 中。当我在 Meteor 应用程序中添加新代码时,我经常会遇到类似的错误。因此,如果我在控制台中看到此错误,我会尝试注释新代码并找到有问题的行并尝试更改它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多