Skip to content

Commit

Permalink
save bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jun 28, 2023
1 parent e65cc81 commit 9422802
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function renderComponent(component) {
parentDom = component._parentDom;

if (parentDom) {
let commitQueue = [];
let refQueue = [];
let commitQueue = [],
refQueue = [];
const oldVNode = assign({}, vnode);
oldVNode._original = vnode._original + 1;

Expand Down
16 changes: 7 additions & 9 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ export function diffChildren(
newDom = childVNode._dom;

if ((j = childVNode.ref) && oldVNode.ref != j) {
if (!refs) refs = [];
if (oldVNode.ref) refs.push(oldVNode.ref, null, childVNode);
refs.push(j, childVNode._component || newDom, childVNode);
if (oldVNode.ref) {
if (!refs) refs = [];
refs.push(oldVNode.ref, null, childVNode);
}
refQueue.push(j, childVNode._component || newDom, childVNode);
}

if (newDom != null) {
Expand Down Expand Up @@ -248,12 +250,8 @@ export function diffChildren(

// Set refs only after unmount
if (refs) {
for (let i = 0; i < refs.length; i++) {
if (refs[i + 1]) {
refQueue.push(refs[i], refs[++i], refs[++i]);
} else {
applyRef(refs[i], refs[++i], refs[++i]);
}
for (i = 0; i < refs.length; i++) {
applyRef(refs[i], refs[++i], refs[++i]);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ export function unmount(vnode, parentVNode, skipRemove) {

if ((r = vnode.ref)) {
if (!r.current || r.current === vnode._dom) {
console.log('applying', r, 'null');
applyRef(r, null, parentVNode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export function render(vnode, parentDom, replaceNode) {
createElement(Fragment, null, [vnode]);

// List of effects that need to be called after diffing.
let commitQueue = [];
let refQueue = [];
let commitQueue = [],
refQueue = [];
diff(
parentDom,
// Determine the new vnode tree and store it on the DOM element on
Expand Down
4 changes: 2 additions & 2 deletions test/browser/refs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ describe('refs', () => {
rerender();
expect(calls).to.deep.equal([
'removing ref from two',
'adding ref to one',
'adding ref to two',
'adding ref to three',
'adding ref to one'
'adding ref to three'
]);
});
});

0 comments on commit 9422802

Please sign in to comment.