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

Commit 4776f42

Browse files
Robert BiggsRobert Biggs
Robert Biggs
authored and
Robert Biggs
committed
Renamed testIfVNodesDiffer to isSameNode.
1. Renamed testIfVNodesDiffer to isSameNode. Easier to say and write. 2. Updated JSDoc comments for h. 3. Updated JSDoc comments for Fragment.
1 parent 97982c5 commit 4776f42

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

dist/composi.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/component.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { patch } from './patch'
22
import { mixin } from './utils/mixin'
33
import { rAF } from './utils/rAF'
4-
import { testIfVNodesDiffer } from './utils/testIfVNodesDiffer'
4+
import { isSameNode } from './utils/isSameNode'
55

66
/**
77
* @description This is a Time Object used as a key to create a pseudo-private property in the Component class for holding state.
@@ -241,7 +241,7 @@ export class Component {
241241
* @method Function to render component after data changes.
242242
* If data is passed as argument, it will be used.
243243
* Otherwise state will be used.
244-
* @param {boolean | number | string | Object | any[]} [data]
244+
* @param {boolean | number | string | Object | any[]} [data] By default, data will be the component's current state, otherwise, if data is provided as an argument, that will be used, overriding the state.
245245
* @returns {void} undefined
246246
*/
247247
update(data) {
@@ -279,7 +279,7 @@ export class Component {
279279
elem.parentNode.removeChild(elem)
280280
}
281281

282-
// Capture old node to use with testIfVNodesDiffer if component has already mounted:
282+
// Capture old node to use with isSameNode if component has already mounted:
283283
const __oldNode = this.element && this.element.node
284284

285285
/**
@@ -299,7 +299,7 @@ export class Component {
299299
return
300300
}
301301

302-
if (testIfVNodesDiffer(__oldNode, __data, this)) {
302+
if (isSameNode(__oldNode, __data, this)) {
303303
this.componentWillUpdate && this.componentWillUpdate(this)
304304
this.componentDidUpdate && this.componentDidUpdate(this)
305305
}

lib/fragment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* h('li', {}, 'B'),
1313
* h('li', {}, 'C')
1414
* ])
15-
* @param {null | Object} props When using Fragment as a function, props is the first argument. Provide either null or {} as the value for props.
16-
* @param {any[]} children The siblings to return with the Fragment. This will be an array of sibling elements.
15+
* @param {{}} [props] When using Fragment as a function, props is the first argument. Provide either null or {} as the value for props.
16+
* @param {any[]} [children] The siblings to return with the Fragment. This will be an array of sibling elements.
1717
* @returns {Object[]} An array of virtual nodes.
1818
*/
1919
export const Fragment = (props, children) => children

lib/h.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
/**
2+
* @description A virtual node defining a node to be created. This gets returns by the h function.
3+
* @typedef {Object} VNode
4+
* @prop {string} type The node to create, such as "h1", "p", "div", etc.
5+
* @prop {Object} [props] An object of key/value pairs defining properties and values for the node. These include properties such as "class", "id", "disabled", etc.
6+
* @prop {any[] | null} [children] An array of children belonging to the node.
7+
* @prop {string | number | undefined} [key] A unique key to identify a node.
8+
*/
19
/**
210
* @description Hyperscript function. Enables definition of HTML/SVG using functions.
311
* @param {string | Function} type The name of the HTML or SVG tag to create or a function using an HTML tag name.
412
* @param {Object} [props] An object of property/value pairs.
513
* @param {any[]} [children] Any child elements.
6-
* @returns {Object} A virtual node describing an element.
14+
* @returns {VNode} A virtual node describing an element.
715
* @example Virtual node with string as content:
816
* const title = h('h1', {class: 'main-title'}, 'This is the Titel!')
917
* @example Virtual node with children:

lib/utils/testIfVNodesDiffer.js renamed to lib/utils/isSameNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @param {*} data Data to be used when rendering a new virtual node for a component.
55
* @param {Object} component A reference to the component being used.
66
*/
7-
export function testIfVNodesDiffer(oldNode, data, component) {
7+
export function isSameNode(oldNode, data, component) {
88
if (
99
component &&
1010
JSON.stringify(oldNode) === JSON.stringify(component.render(data))

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "composi",
3-
"version": "2.3.3",
3+
"version": "2.3.4",
44
"description": "A JavaScript library for creating websites, PWAs and hybrid apps.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)