WIP: Implement multiple <AnimatedOrphans/> support#174
WIP: Implement multiple <AnimatedOrphans/> support#174nickschot wants to merge 11 commits intoember-animation:masterfrom
Conversation
|
@ef4 please let me know if this is what you had in mind or if changes are necessary. I'll update docs & tests if the concept is approved! As the entire component was moved I'll also place some pointers of what has changed in the (old) |
| if(!this.parent) { | ||
| throw new Error(`{{-animated-orphans}} cannot be used directly, use {{animated-orphans}} instead.`); | ||
| } |
There was a problem hiding this comment.
Check if a parent was passed (no validity check (yet?)).
| const _removedSprites = removedSprites.filter(s => { | ||
| let closestAnimatedOrphans; | ||
|
|
||
| // find closest ancestor <AnimatedOrphans/> that is not in the process of being destroyed | ||
| for(let ancestorComponent of ancestorsOf(animatorComponent)) { | ||
| if (ancestorComponent.isEmberAnimatedOrphans && !ancestorComponent._isDestroying) { | ||
| closestAnimatedOrphans = ancestorComponent; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return closestAnimatedOrphans === this.parent; | ||
| }); |
There was a problem hiding this comment.
Finds the removedSprites of which this AnimatedOrphans is the closest ancestor
| if(_removedSprites.length){ | ||
| this._newOrphanTransitions.push({ | ||
| removedSprites: _removedSprites.map(sprite => { | ||
| // we clone the owner objects so that our sprite garbage | ||
| // collection is entirely detached from the original | ||
| // animator's | ||
| sprite.owner = sprite.owner.clone(); | ||
| sprite.owner.flagForRemoval(); | ||
| return sprite; | ||
| }), | ||
| transition, | ||
| duration, | ||
| shouldAnimateRemoved | ||
| }); | ||
| this.reanimate(); | ||
| } |
There was a problem hiding this comment.
Only reanimate if any removedSprites were found for this AnimatedOrphans
| function * ancestorsOf(component) { | ||
| let pointer = component.parentView; | ||
| while (pointer) { | ||
| yield pointer; | ||
| pointer = pointer.parentView; | ||
| } | ||
| } |
There was a problem hiding this comment.
This is copied over from the motion service, might want to extract or export & reuse.
|
Thanks, this is looking good. I think you're right to split this into two components. The inner one wants to be able to manually append DOM nodes to its element, which means we don't really want any other glimmer-managed content in there.
I agree, I think that matching can happen in the motion service.
Yes, and it's also possibly using private API, so it probably belongs in https://github.com/ember-animation/ember-animated/blob/98b32fa004ce13390429bd55679ebb7838102f89/addon/-private/ember-internals.js |
|
One other API-design issue: since
|
Which |
|
Oh yes, you're right. I was thinking of |
|
I wonder if The original name worked because you were just making a place for animated orphans to render. But now you're also expressing something more. |
For the matching to happen there we do also need to keep track of the AnimatedOrphans instances (currently its just the callbacks). |
|
Also, currently there is no way to do this (which happens frequently in tests):
Should we provide a way to pass on styles to |
|
Ah, so yeah, this is kinda what I meant about letting people set their own tag and attributes. And I can see how it's confusing. Maybe we should just make the outer component have the Element, and then it does wrap the user's content, and then it behaves more like how it looks in the template. Angle bracket invocations that don't actually generate any DOM (or in this case, that generate DOM with a different structure than they look like) feel a bit weird to me. For that reason I've tried to favor curlies for DOM-less things like |
|
Hi all. Are there any new thoughts/happenings around this feature? |
|
@kturney I unfortunately did not have the time to finalize this PR yet. I will take a look at updating the branch to master later today. |
…rphans # Conflicts: # addon/-private/ember-internals.ts # addon/components/animated-each.ts # addon/components/animated-orphans.ts # addon/services/motion.ts
|
I've updated this branch to work with master again (& TS), not made any other changes yet. |
I'm working on an implementation for this now. We can brainstorm a new name once we're happy with implementation. |
|
So working on this I ran into a couple of things:
@ef4 any thoughts/ideas? |
This implements #169
In the current implementation it is necessary for every
<AnimatedOrphans/>to be a block component as animators will only check against ancestor<AnimatedOrphans/>.The "original" component is now situated in
{{-animated-orphans}}and a new top level<AnimatedOrphans/>component has been added (with minimal functionality of its own). Trying to make the original component into a block one resulted in at least some margin collapse issues.In the current implementation the
{{-animated-orphans}}component will check if it is the closest ancestor of the removed component. It might be better to do this in thematchDestroyedfunction in the motion service.