Ractive.js 模式间接观察者报告相同的值

Ractive.js Pattern Indirect Observer Reports Same Value

我使用 Ractive.js 来绑定一个 javascript 对象和一个 HTML 表单。我的对象看起来像这样:

entity: {
  id: 'some id'
  type: 'a type'
  names: [
     {
       locale: 'en',
       name: 'some name'
     },
     {
       locale: 'tr',
       name: 'some translation'
     }
  ]
}

我想订阅名称更新。我通过以下方式注册更新:

ractive.observe({
  // indirect observer
  'entity': function(newValue, oldValue, key) {
    console.log(key + ' is changed from ' + oldValue + ' to ' + newValue);
  },
  // direct observer
  'entity.names.*': function(newValue, oldValue, key, index) { 
     console.log(key + ' is changed from ' + oldValue + ' to ' + newValue + ' and index is ' + index);
  }
}

然而,oldValuenewValue 对于上面的两个观察者来说总是相同的(等于观察模式的最新值)。

根据他们的 documentation,这种行为对于直接观察者来说是预期的。但是,间接观察者应该提供不同的值。

对于行 26482743 上的 v0.7.3,值被复制到模式观察器中。但是,该副本是浅副本。因此,如果更新实际值,则更新观察者中的值,即使我们期望模式观察者在更新之前保持值。

可以找到关于此的更多讨论 here