refactor(core): add render
This commit is contained in:
parent
aad62b65f5
commit
8bee8f0213
20 changed files with 232 additions and 102 deletions
41
src/core/util/dom.js
Normal file
41
src/core/util/dom.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { isFn } from '../util/core'
|
||||
|
||||
const cacheNode = {}
|
||||
|
||||
/**
|
||||
* Get Node
|
||||
* @param {String|Element} el
|
||||
* @param {Boolean} noCache
|
||||
* @return {Element}
|
||||
*/
|
||||
export function getNode (el, noCache = false) {
|
||||
if (typeof el === 'string') {
|
||||
el = noCache ? dom.find(el) : (cacheNode[el] || dom.find(el))
|
||||
}
|
||||
|
||||
return el
|
||||
}
|
||||
|
||||
export const dom = {
|
||||
body: document.body,
|
||||
head: document.head,
|
||||
find: node => document.querySelector(node),
|
||||
findAll: node => document.querySelectorAll(node),
|
||||
create: (node, tpl) => {
|
||||
node = document.createElement(node)
|
||||
if (tpl) node.innerHTML = tpl
|
||||
},
|
||||
appendTo: (target, el) => target.appendChild(el)
|
||||
}
|
||||
|
||||
export function on (el, type, handler) {
|
||||
isFn(type)
|
||||
? window.addEventListener(el, type)
|
||||
: el.addEventListener(type, handler)
|
||||
}
|
||||
|
||||
export const off = function on (el, type, handler) {
|
||||
isFn(type)
|
||||
? window.removeEventListener(el, type)
|
||||
: el.removeEventListener(type, handler)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue