forked from Singtaa/onejs-preact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
29 lines (25 loc) · 911 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { EMPTY_ARR } from './constants';
export const isArray = Array.isArray;
/**
* Assign properties from `props` to `obj`
* @template O, P The obj and props types
* @param {O} obj The object to copy properties to
* @param {P} props The object to copy properties from
* @returns {O & P}
*/
export function assign(obj, props) {
// @ts-expect-error We change the type of `obj` to be `O & P`
for (let i in props) obj[i] = props[i];
return /** @type {O & P} */ (obj);
}
/**
* Remove a child node from its parent if attached. This is a workaround for
* IE11 which doesn't support `Element.prototype.remove()`. Using this function
* is smaller than including a dedicated polyfill.
* @param {preact.ContainerNode} node The node to remove
*/
export function removeNode(node) {
let parentNode = node.parentNode;
if (parentNode) parentNode.removeChild(node);
}
export const slice = EMPTY_ARR.slice;