Here is a
situation:
I have 3 classes: a collection of Name instances which are nested into PaymentMethod
which is a property of Invoice.
I create some instances of Name, put them into PaymentMethod, than assign PaymentMethod to Invoice.
Then I render a view with an Invoice instance. It renders without any problems. Then I set Invoice.PaymentMethod to null the view is re-rendered without any problems (and PaymentMethod disappears from the screen).
But when I assign PaymentMethod instance back to Invoice, an error is thrown:
TypeError: this.anchor.parentNode is null
return this.anchor.parentNode.removeChild(this.anchor);
It occurs in DynamicNode.prototype.remove()
Here is full code:
var Invoice = Serenade.Model.extend('Invoice');
Invoice.property('paymentMethod');
var PaymentMethod = Serenade.Model.extend('PaymentMethod');
PaymentMethod.property('type');
PaymentMethod.hasMany('names', {
as: function() { return Name}
});
var Name = Serenade.Model.extend('Name');
Name.property('value');
var myInvoice = new Invoice();
var myPaymentMethod = new PaymentMethod({type:'transfer'});
var name1 = new Name({value:'Citibank '});
var name2 = new Name({value:'New York Branch'});
myPaymentMethod.names.push(name1);
myPaymentMethod.names.push(name2);
myInvoice.paymentMethod = myPaymentMethod;
Serenade.view('myView', '\
div\n\
p "Payment instructions: "\n\
- in @paymentMethod\n\
span @type\n\
');
Serenade.view('myViewCollection', '\
div\n\
p "Payment instructions: "\n\
- in @paymentMethod\n\
- collection @names\n\
span @value\n\
');
var view1 = Serenade.render('myView',myInvoice);
var view2 = Serenade.render('myViewCollection',myInvoice);
window.onload = function(){
document.body.appendChild(view1);
document.body.appendChild(view2);
}
After it is loaded, I run 2 commands from the console, the second command throws an error.
myInvoice.paymentMethod = null
myInvoice.paymentMethod = myPaymentMethod
Note that there are 2 views, one of which doesn't - collection, it gives no errors, and the other one is with a collection, this is the one that errors.
As a workaround I just added a condition to check if this.anchor.parentNode is not null to Serenade.js
Please, advise.