JS polymer conflicts with Rails Turbolinks

Trying to use PolymerJs with a Ruby on Rails project with Turbolinks enabled. Polymer component bootstrapping works, but when I click on the link that the new page displays, but my Polymer components are not reinitialized. Instead, they look like JS doesn't work for them at all.

I load polymer components and the platform into the header, so they are not loaded with "page changes" (this is how turboprops work - it only reloads the body).

It seems that I can "fake" it by making the following assumption that I want to "update" my user element and core-ajax tags on my page

custom_elements = document.querySelectorAll("my-custom-element, core-ajax ") 
for element in custom_elements 
  element.parentNode.replaceChild(element.cloneNode(), element) 

I guess there is a more idiomatic way to do this. Also tried calling the Polymer () call inside the element again without success. It seems to be working properly, but there is no shadowDom binding or any other activity indicating that Polymer tried to reconnect my elements. I also tried using preventDispose, but this does not seem to work as a completely new object is being loaded from the server.

How can I tell Polymer / Platform to reinitialize all the elements on my page? What events should I name?

Or, if this is not possible, how to initialize only this polymer element.

+4
source share
1

Turbolinks 4. Turbolinks 5

Turbolinks replaceChild

https://github.com/rails/turbolinks/blob/master/lib/assets/javascripts/turbolinks.js.coffee#L97

document.documentElement.replaceChild(body, document.body);

" ", .

, .

$(document).on "page:change", ->
   document.documentElement.replaceChild(document.importNode(document.body, true), document.body);

$(document).on "page:change", ->
  for polymerElement in Polymer.elements
    for domElement in document.body.querySelectorAll(polymerElement.name)
      domElement.parentNode.replaceChild(document.importNode(domElement, true), domElement);

https://groups.google.com/forum/#!msg/polymer-dev/WaWbepYW97Q/XE3SQTyvyCUJ

, , , , , , . , , ...

+2

All Articles