Module: Browser::NativeCachedWrapper

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

Instance Method Details

#restricted?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'opal/browser/utils.rb', line 23

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.


30
31
32
33
# File 'opal/browser/utils.rb', line 30

def set_native_reference(native)
  `#{native}.$$opal_native_cached = #{self}`
  @native = native
end