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
17 changes: 10 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "attach",
"name": "Attach",
"restart": true,
"protocol": "inspector"
}]
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"restart": true,
"protocol": "inspector",
"port": 9230
}
]
}
28 changes: 17 additions & 11 deletions lib/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Utils = require("../utils");
const find = require("find");
// @ts-ignore
const jsToString = require("js-to-string");
const deepAssign = require("deep-assign");

/**
* @typedef CompiledObjectType
Expand Down Expand Up @@ -124,7 +125,7 @@ class Renderer {
* @returns {Function}
*/
FixData(oldData, newData) {
const mergedData = Object.assign({}, oldData, this.data, newData);
const mergedData = deepAssign({}, oldData, this.data, newData);
return function data() {
return mergedData;
};
Expand All @@ -135,7 +136,7 @@ class Renderer {
* @returns {Function}
*/
FixPropsData(oldPropsData, newPropsData) {
return Object.assign({}, oldPropsData, this.propsData, newPropsData);
return deepAssign({}, oldPropsData, this.propsData, newPropsData);
}
/**
* @param {string} componentFile
Expand Down Expand Up @@ -389,7 +390,7 @@ class Renderer {
*
* @param {CompiledObjectType} compiledObject
* @param {string} filePath
* @returns {Promise<{data: object}>}
* @returns {Promise<{data: object, propsData: object, props: object}>}
*/
MakeBundle(compiledObject, filePath) {
return new Promise((resolve, reject) => {
Expand All @@ -405,22 +406,27 @@ class Renderer {
*
* @param {string} filePath
* @param {Object} data
* @param {Object} vueOptions
* @param {{data: Object, propsData: Object} | Object} vueOptions
* @returns {Promise<{vue: object, css: string, script: string}>}
*/
MakeVueClass(filePath, data, vueOptions = {}) {
return new Promise((resolve, reject) => {
let cachedBundle = this.internalCache.get(filePath);
if (cachedBundle) {
const cachedData = Object.assign({}, cachedBundle.data());
const newbundle = deepAssign({}, cachedBundle.bundle);

if (cachedBundle.bundle.data && typeof cachedBundle.bundle.data === "function") {
cachedBundle.bundle.data = this.FixData(cachedBundle.bundle.data(), data);
newbundle.data = this.FixData(cachedData, data);
}
if (vueOptions.propsData && (cachedBundle.bundle.propsData || cachedBundle.bundle.props)) {
cachedBundle.bundle.propsData = this.FixPropsData(cachedBundle.bundle.propsData || {}, vueOptions.propsData);
newbundle.propsData = this.FixPropsData(cachedBundle.bundle.propsData || {}, vueOptions.propsData);
}

// @ts-ignore
const vue = new Vue(cachedBundle.bundle);
const cleanBundle = this._deleteCtor(cachedBundle.bundle);
const vue = new Vue(newbundle);
// vue._data = newbundle.data();
const cleanBundle = this._deleteCtor(newbundle);
const object = {
vue: vue,
css: cachedBundle.style,
Expand All @@ -433,7 +439,7 @@ class Renderer {
.then(compiled => {
this.MakeBundle(compiled, filePath)
.then(bundle => {
this.internalCache.set(filePath, { bundle: bundle, style: compiled.style });
this.internalCache.set(filePath, { bundle: bundle, style: compiled.style, data: bundle.data });
//Insert Data
if (bundle.data && typeof bundle.data === "function") {
bundle.data = this.FixData(bundle.data(), data);
Expand Down Expand Up @@ -521,7 +527,7 @@ class Renderer {
this.MakeVueClass(filePath, data, vueOptions)
.then(vueClass => {
const mergedHeadObject = Utils.MergeHead(vueOptions.head, this.head);
const template = Object.assign({}, this.template, vueOptions.template);
const template = deepAssign({}, this.template, vueOptions.template);
//Init Renderer
const context = {
head: Utils.BuildHead(mergedHeadObject),
Expand Down Expand Up @@ -557,7 +563,7 @@ class Renderer {
.then(vueClass => {
const mergedHeadObject = Utils.MergeHead(vueOptions.head, this.head);
const headString = Utils.BuildHead(mergedHeadObject);
const template = Object.assign({}, this.template, vueOptions.template);
const template = deepAssign({}, this.template, vueOptions.template);
//Init Renderer
const context = {
head: headString,
Expand Down
Loading