Hey Ya'll, loooong day here, I'm fried. I have an ...
# suitecommerce
c
Hey Ya'll, loooong day here, I'm fried. I have an extension that keeps firing the
initialize
method twice. I'm sure it's something dumb I've done but I can't see it. Has anyone listening banged their head on this one and remember what it was?
c
@Chris If your view is a child view, then the child view's
initialize
method will re-run whenever the parent view renders. The only way to solve is to cache the child view instance (within the
childViews
object in the parent view) rather than instantiating a new child view instance every time. For example, in the parent view, change this:
Copy code
childViews: {
  'My.Child': function() {
    return new MyChildView();
  }
}
To something like this:
Copy code
initialize: function () {
  this.myChildView = new MyChildView();
},
childViews: {
  'My.Child': function() {
    return this.myChildView;
  }
}
As a reference, the ListHeader view is often implemented in this way, if you look for usages of that throughout SCA core.
1000 1
👍🏻 1
🙏🏻 1
c
@Caleb Evans Thanks, checking on this now.