-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use InitialPropertiesHandler for injected elements
Fixes #4304
- Loading branch information
Denis Anisimov
committed
Jul 31, 2018
1 parent
aff7bb0
commit b7cae0e
Showing
4 changed files
with
101 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import com.vaadin.client.Command; | ||
import com.vaadin.client.Console; | ||
import com.vaadin.client.ExistingElementMap; | ||
import com.vaadin.client.InitialPropertiesHandler; | ||
import com.vaadin.client.PolymerUtils; | ||
import com.vaadin.client.WidgetUtil; | ||
import com.vaadin.client.flow.ConstantPool; | ||
|
@@ -61,7 +62,6 @@ | |
import elemental.json.JsonObject; | ||
import elemental.json.JsonType; | ||
import elemental.json.JsonValue; | ||
|
||
import jsinterop.annotations.JsFunction; | ||
|
||
/** | ||
|
@@ -284,9 +284,9 @@ private native void bindPolymerModelProperties(StateNode node, | |
private native void hookUpPolymerElement(StateNode node, Element element) | ||
/*-{ | ||
var self = this; | ||
var originalPropertiesChanged = element._propertiesChanged; | ||
if (originalPropertiesChanged) { | ||
element._propertiesChanged = function (currentProps, changedProps, oldProps) { | ||
$entry(function () { | ||
|
@@ -295,16 +295,16 @@ private native void hookUpPolymerElement(StateNode node, Element element) | |
originalPropertiesChanged.apply(this, arguments); | ||
}; | ||
} | ||
var tree = [email protected]::getTree()(); | ||
var originalReady = element.ready; | ||
element.ready = function (){ | ||
originalReady.apply(this, arguments); | ||
@com.vaadin.client.PolymerUtils::fireReadyEvent(*)(element); | ||
// The _propertiesChanged method which is replaced above for the element | ||
// doesn't do anything for items in dom-repeat. | ||
// Instead it's called with some meaningful info for the <code>dom-repeat</code> element. | ||
|
@@ -313,7 +313,7 @@ private native void hookUpPolymerElement(StateNode node, Element element) | |
// which changes this method for any dom-repeat instance. | ||
var replaceDomRepeatPropertyChange = function(){ | ||
var domRepeat = element.root.querySelector('dom-repeat'); | ||
if ( domRepeat ){ | ||
// If the <code>dom-repeat</code> element is in the DOM then | ||
// this method should not be executed anymore. The logic below will replace | ||
|
@@ -327,12 +327,12 @@ private native void hookUpPolymerElement(StateNode node, Element element) | |
// if dom-repeat is found => replace _propertiesChanged method in the prototype and mark it as replaced. | ||
if ( !domRepeat.constructor.prototype.$propChangedModified){ | ||
domRepeat.constructor.prototype.$propChangedModified = true; | ||
var changed = domRepeat.constructor.prototype._propertiesChanged; | ||
domRepeat.constructor.prototype._propertiesChanged = function(currentProps, changedProps, oldProps){ | ||
changed.apply(this, arguments); | ||
var props = Object.getOwnPropertyNames(changedProps); | ||
var items = "items."; | ||
for(i=0; i<props.length; i++){ | ||
|
@@ -352,7 +352,7 @@ private native void hookUpPolymerElement(StateNode node, Element element) | |
if( currentPropsItem && currentPropsItem.nodeId ){ | ||
var nodeId = currentPropsItem.nodeId; | ||
var value = currentPropsItem[propertyName]; | ||
// this is an attempt to find the template element | ||
// which is not available as a context in the protype method | ||
var host = this.__dataHost; | ||
|
@@ -363,7 +363,7 @@ private native void hookUpPolymerElement(StateNode node, Element element) | |
while( !host.localName || host.__dataHost ){ | ||
host = host.__dataHost; | ||
} | ||
$entry(function () { | ||
@SimpleElementBindingStrategy::handleListItemPropertyChange(*)(nodeId, host, propertyName, value, tree); | ||
})(); | ||
|
@@ -374,7 +374,7 @@ private native void hookUpPolymerElement(StateNode node, Element element) | |
}; | ||
} | ||
}; | ||
// dom-repeat doesn't have to be in DOM even if template has it | ||
// such situation happens if there is dom-if e.g. which evaluates to <code>false</code> initially. | ||
// in this case dom-repeat is not yet in the DOM tree until dom-if becomes <code>true</code> | ||
|
@@ -389,7 +389,7 @@ private native void hookUpPolymerElement(StateNode node, Element element) | |
element.addEventListener('dom-change',replaceDomRepeatPropertyChange); | ||
} | ||
} | ||
}-*/; | ||
|
||
private static void handleListItemPropertyChange(double nodeId, | ||
|
@@ -846,6 +846,9 @@ private void appendVirtualChild(BindingContext context, StateNode node, | |
return; | ||
} | ||
|
||
InitialPropertiesHandler initialPropertiesHandler = node.getTree() | ||
.getRegistry().getInitialPropertiesHandler(); | ||
|
||
assert context.htmlNode instanceof Element : "Unexpected html node. The node is supposed to be a custom element"; | ||
if (NodeProperties.INJECT_BY_ID.equals(type)) { | ||
String id = object.getString(NodeProperties.PAYLOAD); | ||
|
@@ -864,6 +867,10 @@ private void appendVirtualChild(BindingContext context, StateNode node, | |
.getDomElementById(context.htmlNode, id); | ||
if (verifyAttachedElement(existingElement, node, id, address, | ||
context)) { | ||
if (!reactivePhase) { | ||
initialPropertiesHandler.nodeRegistered(node); | ||
initialPropertiesHandler.flushPropertyUpdates(); | ||
} | ||
node.setDomNode(existingElement); | ||
context.binderContext.createAndBind(node); | ||
} | ||
|
@@ -886,6 +893,10 @@ private void appendVirtualChild(BindingContext context, StateNode node, | |
|
||
if (verifyAttachedElement(customElement, node, null, address, | ||
context)) { | ||
if (!reactivePhase) { | ||
initialPropertiesHandler.nodeRegistered(node); | ||
initialPropertiesHandler.flushPropertyUpdates(); | ||
} | ||
node.setDomNode(customElement); | ||
context.binderContext.createAndBind(node); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
...tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/KeyPressListenerView.java
This file was deleted.
Oops, something went wrong.