Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Using ts-ignore to avoid escaping expando properties.
Browse files Browse the repository at this point in the history
1. Switched to using // @ts-ignore in code. This turns off type checking for that line of code.
2. Using this to avoid having to write element['mounted'].
3. Alternative:
// @ts-ignore
element.mounted
  • Loading branch information
Wobbabits committed Jun 19, 2018
1 parent f255263 commit 6eedde7
Showing 7 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/composi.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/mount.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@ export const mount = (tag, container, elementToHydrate) => {
if (tag.props && tag.props.onComponentDidMount) {
tag.props.onComponentDidMount.call(tag.props.onComponentDidMount, element)
}
element['mounted'] = true
// @ts-ignore
element.mounted = true
if (elementToHydrate) {
if (typeof elementToHydrate === 'string') {
elementToHydrate = document.querySelector(elementToHydrate)
7 changes: 4 additions & 3 deletions lib/patch.js
Original file line number Diff line number Diff line change
@@ -8,12 +8,13 @@ import { patchElement } from './utils/patchElement'
*/
export function patch(node, element) {
if (element) {
patchElement(element.parentNode, element, element && element['vnode'], node)
// @ts-ignore
patchElement(element.parentNode, element, element && element.vnode, node)
} else {
element = patchElement(null, null, null, node)
}

element['vnode'] = node
// @ts-ignore
element.vnode = node

return element
}
9 changes: 4 additions & 5 deletions lib/utils/patchElementHelpers/removeChildren.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/**
* @description A function to remove the children of a node.
* @param {Node} element The parent of the node whose children will be removed.
* @namespace {Node} node The node whose children will be removed.
* @property {Object} node.props
* @param {Node} node The node whose children will be removed.
* @returns {Node} element The parent of the removed nodes.
*/
export function removeChildren(element, node) {
const props = node.props
const props = node['props']
if (props) {
for (let i = 0; i < node.children.length; i++) {
removeChildren(element.childNodes[i], node.children[i])
for (let i = 0; i < /** @type {Element} */ (node).children.length; i++) {
removeChildren(element.childNodes[i], /** @type {Element} */ (node).children[i])
}
}
return element
3 changes: 2 additions & 1 deletion lib/utils/patchElementHelpers/updateElement.js
Original file line number Diff line number Diff line change
@@ -19,8 +19,9 @@ export function updateElement(element, oldProps, props, isSVG) {
setProp(element, prop, props[prop], oldProps[prop], isSVG)
}
}
// @ts-ignore
// Handle lifecycle hook:
if (element['mounted'] && props && props.onComponentDidUpdate) {
if (element.mounted && props && props.onComponentDidUpdate) {
props.onComponentDidUpdate.call(
props.onComponentDidUpdate,
oldProps,
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composi",
"version": "2.4.8",
"version": "2.4.9",
"description": "A JavaScript library for creating websites, PWAs and hybrid apps.",
"main": "index.js",
"scripts": {

0 comments on commit 6eedde7

Please sign in to comment.