You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
More concisedom_node and ref handling for jquery #62
In order to get a reference to a component add the special ref keyword to a components param list. The value of the param must be a proc which will receive the dom node. For example:
DIV(ref: ->(node){puts"Hey my inner text is #{`#{node}.innerText`}) { "hohoho" }# puts `ho ho ho` to the console
Because often you want to save the node in an instance variable the Observable mixin provides the set method which will set the provided instance variable to the value of the dom node.
# @the_div will contain the dom node of the div once the `DIV` has been mounted.DIV(ref: set(:the_div)){"click me"}.on(:click){alert("I said #{`#{@the_div}.innerText`")}# alerts `click me`
If you are using jQuery you can access the jQuery API though the global jQ method:
DIV(ref: set(:the_div)){"click me"}.on(:click){alert("I said #{jQ[@the_div].text}")}
See opal-jquery for details on the the Opal jQuery wrapper, just note that Element is replaced by the jQ as Element conflicts with the React Element wrapper.
Finally if you are using jQuery you can replace the set method by set_jq which will set the instance variable to the dom node wrapped by jQuery.
DIV(ref: set_jq(:the_div)){"click me"}.on(:click){alert("I said #{@the_div.text")}
Activity
barriehadfield commentedon Nov 16, 2018
Seems odd that
self.domgives you a ref - why not:self.dom_refgives you a ref to selfself.jq_dom_refgives you a jQuery dom to selfie just be explicit?
catmando commentedon Nov 18, 2018
cause I hate typing
but perhaps these are obscure enough to warrant the extra typing?
catmando commentedon Nov 19, 2018
how about
dom_refandjq_reffor the keys, anddom_nodeandjq_nodefor the methods?barriehadfield commentedon Nov 19, 2018
That sounds great @catmando I will remember that :-)
step 1 in fixing #62
catmando commentedon Jan 16, 2019
so I went around and around on this.
In the end I am leaving
refworking the same as react'sref(i.e. it takes a callback which is sent the dom_node of the mounted component.then there is a the
setmethod which is part of theObservablemodule. This creates a lambda which sets an instance variable.Together you can then say:
ref: set(:foo)to set the@footo the ref.Meanwhile
DOMis now changed to the shorter, and easier to understandJQclass to wrap jQuery.So you could then say
JQ[@foo]to get the jquery wrapped node.You can also say
JQ[dom_node]to get your own dom_node wrapped by jQuery.Finally there is a
set_jqmethod which works like set but wraps the node in jQuery for you like this:ref: set_jq(:foo)Summary:
refwhich takes a callback argument.setwhich is part of theObservablemoduledom_nodeinstance methodset_jqis addedadds specs and closes #62
[-]dom_node for jquery[/-][+]More concise`dom_node` and `ref` handling for jquery[/+]updated change log. Improved #62
catmando commentedon Jan 17, 2019
Summary:
In order to get a reference to a component add the special
refkeyword to a components param list. The value of the param must be a proc which will receive the dom node. For example:Because often you want to save the node in an instance variable the
Observablemixin provides thesetmethod which will set the provided instance variable to the value of the dom node.If you are using jQuery you can access the jQuery API though the global
jQmethod:Finally if you are using jQuery you can replace the
setmethod byset_jqwhich will set the instance variable to the dom node wrapped by jQuery.step 1 in fixing hyperstack-org#62
adds specs and closes hyperstack-org#62
updated change log. Improved hyperstack-org#62
Fix hyperstack-org#62: an uncontrolled <textarea> must ignore later v…
Merge branch 'fix/issue-62-uncontrolled-textarea' into 'edge'