From c44278546589f902e24c961dd29cdb8981ed02d8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 3 Jun 2019 13:57:19 +0800 Subject: [PATCH] chore: notes on style binding optimization --- packages/runtime-core/src/createRenderer.ts | 1 - packages/runtime-core/src/index.ts | 1 + packages/runtime-core/src/patchFlags.ts | 5 +++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/src/createRenderer.ts b/packages/runtime-core/src/createRenderer.ts index 8c5860e6..1a27b113 100644 --- a/packages/runtime-core/src/createRenderer.ts +++ b/packages/runtime-core/src/createRenderer.ts @@ -318,7 +318,6 @@ export function createRenderer(options: RendererOptions) { // style // this flag is matched when the element has dynamic style bindings - // TODO separate static and dynamic styles? if (patchFlag & STYLE) { hostPatchProp(el, 'style', newProps.style, oldProps.style, isSVG) } diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index ce76e3fe..46d547da 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -9,6 +9,7 @@ export { Portal } from './vnode' +export { nextTick } from './scheduler' export { createComponent, FunctionalComponent } from './component' export { createRenderer, RendererOptions } from './createRenderer' export { Slot, Slots } from './componentSlots' diff --git a/packages/runtime-core/src/patchFlags.ts b/packages/runtime-core/src/patchFlags.ts index ff7a4ce5..119111f1 100644 --- a/packages/runtime-core/src/patchFlags.ts +++ b/packages/runtime-core/src/patchFlags.ts @@ -25,6 +25,11 @@ export const TEXT = 1 export const CLASS = 1 << 1 // Indicates an element with dynamic style +// The compiler pre-compiles static string styles into static objects +// + detects and hoists inline static objects +// e.g. style="color: red" and :style="{ color: 'red' }" both get hoisted as +// const style = { color: 'red' } +// render() { return e('div', { style }) } export const STYLE = 1 << 2 // Indicates an element that has non-class/style dynamic props.