-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix problems with skipped _notifyPath forwarding #60
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,13 +227,14 @@ | |
} | ||
} | ||
// do not change if there is one, it's same as before, and we are not forced | ||
if (!compositionString) { | ||
composition = this.defaultComposition && this.defaultComposition.cloneNode(true); | ||
compositionString = this.defaultComposition; | ||
} else { | ||
// make clone to avoid direct binding | ||
composition = this.stringToDocumentFragment(compositionString); | ||
} | ||
if (!compositionString || compositionString !== this._lastLayout || this._forceLayoutChange) { | ||
if (!compositionString) { | ||
composition = this.defaultComposition && this.defaultComposition.cloneNode(true); | ||
} else { | ||
// make clone to avoid direct binding | ||
composition = this.stringToDocumentFragment(compositionString); | ||
} | ||
this.stampComposition(composition); | ||
this._forceLayoutChange = false; | ||
this._lastLayout = compositionString; | ||
|
@@ -246,6 +247,7 @@ | |
* @param {Mixed} value New value | ||
*/ | ||
StarcounterIncludePrototype._notifyPath = function(path, value) { | ||
var modelAlreadyLoaded = this.template.model == this.partial; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EDIT: you can ignore this comment. After a second thought, both points aren't valid.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rename it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a fair point. |
||
if (path.indexOf("partial.") === 0 || path.indexOf("viewModel.") === 0) { | ||
if ( | ||
// path === "viewModel.Html" || // covered by viewModel._whatever_ | ||
|
@@ -259,11 +261,6 @@ | |
(path.indexOf('.Html') === path.length - 5) && path.slice(8, -5).indexOf('.') === -1 | ||
) { | ||
this.partialChanged(this.partial); | ||
} else if( | ||
// if viewModel|partial._whatever_, but not _ver - scope changed | ||
path.split('.').length === 2 && path.indexOf('_ver#s') === -1 && path.indexOf('_ver#c$') === -1 | ||
){ | ||
this.partialChanged(this.partial); | ||
} else { | ||
const compositionProviderPath = findCompositionProviderPath(this.partial); | ||
// if (path === 'partial.' + compositionProviderPath || | ||
|
@@ -280,11 +277,15 @@ | |
} else if (path === 'partial.' + compositionProviderPath + '.PartialId' || path === 'viewModel.' + compositionProviderPath + '.PartialId') { | ||
const compositionProvider = findCompositionProvider(this.partial); | ||
this.partialId = compositionProvider && compositionProvider.PartialId; //should always be string | ||
} else if (this.template._notifyPath) { | ||
this.template._notifyPath( | ||
path.replace("partial.", "model.") | ||
.replace("viewModel.", "model."), | ||
value); | ||
} else { | ||
this.partialChanged(this.partial); | ||
|
||
if (modelAlreadyLoaded && this.template._notifyPath) { | ||
this.template._notifyPath( | ||
path.replace("partial.", "model.") | ||
.replace("viewModel.", "model."), | ||
value); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it the regression of #37 (ignoring Palindrom meta-data)? At least performance-wise even thought no attrs for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There is a test for that (see the PR https://github.com/Starcounter/starcounter-include/pull/44/files), so I don't think so?
If no attrs for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The test you mention, tests building URL, not propagating changes to nested templates.
Consider the case: viewModel = {
_ver#s: 1,
_ver#c$: 1,
App: {}
} <dom-bind><template>
<starcounter-include view-model="{{viewModel}}"/>
</template></dom-bind> // palindrom-client translates `{op: 'replace', path: '/_ver#s', value: 2}` to polymer notification
domBind.set('viewModel._ver#s', 2);
// palindrom-client translates `{op: 'replace', path: '/App', value: {}}` to polymer notification
domBind.set('viewModel.App', {}); In both cases no attributes for
Like, where? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if you mean that it is wrong behavior or performance problem? The test that I mentioned was checking for wrong behavior. What you suggest seems to be a performance improvement and I agree with it, though I am not sure about the significance of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not just performance improvement. The case I described is the correct behavior, that is not tested and might be broken by this change. Why do you think https://github.com/Starcounter/starcounter-include/pull/44/files tests wrong behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry for choosing wrong words. The test in https://github.com/Starcounter/starcounter-include/pull/44/files is correct. It tests in the metadata is ignored by the URL builder (which is desired). It does not check if notifications about the metadata are forwarded or skipped (which doesn't matter except for performance). Why do you think that it matters if we skip forwarding the notifications about the metadata? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Currently it's only performance, and it's not notified any further due to functionality we lost while upgrading to Polymer 2.0 Juicy/imported-template#43. |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,17 @@ <h2>Custom Shadow DOM composition</h2> | |
.equal(document.querySelector(REFERENCE_COMPOSITION).innerHTML.trim()); | ||
}); | ||
}); | ||
describe('after partial property is replaced with itself', function () { | ||
it('should keep using the existing composition', function (done) { //otherwise ViewKeeper (aka workspaces) do not keep state in Firefox and Edge | ||
var old = scInclude.shadowRoot.querySelector("h2"); | ||
scInclude.partial = scInclude.partial; | ||
setTimeout(function() { | ||
expect(old).to.be.not.null; | ||
expect(old).to.be.equal(scInclude.shadowRoot.querySelector("h2")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather compare entire There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean compare old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that way, you are not testing "keep", you are testing "is again/still the markup". I think we should avoid flashing and in case there is a custom element that animates something, for example, we shouldn't break it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, line 89 checks the equality of the DOM node, not just the equality of the node's name. Perhaps we could check for flashing caused by detaching and attaching the same node, is that what you mean? I guess a way to do that would be to use mutation observer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that one particular node is back there again does not mean it didn't flashed due to:
Shadow DOM (composition) is a
Great idea. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But would comparing Anyway, feel free to improve the test. My goal was to add a test for something that failed before. I didn't try to solve anything more than that. |
||
done(); | ||
}, 500); | ||
}); | ||
}); | ||
|
||
}); | ||
</script> | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -92,11 +92,12 @@ | |||
done(); | ||||
}); | ||||
}); | ||||
it('should forward Polymer notification to `imported-template`', function () { | ||||
|
||||
it('should NOT forward Polymer notification to `imported-template` before it was stamped', function () { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we taking responsibility of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this inconsistent:
For me this is contradicting. The fix that I made 1acb2e9 (with a new test added) caused the test at line 96 to fail, and my conclusion was that the test at line 96 was wrong and should be inverted. |
||||
sinon.stub(importedTemplate, "_notifyPath"); | ||||
var newVal = "notification works"; | ||||
domBind.set("model.Page.scope1.doesItWork", newVal); | ||||
expect(importedTemplate._notifyPath).to.be.calledWith("model.scope1.doesItWork", newVal) | ||||
expect(importedTemplate._notifyPath).to.be.not.calledWith("model.scope1.doesItWork", newVal) | ||||
}); | ||||
|
||||
describe('after `dom-bind`` changed the partial property', function () { | ||||
|
@@ -183,6 +184,26 @@ | |||
}); | ||||
}); | ||||
}); | ||||
|
||||
describe('after `dom-bind` re-set the sub-partial property (just one scope) to the same instance but potentially with new values', function () { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After you removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test only checks if the notification is forwarded, without really testing any values in it. Perhaps the description should be changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well.. it was also involving testing integration with Polymer's dirty-checking. But Polymer 2.0 does not forward it anyways, so we already change this test to check that it's NOT forwarded |
||||
var scope; | ||||
|
||||
beforeEach(function(done) { | ||||
// IDEA: promisify juicy-html | ||||
sinon.stub(importedTemplate, "_notifyPath"); | ||||
importedTemplate.addEventListener('stamping', function onceStamped(){ | ||||
importedTemplate.removeEventListener('stamping', onceStamped); | ||||
scope = domBind.get('model.Page.scope1'); | ||||
domBind.set('model.Page.scope1', scope); | ||||
done(); | ||||
}); | ||||
}); | ||||
|
||||
it('should forward the notification to `imported-template`', function () { | ||||
expect(importedTemplate._notifyPath).to.be.calledWith("model.scope1", scope) | ||||
}); | ||||
}); | ||||
|
||||
describe('after `dom-bind`` changed the sub-partial property (just one scope) to new one with thethat results with the same merged Html', function () { | ||||
var changedScopeWithSameHtml; | ||||
beforeEach(function(done) { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was it moved here? Was it causing any problems? Now it's calling
composition = this.stringToDocumentFragment(compositionString);
even though there may be no need for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right about this. Actually, I have created a regression that was not caught by tests. I will make another PR.