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)


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