From f629b345c4aa5320dba8496566330f179e7a0306 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 25 Apr 2016 00:06:33 -0400 Subject: [PATCH] decouple renderer logic and web platform --- build/alias.js | 3 ++- build/build.js | 6 +++++ src/entries/web-server-renderer.js | 19 ++++++++++++++-- .../web => }/server/create-renderer.js | 22 +++++-------------- 4 files changed, 30 insertions(+), 20 deletions(-) rename src/{platforms/web => }/server/create-renderer.js (75%) diff --git a/build/alias.js b/build/alias.js index 7a5d3fb9..07888d1f 100644 --- a/build/alias.js +++ b/build/alias.js @@ -5,5 +5,6 @@ module.exports = { compiler: path.resolve(__dirname, '../src/compiler'), core: path.resolve(__dirname, '../src/core'), shared: path.resolve(__dirname, '../src/shared'), - web: path.resolve(__dirname, '../src/platforms/web') + web: path.resolve(__dirname, '../src/platforms/web'), + server: path.resolve(__dirname, '../src/server') } diff --git a/build/build.js b/build/build.js index 83609915..cb7d2809 100644 --- a/build/build.js +++ b/build/build.js @@ -63,6 +63,12 @@ build([ format: 'cjs', external: ['entities'], out: 'dist/compiler.common.js' + }, + // Web server renderer + { + entry: 'src/entries/web-server-renderer.js', + format: 'cjs', + out: 'dist/server-renderer.js' } ]) diff --git a/src/entries/web-server-renderer.js b/src/entries/web-server-renderer.js index 7375b9f7..be6e7d40 100644 --- a/src/entries/web-server-renderer.js +++ b/src/entries/web-server-renderer.js @@ -1,3 +1,18 @@ -import { createComponentRenderer } from 'web/server/create-renderer' +import { createRenderer } from 'server/create-renderer' +import attrs from 'web/server/modules/attrs' +import klass from 'web/server/modules/class' +import style from 'web/server/modules/style' +import show from 'web/server/directives/show' +import { isUnaryTag } from 'web/util/index' -export default createComponentRenderer() +export default createRenderer({ + isUnaryTag, + modules: { + attrs, + style, + class: klass + }, + directives: { + show + } +}) diff --git a/src/platforms/web/server/create-renderer.js b/src/server/create-renderer.js similarity index 75% rename from src/platforms/web/server/create-renderer.js rename to src/server/create-renderer.js index 0f744b36..dc57e894 100644 --- a/src/platforms/web/server/create-renderer.js +++ b/src/server/create-renderer.js @@ -1,20 +1,8 @@ -import renderAttrs from './modules/attrs' -import renderClass from './modules/class' -import renderStyle from './modules/style' -import show from './directives/show' -import { isUnaryTag } from 'web/util/index' - -export function createComponentRenderer (options = {}) { - const modules = Object.assign({ - attrs: renderAttrs, - style: renderStyle, - class: renderClass - }, options.modules) - - const directives = Object.assign({ - show - }, options.directives) - +export function createRenderer ({ + modules = {}, + directives = {}, + isUnaryTag = (() => false) +} = {}) { function renderComponent (component) { component.$mount() return renderElement(component._vnode)