Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions lib/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Renderer {
this.internalCache = new Utils.Cache();
this.head = options.head || {};
this.data = options.data || {};
this.propsData = options.propsData || {};
this.template = options.template || {};
const version = Utils.VueVersion(options.vueVersion);
if (version.enabled) {
Expand Down Expand Up @@ -128,6 +129,14 @@ class Renderer {
return mergedData;
};
}
/**
* @param {Object} oldPropsData
* @param {Object} newPropsData
* @returns {Function}
*/
FixPropsData(oldPropsData, newPropsData) {
return Object.assign({}, oldPropsData, this.propsData, newPropsData);
}
/**
* @param {string} componentFile
* @param {string} filePath
Expand Down Expand Up @@ -396,15 +405,19 @@ class Renderer {
*
* @param {string} filePath
* @param {Object} data
* @param {Object} vueOptions
* @returns {Promise<{vue: object, css: string, script: string}>}
*/
MakeVueClass(filePath, data) {
MakeVueClass(filePath, data, vueOptions = {}) {
return new Promise((resolve, reject) => {
let cachedBundle = this.internalCache.get(filePath);
if (cachedBundle) {
if (cachedBundle.bundle.data && typeof cachedBundle.bundle.data === "function") {
cachedBundle.bundle.data = this.FixData(cachedBundle.bundle.data(), data);
}
if (vueOptions.propsData && (cachedBundle.bundle.propsData || cachedBundle.bundle.props)) {
cachedBundle.bundle.propsData = this.FixPropsData(cachedBundle.bundle.propsData || {}, vueOptions.propsData);
}
// @ts-ignore
const vue = new Vue(cachedBundle.bundle);
const cleanBundle = this._deleteCtor(cachedBundle.bundle);
Expand All @@ -425,6 +438,10 @@ class Renderer {
if (bundle.data && typeof bundle.data === "function") {
bundle.data = this.FixData(bundle.data(), data);
}
//Insert propsData
if (vueOptions.propsData && (bundle.propsData || bundle.props)) {
bundle.propsData = this.FixPropsData(bundle.propsData || {}, vueOptions.propsData);
}

//Create Vue Class
// @ts-ignore
Expand Down Expand Up @@ -501,7 +518,7 @@ class Renderer {
return new Promise((resolve, reject) => {
this.FindFile(vueFile)
.then(filePath => {
this.MakeVueClass(filePath, data)
this.MakeVueClass(filePath, data, vueOptions)
.then(vueClass => {
const mergedHeadObject = Utils.MergeHead(vueOptions.head, this.head);
const template = Object.assign({}, this.template, vueOptions.template);
Expand Down Expand Up @@ -536,7 +553,7 @@ class Renderer {
return new Promise((resolve, reject) => {
this.FindFile(vueFile)
.then(filePath => {
this.MakeVueClass(filePath, data)
this.MakeVueClass(filePath, data, vueOptions)
.then(vueClass => {
const mergedHeadObject = Utils.MergeHead(vueOptions.head, this.head);
const headString = Utils.BuildHead(mergedHeadObject);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-pronto",
"version": "1.7.0",
"version": "1.7.1",
"description": "Seriously fast vue server renderer",
"main": "lib/index.js",
"files": [
Expand Down
51 changes: 51 additions & 0 deletions tests/example/views/index/index-with-props.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<div>
<h1 class="red">{{msg}}</h1>
<foo hellodata="component"></foo>
<p>{{bar}}</p>
<div v-html="fakehtml"></div>
<h1>{{title}}</h1>
<p>Welcome to the {{title}} demo. Click a link:</p>
<p>import fooTransitionExpand from '@foo/styles-animation/src/components/foo-transition-expand.vue';</p>
<p>const test = require("foo.vue");</p>
<p>const bar = require("bar.vue");</p>
<input v-model="messageOuter" placeholder="edit me">
<button type="button" name="button" v-on:click="hello(messageOuter)">{{messageOuter}}</button>
<message-comp :message="messageOuter"></message-comp>
<users :users="users"></users>
<simple></simple>
</div>
</template>

<script>
import foo from "../../components/component.vue";
import messageComp from '../../components/message-comp.vue';
import users from '../../components/users.vue';
import helloMixin from '../../mixins/exampleMixin.js';
import simple from 'simple-vue-component-test/simple.vue';
export default {
props: {
msg: {
type: String,
default: 'Hello world!'
},
messageOuter: {
type: String,
default: 'Say Foo'
}
},
components: {
foo,
messageComp,
users,
simple
},
mixins: [helloMixin]
}
</script>

<style>
.red {
color: #f00;
}
</style>
50 changes: 50 additions & 0 deletions tests/renderer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.