From 0b17fc658057dbc4be7e0bd5f652cb5c3adec993 Mon Sep 17 00:00:00 2001 From: hhh <1340545944@qq.com> Date: Tue, 22 Jan 2019 20:02:18 +0800 Subject: [PATCH] improve some internals --- src/core/HNode.ts | 8 ++++---- src/ext/Fragment.ts | 1 - src/ext/Portal.ts | 2 +- src/utils/refCache.ts | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/HNode.ts b/src/core/HNode.ts index 33f5322..b3f9085 100644 --- a/src/core/HNode.ts +++ b/src/core/HNode.ts @@ -1,5 +1,5 @@ import { Store, createStore, HandlerMap, PartialHandlers } from "./Store"; -import { _document, _isArray, _Infinity, _Map, _entries } from "../utils/refCache"; +import { _document, _isArray, _Infinity, _Map, _entries, _createTextNode } from "../utils/refCache"; import { toArr, isHNode } from "../utils/helpers"; import { handleProp } from "./handleProp"; import { handleError } from "./handleError"; @@ -54,9 +54,9 @@ export const toNodeArr = function toNodes( const srcType = typeof src; if (srcType === 'string') { - return [_document.createTextNode(src as string)]; + return [_createTextNode(src as string)]; } else if (srcType === 'number') { - return [_document.createTextNode(String(src))]; + return [_createTextNode(String(src))]; } if (src) { @@ -135,6 +135,6 @@ export const toNodeArr = function toNodes( } - return [_document.createTextNode('')]; + return [_createTextNode('')]; }; diff --git a/src/ext/Fragment.ts b/src/ext/Fragment.ts index 2d20847..635e49a 100644 --- a/src/ext/Fragment.ts +++ b/src/ext/Fragment.ts @@ -1,5 +1,4 @@ import { define } from "../core/registry"; -import { _document, _Symbol } from "../utils/refCache"; export interface FragmentProps { children: unknown; diff --git a/src/ext/Portal.ts b/src/ext/Portal.ts index 3504ef8..19d24b5 100644 --- a/src/ext/Portal.ts +++ b/src/ext/Portal.ts @@ -1,6 +1,6 @@ import { renderToDOM } from "../core/render"; import { define } from "../core/registry"; -import { _document, _Symbol, _null } from "../utils/refCache"; +import { _document, _null } from "../utils/refCache"; import { clear } from "../utils/clear"; import { HNode } from "../core/HNode"; import { FragmentProps } from "./Fragment"; diff --git a/src/utils/refCache.ts b/src/utils/refCache.ts index f14f851..6602dcd 100644 --- a/src/utils/refCache.ts +++ b/src/utils/refCache.ts @@ -1,4 +1,5 @@ export const _document = document, + _createTextNode = _document.createTextNode.bind(_document), _Object = Object, _Array = Array, _String = String,