aurelia / templating-resources

A standard set of behaviors, converters and other resources for use with the Aurelia templating library.
MIT License
59 stars 55 forks source link

Fix/repeat one time #357

Open rluba opened 6 years ago

rluba commented 6 years ago

This is a crude attempt at fixing #356.

The fix for the if case was relatively straight-forward. But to disable the fast-pass for the "subview without lifecycle methods" case, I had to rely on instruction.initiatedByBehavior, because I couldn't find a better indicator.

I just started working with Aurelia a few weeks ago, so I’m sure there’s a more elegant way that I couldn’t discover. Let me know what you think!

bigopon commented 6 years ago

@rluba @EisenbergEffect

I think all the changes are good except using initiatedByBehavior. By default checking that will also make it false positive for any custom element / custom attribute that doesn't actually require lifecycle. I think we have to introduce new property on If metadata via:

const meta = metada.get(metdata.resource, If);
meta.behaviorRequiresLifecycle = true;

and check:

function behaviorRequiresLifecycle(instruction) {
  let t = instruction.type;
  let name = t.elementName !== null ? t.elementName : t.attributeName;
  return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind)
    || t.viewFactory && viewsRequireLifecycle(t.viewFactory)
    || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory)
    || instruction.type.behaviorRequiresLifecycle;
}

Note: naming is for discussion.