Explorar o código

restructure for server rendering

Evan You %!s(int64=10) %!d(string=hai) anos
pai
achega
1a21db9c9a

+ 1 - 1
src/entries/web-compiler.js

@@ -1,7 +1,7 @@
 import { extend } from 'shared/util'
 import { compile as baseCompile } from 'compiler/index'
 import directives from 'web/compiler/directives/index'
-import { isReservedTag, mustUseProp, getTagNamespace } from 'web/util'
+import { isReservedTag, mustUseProp, getTagNamespace } from 'web/util/index'
 
 const baseOptions = {
   directives,

+ 1 - 1
src/entries/web-runtime-with-compiler.js

@@ -1,6 +1,6 @@
 import config from 'core/config'
 import { warn, cached } from 'core/util/index'
-import { query } from 'web/util'
+import { query } from 'web/util/index'
 import Vue from './web-runtime'
 import { compile } from './web-compiler'
 

+ 1 - 1
src/entries/web-runtime.js

@@ -4,7 +4,7 @@ import * as nodeOps from 'web/runtime/node-ops'
 import platformDirectives from 'web/runtime/directives/index'
 import baseModules from 'core/vdom/modules/index'
 import platformModules from 'web/runtime/modules/index'
-import { query, isUnknownElement, isReservedTag } from 'web/util'
+import { query, isUnknownElement, isReservedTag } from 'web/util/index'
 
 // install platform specific utils
 Vue.config.isUnknownElement = isUnknownElement

+ 1 - 1
src/platforms/web/runtime/class-util.js

@@ -1,4 +1,4 @@
-import { isIE9 } from '../util'
+import { isIE9 } from 'web/util/index'
 import { namespaceMap } from './node-ops'
 
 const svgNS = namespaceMap.svg

+ 1 - 1
src/platforms/web/runtime/directives/model.js

@@ -1,4 +1,4 @@
-import { isAndroid, isIE9 } from '../../util'
+import { isAndroid, isIE9 } from 'web/util/index'
 
 if (isIE9) {
   // http://www.matts411.com/post/internet-explorer-9-oninput/

+ 1 - 1
src/platforms/web/runtime/directives/show.js

@@ -1,4 +1,4 @@
-import { isIE9 } from '../../util'
+import { isIE9 } from 'web/util/index'
 import { enter, leave } from '../modules/transition'
 
 export default {

+ 1 - 14
src/platforms/web/runtime/modules/attrs.js

@@ -1,17 +1,4 @@
-import { makeMap } from 'shared/util'
-
-const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
-const isBooleanAttr = makeMap(
-  'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
-  'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
-  'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
-  'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
-  'required,reversed,scoped,seamless,selected,sortable,translate,' +
-  'truespeed,typemustmatch,visible'
-)
-
-const xlinkNS = 'http://www.w3.org/1999/xlink'
-const isXlink = name => name.charAt(5) === ':' && name.slice(0, 5) === 'xlink'
+import { isBooleanAttr, isEnumeratedAttr, isXlink, xlinkNS } from 'web/util/index'
 
 function updateAttrs (oldVnode, vnode) {
   if (!oldVnode.data.attrs && !vnode.data.attrs) {

+ 3 - 55
src/platforms/web/runtime/modules/class.js

@@ -1,24 +1,14 @@
-import { extend, isArray, isObject } from 'shared/util'
 import { setClass } from '../class-util'
+import { genClassForVnode, concat, stringifyClass } from 'web/util/index'
 
 function updateClass (oldVnode, vnode) {
   const el = vnode.elm
-  let data = vnode.data
+  const data = vnode.data
   if (!data.staticClass && !data.class) {
     return
   }
 
-  // check if this is a component container node
-  // or a child component root node
-  let i
-  if ((i = vnode.child) && (i = i._vnode.data)) {
-    data = mergeClassData(i, data)
-  }
-  if ((i = vnode.parent) && (i = i.data)) {
-    data = mergeClassData(data, i)
-  }
-
-  let cls = genClass(data)
+  let cls = genClassForVnode(vnode)
 
   // handle transition classes
   const transitionClass = el._transitionClasses
@@ -33,48 +23,6 @@ function updateClass (oldVnode, vnode) {
   }
 }
 
-function mergeClassData (child, parent) {
-  return {
-    staticClass: concat(child.staticClass, parent.staticClass),
-    class: child.class ? extend(child.class, parent.class) : parent.class
-  }
-}
-
-function genClass (data) {
-  const dynamicClass = data.class
-  const staticClass = data.staticClass
-  if (staticClass || dynamicClass) {
-    return concat(staticClass, stringifyClass(dynamicClass))
-  }
-}
-
-function concat (a, b) {
-  return a ? b ? (a + ' ' + b) : a : (b || '')
-}
-
-function stringifyClass (data) {
-  if (!data) {
-    return ''
-  }
-  if (typeof data === 'string') {
-    return data
-  }
-  if (isArray(data)) {
-    let res = ''
-    for (let i = 0, l = data.length; i < l; i++) {
-      if (data[i]) res += stringifyClass(data[i]) + ' '
-    }
-    return res.slice(0, -1)
-  }
-  if (isObject(data)) {
-    let res = ''
-    for (var key in data) {
-      if (data[key]) res += key + ' '
-    }
-    return res.slice(0, -1)
-  }
-}
-
 export default {
   create: updateClass,
   update: updateClass

+ 1 - 1
src/platforms/web/runtime/modules/transition.js

@@ -1,7 +1,7 @@
 import { addClass, removeClass } from '../class-util'
 import { inBrowser } from 'core/util/index'
 import { cached, remove } from 'shared/util'
-import { isIE9 } from '../../util'
+import { isIE9 } from 'web/util/index'
 
 const TRANSITION = 'transition'
 const ANIMATION = 'animation'

+ 0 - 0
src/platforms/web/server/modules/attrs.js


+ 0 - 0
src/platforms/web/server/modules/class.js


+ 0 - 0
src/platforms/web/server/modules/style.js


+ 7 - 0
src/platforms/web/server/render.js

@@ -0,0 +1,7 @@
+import attrs from './modules/attrs'
+import style from './modules/style'
+import klass from './modules/class'
+
+export function render () {
+
+}

+ 14 - 0
src/platforms/web/util/attrs.js

@@ -0,0 +1,14 @@
+import { makeMap } from 'shared/util'
+
+export const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
+export const isBooleanAttr = makeMap(
+  'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
+  'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
+  'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
+  'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
+  'required,reversed,scoped,seamless,selected,sortable,translate,' +
+  'truespeed,typemustmatch,visible'
+)
+
+export const xlinkNS = 'http://www.w3.org/1999/xlink'
+export const isXlink = name => name.charAt(5) === ':' && name.slice(0, 5) === 'xlink'

+ 57 - 0
src/platforms/web/util/class.js

@@ -0,0 +1,57 @@
+import { extend, isArray, isObject } from 'shared/util'
+
+export function genClassForVnode (vnode) {
+  let data = vnode.data
+  // Important: check if this is a component container node
+  // or a child component root node
+  let i
+  if ((i = vnode.child) && (i = i._vnode.data)) {
+    data = mergeClassData(i, data)
+  }
+  if ((i = vnode.parent) && (i = i.data)) {
+    data = mergeClassData(data, i)
+  }
+  return genClassFromData(data)
+}
+
+function mergeClassData (child, parent) {
+  return {
+    staticClass: concat(child.staticClass, parent.staticClass),
+    class: child.class ? extend(child.class, parent.class) : parent.class
+  }
+}
+
+function genClassFromData (data) {
+  const dynamicClass = data.class
+  const staticClass = data.staticClass
+  if (staticClass || dynamicClass) {
+    return concat(staticClass, stringifyClass(dynamicClass))
+  }
+}
+
+export function concat (a, b) {
+  return a ? b ? (a + ' ' + b) : a : (b || '')
+}
+
+export function stringifyClass (value) {
+  if (!value) {
+    return ''
+  }
+  if (typeof value === 'string') {
+    return value
+  }
+  if (isArray(value)) {
+    let res = ''
+    for (let i = 0, l = value.length; i < l; i++) {
+      if (value[i]) res += stringifyClass(value[i]) + ' '
+    }
+    return res.slice(0, -1)
+  }
+  if (isObject(value)) {
+    let res = ''
+    for (var key in value) {
+      if (value[key]) res += key + ' '
+    }
+    return res.slice(0, -1)
+  }
+}

+ 0 - 25
src/platforms/web/util.js → src/platforms/web/util/element.js

@@ -1,11 +1,6 @@
 import { inBrowser } from 'core/util/env'
-import { warn } from 'core/util/debug'
 import { makeMap } from 'shared/util'
 
-const UA = inBrowser && window.navigator.userAgent.toLowerCase()
-export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
-export const isAndroid = UA && UA.indexOf('android') > 0
-
 export const isReservedTag = makeMap(
   'html,base,head,link,meta,style,title,' +
   'address,article,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
@@ -66,23 +61,3 @@ export function isUnknownElement (tag) {
     ))
   }
 }
-
-/**
- * Query an element selector if it's not an element already.
- *
- * @param {String|Element} el
- * @return {Element}
- */
-
-export function query (el) {
-  if (typeof el === 'string') {
-    var selector = el
-    el = document.querySelector(el)
-    if (!el) {
-      process.env.NODE_ENV !== 'production' && warn(
-        'Cannot find element: ' + selector
-      )
-    }
-  }
-  return el
-}

+ 29 - 0
src/platforms/web/util/index.js

@@ -0,0 +1,29 @@
+import { warn, inBrowser } from 'core/util/index'
+
+export * from './attrs'
+export * from './class'
+export * from './element'
+
+const UA = inBrowser && window.navigator.userAgent.toLowerCase()
+export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
+export const isAndroid = UA && UA.indexOf('android') > 0
+
+/**
+ * Query an element selector if it's not an element already.
+ *
+ * @param {String|Element} el
+ * @return {Element}
+ */
+
+export function query (el) {
+  if (typeof el === 'string') {
+    var selector = el
+    el = document.querySelector(el)
+    if (!el) {
+      process.env.NODE_ENV !== 'production' && warn(
+        'Cannot find element: ' + selector
+      )
+    }
+  }
+  return el
+}