From 744dda5f3b6cabbd86afbd04f34ee545e85fa0da Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Fri, 30 Apr 2021 15:05:09 -0700 Subject: [PATCH] Fix transitions --- packages/diffhtml/lib/transition.js | 7 ++++--- .../diffhtml/test/integration/transitions.js | 18 +++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/diffhtml/lib/transition.js b/packages/diffhtml/lib/transition.js index 7f9656a3..03fae168 100644 --- a/packages/diffhtml/lib/transition.js +++ b/packages/diffhtml/lib/transition.js @@ -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. @@ -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) { @@ -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))); }); } diff --git a/packages/diffhtml/test/integration/transitions.js b/packages/diffhtml/test/integration/transitions.js index 701494a5..3bc2772e 100644 --- a/packages/diffhtml/test/integration/transitions.js +++ b/packages/diffhtml/test/integration/transitions.js @@ -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, '

'); 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, '
'); - 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)', () => {