Module: Vis::DataCommon
Instance Method Summary collapse
- #[](id) ⇒ Object
- #get(*args) ⇒ Object
- #get_ids(options) ⇒ Object
-
#off(event, event_handler_id) ⇒ Object
events.
- #on(event, &block) ⇒ Object
-
#options_to_native(options) ⇒ Object
options.
Instance Method Details
#[](id) ⇒ Object
3 4 5 |
# File 'lib/vis/data_common.rb', line 3 def [](id) get(id) end |
#get(*args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vis/data_common.rb', line 7 def get(*args) if `Opal.is_a(args.$last(), Opal.Hash)` args.push((args.pop)) end res = `self["native"].get.apply(self["native"], Opal.to_a(args))` if `res !== null && Opal.is_a(res, Opal.Array)` native_to_hash_array(res) else `res !== null ? Opal.Hash.$new(res) : #{nil}` end end |
#get_ids(options) ⇒ Object
19 20 21 |
# File 'lib/vis/data_common.rb', line 19 def get_ids() @native.JS.getIds(()) end |
#off(event, event_handler_id) ⇒ Object
events
25 26 27 28 29 30 |
# File 'lib/vis/data_common.rb', line 25 def off(event, event_handler_id) event = lower_camelize(event) handler = @event_handlers[event][event_handler_id] `self["native"].off(event, handler)` @event_handlers[event].delete(event_handler_id) end |
#on(event, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vis/data_common.rb', line 32 def on(event, &block) event = lower_camelize(event) @event_handlers[event] = {} unless @event_handlers[event] event_handler_id = `Math.random().toString(36).substring(6)` handler = %x{ function(event, properties, sender_id) { return block.$call(Opal.Hash.$new(event),Opal.Hash.$new(properties), sender_id); } } @event_handlers[event][event_handler_id] = handler `self["native"].on(event, handler);` event_handler_id end |
#options_to_native(options) ⇒ Object
options
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vis/data_common.rb', line 48 def () return unless new_opts = {}.merge!() if new_opts.has_key?(:filter) block = new_opts[:filter] if `typeof block === "function"` unless new_opts[:filter].JS[:hyper_wrapped] new_opts[:filter] = %x{ function(item) { return #{block.call(`Opal.Hash.$new(item)`)}; } } new_opts[:filter].JS[:hyper_wrapped] = true end end end lower_camelize_hash(new_opts).to_n end |