Skip to content

Commit

Permalink
📇: allow to include viewModel into spec expression if possible
Browse files Browse the repository at this point in the history
Given a model provides us with an expression serialization, we embedd it into the spec expression accordingly.
  • Loading branch information
merryman authored and linusha committed Jul 23, 2024
1 parent e26a66c commit 40078ec
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lively.serializer2/plugins/expression-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default class ExpressionSerializer {
embedValue (val, nestedExpressions) {
if (val && val.__serialize__) {
val = val.__serialize__({ expressionSerializer: this });
if (val && val.__expr__) {
if (val?.__expr__) {
if (nestedExpressions) {
const uuid = string.newUUID();
nestedExpressions[uuid] = val;
Expand Down Expand Up @@ -912,6 +912,15 @@ export function serializeSpec (morph, opts = {}) {
gatherConnectionInfo(morph, path, subopts);
traverseSubmorphs(morph, exported, path, styleProto, subopts); // needs to be done before we handle text attributes
handleSpecProps(morph, exported, styleProto, path, masterInScope, subopts);

let { viewModel } = morph;
if (asExpression && viewModel) {
const viewModelExpr = exprSerializer.embedValue(viewModel, nestedExpressions);
if (viewModelExpr !== viewModel) {
exported.viewModel = viewModelExpr;
}
}

if (!skipAttributes.includes('textAndAttributes')) handleTextAndAttributes(morph, exported, styleProto, path, masterInScope, subopts);

if (root && keepConnections) {
Expand Down

0 comments on commit 40078ec

Please sign in to comment.