Module: Browser::NativeCachedWrapper
- Included in:
- Blob, CSS::Declaration, CSS::Rule, CSS::StyleSheet, Console, Crypto, DOM::Attribute, DOM::MutationObserver::Record, DOM::Node, Event::DataTransfer, Event::DataTransfer::Item, FormData, History, Location, Navigator, Browser::Navigator::MimeType, Browser::Navigator::Position, Screen, Window
- Defined in:
- opal/browser/utils.rb
Overview
NativeCachedWrapper is a special case of Native::Wrapper.
What this module does is it makes sure that your Ruby objects
are mapped 1:1 to your Javascript objects. So that for instance
your $document.at_css('body')
is always the same Ruby object.
You can only use it if your final .new
is of the signature
.new(native)
and your native (probably DOM) object persists and
doesn't mind arbitrary properties.
The rule of thumb is: if it does overload #initialize
's signature
and not .new
's - it won't work. Use Native::Wrapper in this case.
Instance Method Summary collapse
- #restricted? ⇒ Boolean
-
#set_native_reference(native) ⇒ Object
Change a native reference and make sure the change is reflected on JS side as well.
Instance Method Details
#restricted? ⇒ Boolean
26 27 28 |
# File 'opal/browser/utils.rb', line 26 def restricted? !!@restricted end |
#set_native_reference(native) ⇒ Object
Change a native reference and make sure the change is reflected on JS side as well. This method is used by Node#initialize_copy. Please don't use this method outside of the cloning semantic.
33 34 35 36 |
# File 'opal/browser/utils.rb', line 33 def set_native_reference(native) `#{native}.$$opal_native_cached = #{self}` @native = native end |