From 5660b5f11a9a0d4653eb5425a487057d54716658 Mon Sep 17 00:00:00 2001 From: Patryk Szwermer Date: Wed, 24 Apr 2019 15:27:44 +0200 Subject: [PATCH 1/5] Added changes that referes to latest changes proposed in the blending app to identify compositions by handler uris. Related issue: https://github.com/Starcounter/Blending/issues/422 --- starcounter-include.html | 47 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/starcounter-include.html b/starcounter-include.html index 121347f..be465b1 100644 --- a/starcounter-include.html +++ b/starcounter-include.html @@ -310,27 +310,34 @@ return this._renderCompositionChange(compositionProviderComposition, () => { // convert string from view-model, to actual document fragment const customComposition = this.stringToDocumentFragment(compositionProviderComposition); + var defaultViewHtmlsToBeRendered; + + if (compositionProvider.ActualViewUris[0].hasOwnProperty("BlendingUri")) { + defaultViewHtmlsToBeRendered = + compositionProvider.ActualViewUris.filter( + x => !compositionProvider.ViewUris.includes(x.BlendingUri)) + .map(x => x.ViewHtml); + } else { + defaultViewHtmlsToBeRendered = compositionProvider.ViewUris; + } - // append default compositions for views not covered by this composition - if (compositionProvider.ViewUris) { - const keys = Object.keys(this.viewModel); - for(let key of keys) { - const scoped = this.viewModel[key]; - if (scoped && scoped.Html && compositionProvider.ViewUris.indexOf(scoped.Html) === -1) { - if (this.defaultComposition) { - this.template.scopedNodes.forEach((nodes) => { - if(nodes.scope === key) { - nodes.forEach((node) => appendComposition(customComposition, node)); - } - }); - } - else { - // BUG,TODO (tomalec): looks like a bug - // This means that if there *is* a custom composition, but it does not cover all views, - // and it happend that none of the views had a default composition, - // we would discard custom composition and use default -> fallback - return false; - } + const keys = Object.keys(this.viewModel); + for (let key of keys) { + const scoped = this.viewModel[key]; + if (scoped && scoped.Html && defaultViewHtmlsToBeRendered.includes(scoped.Html)) { + if (this.defaultComposition) { + this.template.scopedNodes.forEach((nodes) => { + if (nodes.scope === key) { + nodes.forEach((node) => appendComposition(customComposition, node)); + } + }); + } + else { + // BUG,TODO (tomalec): looks like a bug + // This means that if there *is* a custom composition, but it does not cover all views, + // and it happend that none of the views had a default composition, + // we would discard custom composition and use default -> fallback + return false; } } } From 673a78080898c97cf9a38f6fc07cc54cb66b7864 Mon Sep 17 00:00:00 2001 From: Marcin Warpechowski Date: Wed, 24 Apr 2019 22:13:17 +0200 Subject: [PATCH 2/5] revert the check for the existance of compositionProvider.ViewUris otherwise many WCT tests of starcounter-include fail --- starcounter-include.html | 57 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/starcounter-include.html b/starcounter-include.html index be465b1..12002cb 100644 --- a/starcounter-include.html +++ b/starcounter-include.html @@ -310,34 +310,37 @@ return this._renderCompositionChange(compositionProviderComposition, () => { // convert string from view-model, to actual document fragment const customComposition = this.stringToDocumentFragment(compositionProviderComposition); - var defaultViewHtmlsToBeRendered; - - if (compositionProvider.ActualViewUris[0].hasOwnProperty("BlendingUri")) { - defaultViewHtmlsToBeRendered = - compositionProvider.ActualViewUris.filter( - x => !compositionProvider.ViewUris.includes(x.BlendingUri)) - .map(x => x.ViewHtml); - } else { - defaultViewHtmlsToBeRendered = compositionProvider.ViewUris; - } + + // append default compositions for views not covered by this composition + if (compositionProvider.ViewUris) { + var defaultViewHtmlsToBeRendered; + if (compositionProvider.ActualViewUris[0].hasOwnProperty("BlendingUri")) { + defaultViewHtmlsToBeRendered = + compositionProvider.ActualViewUris.filter( + x => !compositionProvider.ViewUris.includes(x.BlendingUri)) + .map(x => x.ViewHtml); + } else { + defaultViewHtmlsToBeRendered = compositionProvider.ViewUris; + } - const keys = Object.keys(this.viewModel); - for (let key of keys) { - const scoped = this.viewModel[key]; - if (scoped && scoped.Html && defaultViewHtmlsToBeRendered.includes(scoped.Html)) { - if (this.defaultComposition) { - this.template.scopedNodes.forEach((nodes) => { - if (nodes.scope === key) { - nodes.forEach((node) => appendComposition(customComposition, node)); - } - }); - } - else { - // BUG,TODO (tomalec): looks like a bug - // This means that if there *is* a custom composition, but it does not cover all views, - // and it happend that none of the views had a default composition, - // we would discard custom composition and use default -> fallback - return false; + const keys = Object.keys(this.viewModel); + for (let key of keys) { + const scoped = this.viewModel[key]; + if (scoped && scoped.Html && defaultViewHtmlsToBeRendered.includes(scoped.Html)) { + if (this.defaultComposition) { + this.template.scopedNodes.forEach((nodes) => { + if (nodes.scope === key) { + nodes.forEach((node) => appendComposition(customComposition, node)); + } + }); + } + else { + // BUG,TODO (tomalec): looks like a bug + // This means that if there *is* a custom composition, but it does not cover all views, + // and it happend that none of the views had a default composition, + // we would discard custom composition and use default -> fallback + return false; + } } } } From 411a40aa4a522497ed54d8113f642daa6967823d Mon Sep 17 00:00:00 2001 From: Marcin Warpechowski Date: Wed, 24 Apr 2019 22:40:26 +0200 Subject: [PATCH 3/5] reflect the JSON structure of BlendingProvide 8.1.0 in the test fixture because the changes in source code rely on it to work and the test fails because of an outdated fixture --- test/composition/default-declarative-shadow-dom.html | 6 ++++-- test/composition/parent-declarative-shadow-dom.html | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/composition/default-declarative-shadow-dom.html b/test/composition/default-declarative-shadow-dom.html index 26ba5f8..18555c4 100644 --- a/test/composition/default-declarative-shadow-dom.html +++ b/test/composition/default-declarative-shadow-dom.html @@ -65,7 +65,8 @@

Custom Shadow DOM alternative composition

"CompositionProvider_0": { "PartialId": "given PartialId", "Composition": "", - "ViewUris": [] + "ViewUris": [], + "ActualViewUris": ["template_w_declarative-shadow-dom-alternative.html"] }, "App": { "Html": "template_w_declarative-shadow-dom-alternative.html", @@ -76,7 +77,8 @@

Custom Shadow DOM alternative composition

"CompositionProvider_0": { "PartialId": "given PartialId", "Composition": "custom!", - "ViewUris": ["template_w_declarative-shadow-dom.html"] + "ViewUris": ["template_w_declarative-shadow-dom.html"], + "ActualViewUris": ["template_w_declarative-shadow-dom.html", "template_w_declarative-shadow-dom-alternative.html"] }, "App1": { "Html": "template_w_declarative-shadow-dom.html", diff --git a/test/composition/parent-declarative-shadow-dom.html b/test/composition/parent-declarative-shadow-dom.html index ae07434..90f7ca5 100644 --- a/test/composition/parent-declarative-shadow-dom.html +++ b/test/composition/parent-declarative-shadow-dom.html @@ -73,7 +73,8 @@

Custom Shadow DOM alternative composition

"CompositionProvider_0": { "PartialId": "given PartialId", "Composition": "", - "ViewUris": [] + "ViewUris": [], + "ActualViewUris": ["template_w_declarative-shadow-dom-alternative.html"] }, "App": { "Html": "template_w_declarative-shadow-dom-alternative.html", @@ -84,7 +85,8 @@

Custom Shadow DOM alternative composition

"CompositionProvider_0": { "PartialId": "given PartialId", "Composition": "custom!", - "ViewUris": ["template_w_declarative-shadow-dom.html"] + "ViewUris": ["template_w_declarative-shadow-dom.html"], + "ActualViewUris": ["template_w_declarative-shadow-dom.html", "template_w_declarative-shadow-dom-alternative.html"] }, "App1": { "Html": "template_w_declarative-shadow-dom.html", From 401447f5945d82a6131b739243c5614eda5e8bd4 Mon Sep 17 00:00:00 2001 From: Patryk Szwermer Date: Thu, 25 Apr 2019 13:49:36 +0200 Subject: [PATCH 4/5] Removed conditional set of defaultViewHtmlsToBeRendered and replaced it with single expression --- starcounter-include.html | 51 +++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/starcounter-include.html b/starcounter-include.html index 12002cb..3562d44 100644 --- a/starcounter-include.html +++ b/starcounter-include.html @@ -312,35 +312,28 @@ const customComposition = this.stringToDocumentFragment(compositionProviderComposition); // append default compositions for views not covered by this composition - if (compositionProvider.ViewUris) { - var defaultViewHtmlsToBeRendered; - if (compositionProvider.ActualViewUris[0].hasOwnProperty("BlendingUri")) { - defaultViewHtmlsToBeRendered = - compositionProvider.ActualViewUris.filter( - x => !compositionProvider.ViewUris.includes(x.BlendingUri)) - .map(x => x.ViewHtml); - } else { - defaultViewHtmlsToBeRendered = compositionProvider.ViewUris; - } - - const keys = Object.keys(this.viewModel); - for (let key of keys) { - const scoped = this.viewModel[key]; - if (scoped && scoped.Html && defaultViewHtmlsToBeRendered.includes(scoped.Html)) { - if (this.defaultComposition) { - this.template.scopedNodes.forEach((nodes) => { - if (nodes.scope === key) { - nodes.forEach((node) => appendComposition(customComposition, node)); - } - }); - } - else { - // BUG,TODO (tomalec): looks like a bug - // This means that if there *is* a custom composition, but it does not cover all views, - // and it happend that none of the views had a default composition, - // we would discard custom composition and use default -> fallback - return false; - } + const defaultViewHtmlsToBeRendered = + compositionProvider.ActualViewUris.filter( + x => !compositionProvider.ViewUris.includes(x.hasOwnProperty("BlendingUri") ? x.BlendingUri : x)) + .map(x => x.hasOwnProperty("ViewHtml") ? x.ViewHtml : x); + + const keys = Object.keys(this.viewModel); + for (let key of keys) { + const scoped = this.viewModel[key]; + if (scoped && scoped.Html && defaultViewHtmlsToBeRendered.includes(scoped.Html)) { + if (this.defaultComposition) { + this.template.scopedNodes.forEach((nodes) => { + if (nodes.scope === key) { + nodes.forEach((node) => appendComposition(customComposition, node)); + } + }); + } + else { + // BUG,TODO (tomalec): looks like a bug + // This means that if there *is* a custom composition, but it does not cover all views, + // and it happend that none of the views had a default composition, + // we would discard custom composition and use default -> fallback + return false; } } } From e7a9b1ef3429d8851e3857ec98568f35813f0101 Mon Sep 17 00:00:00 2001 From: PatrykSzwer Date: Fri, 26 Apr 2019 13:38:55 +0200 Subject: [PATCH 5/5] Fixed part of the tests by adding ViewUris and ActualViewUris to the fixtures --- .../cleanup_removed_partial_Layout.html | 6 ++++-- .../nested-html/stamped_from_polymer_template.html | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/view-model-attribute/cleanup_removed_partial_Layout.html b/test/view-model-attribute/cleanup_removed_partial_Layout.html index 2007c4e..c448e23 100644 --- a/test/view-model-attribute/cleanup_removed_partial_Layout.html +++ b/test/view-model-attribute/cleanup_removed_partial_Layout.html @@ -1,4 +1,4 @@ - + @@ -36,7 +36,9 @@ "CompositionProvider_0": { "Html": "../templateToInclude.html", "Composition": 'a Composition', - "PartialId": "given PartialId" + "PartialId": "given PartialId", + "ViewUris": [""], + "ActualViewUris": [""] }, "doesItWork": "works!" }; diff --git a/test/view-model-attribute/nested-html/stamped_from_polymer_template.html b/test/view-model-attribute/nested-html/stamped_from_polymer_template.html index d0dfe8e..7333482 100644 --- a/test/view-model-attribute/nested-html/stamped_from_polymer_template.html +++ b/test/view-model-attribute/nested-html/stamped_from_polymer_template.html @@ -1,4 +1,4 @@ - + @@ -42,7 +42,9 @@ }, 'CompositionProvider_0': { 'Composition': 'custom composition', - 'doesItWork': 'works!' + 'doesItWork': 'works!', + "ViewUris": [""], + "ActualViewUris": [""] } }; };