Skip to content

Commit

Permalink
Fix transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Apr 30, 2021
1 parent 124fb35 commit 744dda5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions packages/diffhtml/lib/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function runTransitions(setName, ...args) {
return promises;
}

const [ vTree, ...rest ] = args;
const vTree = args[0];
const isElement = vTree.nodeType === NODE_TYPE.ELEMENT;

// Filter out text nodes and fragments from transition callbacks.
Expand All @@ -86,7 +86,8 @@ export function runTransitions(setName, ...args) {
// Run each transition callback, but only if the passed args are an
// Element.
set.forEach(callback => {
const retVal = callback(NodeCache.get(vTree), ...rest);
const nodes = args.map(x => NodeCache.get(x) || x);
const retVal = callback(...nodes);

// Is a `thennable` object or Native Promise.
if (typeof retVal === 'object' && retVal.then) {
Expand All @@ -98,7 +99,7 @@ export function runTransitions(setName, ...args) {
// all are run with this.
if (setName === 'attached' || setName === 'detached') {
vTree.childNodes.forEach((/** @type {VTree} */ childTree) => {
promises.push(...runTransitions(setName, childTree, ...rest));
promises.push(...runTransitions(setName, childTree, ...args.slice(1)));
});
}

Expand Down
18 changes: 9 additions & 9 deletions packages/diffhtml/test/integration/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,26 @@ describe('Integration: Transitions', function() {
equal(result.parentNode, null);
});

it.only('will provide the correct arguments to replaced', () => {
var oldElement = null;
var newElement = null;
it('will provide the correct arguments to replaced', () => {
var oldNode = null;
var newNode = null;

diff.innerHTML(this.fixture, '<div><p></p></div>');

diff.addTransitionState('replaced', (...args) => {
oldElement = args[0];
newElement = args[1];
oldNode = args[0];
newNode = args[1];
});

var p = this.fixture.querySelector('p');

diff.innerHTML(this.fixture, '<div><span></span></div>');

equal(oldElement, p);
equal(oldElement.parentNode, null);
equal(oldNode, p);
equal(oldNode.parentNode, null);

equal(newElement, this.fixture.querySelector('span'));
equal(newElement.parentNode, this.fixture.firstChild);
equal(newNode, this.fixture.querySelector('span'));
equal(newNode.parentNode, this.fixture.firstChild);
});

it('will provide the correct arguments to attributeChanged (added)', () => {
Expand Down

0 comments on commit 744dda5

Please sign in to comment.