Skip to content

Commit

Permalink
Update diffhtml package dependencies (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Mar 31, 2022
1 parent 344bbb1 commit cab7fb3
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 85 deletions.
37 changes: 21 additions & 16 deletions packages/diffhtml/lib/node/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function createNode(vTreeLike, ownerDocument = globalThis.documen
isSVG = isSVG || nodeName === 'svg';

/** @type {ValidNode | null} */
let domNode = null;
let domNodeCheck = null;

/** @type {ValidNode | null | void} */
let retVal = null;
Expand All @@ -57,21 +57,27 @@ export default function createNode(vTreeLike, ownerDocument = globalThis.documen
// Invoke all the `createNodeHook` functions passing along the vTree as the
// only argument. These functions must return a valid DOM Node value.
if (retVal = fn(vTree)) {
domNode = retVal;
domNodeCheck = retVal;
}
});

// It is not possible to continue if this object is falsy. By returning null,
// patching can gracefully no-op.
if (!ownerDocument) {
return domNode;
return domNodeCheck;
}

// If no DOM Node was provided by CreateNode hooks, we must create it
// ourselves.
if (domNode === null) {
// Create empty text elements. They will get filled in during the patch
// process.
/**
* If no DOM Node was provided by CreateNode hooks, we must create it
* ourselves.
*
* @type {ValidNode | null}
*/
let domNode = domNodeCheck;

// Create empty text elements. They will get filled in during the patch
// process.
if (!domNode) {
if (nodeName === '#text') {
domNode = ownerDocument.createTextNode(vTree.nodeValue || EMPTY.STR);
}
Expand All @@ -96,19 +102,18 @@ export default function createNode(vTreeLike, ownerDocument = globalThis.documen
}
}

/** @type {HTMLElement | DocumentFragment | Text} */
const validNode = (domNode);

// Add to the domNodes cache.
NodeCache.set(vTree, validNode);
NodeCache.set(vTree, domNode);

// Append all the children into the domNode, making sure to run them
// through this `createNode` function as well.
for (let i = 0; i < childNodes.length; i++) {
/** @type {HTMLElement | DocumentFragment | Text} */
const validChildNode = (createNode(childNodes[i], ownerDocument, isSVG));
validNode.appendChild(validChildNode);
const validChildNode = createNode(childNodes[i], ownerDocument, isSVG);

if (domNode && validChildNode) {
domNode.appendChild(validChildNode);
}
}

return validNode;
return domNode;
}
2 changes: 1 addition & 1 deletion packages/diffhtml/lib/node/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const setAttribute = (vTree, domNode, name, value) => {
const blocklistName = vTree.nodeName + '-' + lowerName;

/** @type {HTMLElement} */
const htmlElement = (domNode);
const htmlElement = /** @type {any} */ (domNode);

// Since this is a property value it gets set directly on the node.
if (allowlist.has(blocklistName)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/diffhtml/lib/tree/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function createTree(input, attributes, childNodes, ...rest) {
childNodes = [];

for (let i = 0; i < inputAsHTMLEl.childNodes.length; i++) {
/** @type {HTMLElement} */
/** @type {ValidInput} */
const childNodeElement = (inputAsHTMLEl.childNodes[i]);
childNodes.push(createTree(childNodeElement));
}
Expand Down Expand Up @@ -168,7 +168,7 @@ export default function createTree(input, attributes, childNodes, ...rest) {
attributes,
childNodes,
children,
} = (input);
} = (/** @type {any} */(input));

const treeName = rawNodeName || nodeName;

Expand Down
6 changes: 5 additions & 1 deletion packages/diffhtml/lib/util/global.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/** @type {unknown} */
/**
* @type {{
* [key: string]: any;
* }}
*/
export default typeof global === 'object' ? global : (typeof window === 'object' ? window : self) || {};
4 changes: 2 additions & 2 deletions packages/diffhtml/lib/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const VTree = EMPTY.OBJ;
* @typedef {Object} VTreeLike
* @property {any=} rawNodeName - unaltered extracted nodeName
* @property {string} nodeName - lowercased, string, nodeName, only required value
* @property {string=} nodeName - lowercased, string, nodeName, only required value
* @property {string=} elementName - lowercased, string, elementName
* @property {string=} nodeValue - defines the text value associated
* @property {number=} nodeType - the type of Node this is representing
Expand All @@ -146,7 +146,7 @@ export const VTree = EMPTY.OBJ;
export const VTreeLike = EMPTY.OBJ;

/**
* @typedef {HTMLElement | Text | Comment | DocumentFragment | Function | string | string[] | VTree | VTree[] | VTreeLike | VTreeLike[]} ValidInput
* @typedef {HTMLElement | ChildNode | Element | Text | Comment | DocumentFragment | Function | string | string[] | VTree | VTree[] | VTreeLike | VTreeLike[]} ValidInput
*/
export const ValidInput = EMPTY.OBJ;

Expand Down
28 changes: 14 additions & 14 deletions packages/diffhtml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@
"test-debug": "NODE_ENV=test mocha --inspect --debug-brk test/_setup test test/integration/*.js"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.25",
"babel-plugin-istanbul": "^6.0.0",
"@babel/cli": "^7.17.6",
"@babel/core": "^7.17.8",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.23",
"babel-plugin-istanbul": "^6.1.1",
"babel-preset-diffhtml-imports": "^1.0.0-beta.25",
"c8": "^7.11.0",
"coveralls": "^3.1.0",
"coveralls": "^3.1.1",
"extless-loader": "^1.0.0",
"jsdom": "^16.5.3",
"jsdom": "^19.0.0",
"mocha": "^9.2.2",
"rollup": "^1.21.4",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-hypothetical": "^2.1.0",
"rollup": "^2.70.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-hypothetical": "^2.1.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-visualizer": "^2.6.0",
"rollup-plugin-visualizer": "^5.6.0",
"rollup-watch": "^4.3.1",
"sinon": "^9.2.3",
"typescript": "4.1.3",
"sinon": "^13.0.1",
"typescript": "^4.6.3",
"uglify-js": "backports"
}
}
66 changes: 34 additions & 32 deletions packages/diffhtml/rollup.lite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,40 @@ const dests = {
umd: 'dist/diffhtml-lite.js',
}

export const input = entries[NODE_ENV];
export const context = 'this';
export default {
input: entries[NODE_ENV],
context: 'this',

export const output = [{
file: dests[NODE_ENV],
format: 'umd',
exports: 'named',
name: 'diff',
sourcemap: false,
}];
output: [{
file: dests[NODE_ENV],
format: 'umd',
exports: 'named',
name: 'diff',
sourcemap: false,
}],

export const plugins = [
replace({
'process.env.NODE_ENV': stringify('production')
}),
babel({ comments: false }),
nodeResolve({ mainFields: ['module'] }),
hypothetical({
allowFallthrough: true,
files: {
'./lib/util/performance.js': `
export default () => () => {};
`,
plugins: [
replace({
'process.env.NODE_ENV': stringify('production')
}),
babel({ comments: false }),
nodeResolve({ mainFields: ['module'] }),
hypothetical({
allowFallthrough: true,
files: {
'./lib/util/performance.js': `
export default () => () => {};
`,

'./lib/util/process.js': `
export default {
env: { NODE_ENV: 'production' },
};
`,
}
}),
NODE_ENV === 'umd' && Visualizer({
filename: './dist/lite-build-size.html'
}),
];
'./lib/util/process.js': `
export default {
env: { NODE_ENV: 'production' },
};
`,
}
}),
NODE_ENV === 'umd' && Visualizer({
filename: './dist/lite-build-size.html'
}),
],
};
34 changes: 17 additions & 17 deletions packages/diffhtml/rollup.main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ const dests = {

const { NODE_ENV = 'umd' } = process.env;

export const input = entries[NODE_ENV];
export const context = 'this';

export const output = [{
file: dests[NODE_ENV],
format: 'umd',
exports: 'named',
name: 'diff',
sourcemap: false,
}];

export const plugins = [
NODE_ENV === 'min' && replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
babel({ comments: false }),
nodeResolve({ mainFields: ['module'] }),
NODE_ENV === 'umd' && Visualizer({ filename: './dist/main-build-size.html' }),
];
export default {
input: entries[NODE_ENV],
context: 'this',
output: [{
file: dests[NODE_ENV],
format: 'umd',
exports: 'named',
name: 'diff',
sourcemap: false,
}],
plugins: [
NODE_ENV === 'min' && replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
babel({ comments: false }),
nodeResolve({ mainFields: ['module'] }),
NODE_ENV === 'umd' && Visualizer({ filename: './dist/main-build-size.html' }),
],
};

0 comments on commit cab7fb3

Please sign in to comment.