-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(compile): post-t'clusion linking now optional #7271
base: master
Are you sure you want to change the base?
Conversation
Can be controlled by returning an object with `{alreadyLinked: true}` from $transclude.
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Updated my comment with the issue template. Also, the Travis build failed for a seemingly unrelated reason. Should I/Can I re-run it? |
@Wizek before you put any more work on this, it is my understating that there will be no features/refactors done to |
well, actually, I do want to spend time fixing bugs in the compiler, that's one of the most fun things working on angular! haha. |
@caitp fixing bugs is ok, but I do not think this is a bug |
@Wizek I understand this, but changing this behavior has side-effects. E.g. right now it is possible to do transclude(function(clone) {
element.append(clone.content());
clone.removeData();
}); how does this change affect this? |
It's more this:
More possible regressions -> more fun to be had! So long as they don't just get reverted, hah. I think some variation of this would actually be benefitial to the framework, however I'm not too keen on the current implementation. Basically if the collection passed to the attach function changes, that collection is what should be linked. But the point about possible regressions is sensible, even though I have fun fixing them, we do want to try to minimize them, and it would be a shame to merge a fix like this and have it reverted =( |
@lgalfaso What kind of attached data are you removing with Also, this change doesn't affect what is being passed into the function that you pass into $transclude, so whatever .data() might be attached would be there all the same, no? |
@Wizek |
@caitp Just to brainstorm a little: While usually you'd want to transclude elements as children, it is in theory possible to transclude them into an entirely different place, e.g. as children to body, right? Because if that is the case, those exotic cases are best handled by the implementer, and not trying to guess them in the framework, right? Another idea I had, you may like this better: What if instead of the boolean the user could return an element which is to be linked further? Allows very similar level of control, a little bit less, though. @@ -859,8 +859,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
}
- if (cloneConnectFn) cloneConnectFn($linkNode, scope);
- if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode);
+ var overrides = {};
+ if (cloneConnectFn) {
+ angular.extend(overrides, cloneConnectFn($linkNode, scope));
+ }
+ if (compositeLinkFn) {
+ var node = overrides.transcludedElement || $linkNode;
+ compositeLinkFn(scope, node, node);
+ }
return $linkNode;
};
} |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
Came across this issue via codetriage.com. I am not familiar with the transclude functionality so just checking in if this change is still valid given there has not been any activity on it and #7270 for the past few months? |
@VegaFromLyra AFAIK it is still relevant. |
Request Type: feature
How to reproduce:
Component(s): $compile
Impact: small
Complexity: small
This issue is related to:
Detailed Description:
Can be controlled by returning an object with
{alreadyLinked: true}
from $transclude.
Can you come up with a better name than
alreadyLinked
?Related to #7270: While not a complete (automatic) solution to that issue, with this new feature the bug can at least be avoided.
Also, this is meant to be an advanced feature for those who want to do some more ninja-esqe stuff with transclusion. It is not meant to be used regularly or by novices who are new to $compile.
Other Comments: