This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
need way to dynamically mount components (i.e. after ajax calls) #252
Comments
already there:
maybe needs a better name |
actually, its built into react-rails, and works with the we can make it a bit nicer like this: #jquery-mounter.rb
require 'jquery'
require 'opal-jquery'
%x{
(function ( $ ) {
$.fn.mount_components = function() {
this.each(function(e) { ReactRailsUJS.mountComponents(e[0]) })
return this;
}
}( jQuery ));
}
Element.expose :mount_components Now we can add the components to the view using Typical in JS: // fetch.js.erb
$('#target_div').html("<%= escape_javascript(render partial: 'fetch') %>").mount_components();
// fetch.erb contains our html code including 1 or more component mount points In Ruby Element['body'].mount_components # mount everything! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
From opal you can call
Hyperloop.mount_all
or from js land itshyperloop_mount_all()
It will find all components with the data-hyperloop-mount data attribute, and the name of the component will be the attribute value. For example
will mount MyBigComponent at the DIV and pass it 'some data' as param1
The text was updated successfully, but these errors were encountered: