1 | /**
|
2 | * Namespace for SVG elements with `xlink:href` attributes.
|
3 | * @type {string}
|
4 | */
|
5 | export const XLINK_NS = 'http://www.w3.org/1999/xlink'
|
6 |
|
7 | /**
|
8 | * Namespace for SVG elements.
|
9 | * @type {string}
|
10 | */
|
11 | export const SVG_NS = 'http://www.w3.org/2000/svg'
|
12 |
|
13 | /**
|
14 | * An empty object. Used as placeholder for `props` in VNode.
|
15 | * @type {{}} EMPTY_OBJECT
|
16 | */
|
17 | export const EMPTY_OBJECT = {}
|
18 |
|
19 | /**
|
20 | * Combine two objects, merging the second into the first. Any properties already existing in the first will be replaced by those of the second. Any properties in the second not in the first will be added to it.
|
21 | * @param {Object.<string, any>} firstObject
|
22 | * @param {Object.<string, any>} secondObject
|
23 | * @return {Object.<string, any>} target
|
24 | */
|
25 | export function mixin(firstObject, secondObject) {
|
26 | const target = {}
|
27 |
|
28 | for (let i in firstObject) target[i] = firstObject[i]
|
29 | for (let j in secondObject) target[j] = secondObject[j]
|
30 |
|
31 | return target
|
32 | }
|
33 |
|
34 | /**
|
35 | * A function to test where something is an object literal or not. Used by Component setState.
|
36 | * @param {Object.<string, any>} obj An object literal to test.
|
37 | * @return {boolean} boolean
|
38 | */
|
39 | export function isObject(obj) {
|
40 | if (Array.isArray(obj)) return false
|
41 | else if (typeof obj === 'object') return true
|
42 | return false
|
43 | }
|
44 |
|
45 | /**
|
46 | * @typedef {import('./vnode').VNode} VNode
|
47 | * @typedef {import('./component').Component} Component
|
48 | */
|
49 | /**
|
50 | * A function to test whether the data provided for updating a component creates a new virtual node or not.
|
51 | * @param {VNode} oldNode The previous virtual node of a component.
|
52 | * @param {*} data Data to be used when rendering a new virtual node for a component.
|
53 | * @param {Component} component A reference to the component being used.
|
54 | * @return {boolean} boolean
|
55 | */
|
56 | export function isSameNode(oldNode, data, component) {
|
57 | if (
|
58 | component &&
|
59 | JSON.stringify(oldNode) === JSON.stringify(component.render(data))
|
60 | ) {
|
61 | return true
|
62 | }
|
63 | return false
|
64 | }
|
65 |
|
66 | /**
|
67 | * Class to throw error message when attempting to insert Fragement tag directly into DOM.
|
68 | * @return {string} message
|
69 | */
|
70 | export class FragmentError {
|
71 | constructor() {
|
72 | this.message = 'Cannot insert Fragment tag directly into DOM.'
|
73 | this.toString = function() {
|
74 | return this.message
|
75 | }
|
76 | }
|
77 | }
|