Class: Params
Overview
All url related data is stored in params. This includes the main uri in addition to any query parameters. The router is responsible for converting any uri sections into params. Sections in the uri will override any specified parameters.
The params value can be updated the same way a model would be, only the updates will trigger an updated url via the browser history api. TODO: Support # for browsers without the history api.
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
- #deep_clone ⇒ Object
- #delete(*args) ⇒ Object
-
#initialize(*args) ⇒ Params
constructor
A new instance of Params.
- #method_missing(method_name, *args, &block) ⇒ Object
- #new_model(*args) ⇒ Object
- #run_update ⇒ Object
- #value_updated ⇒ Object
Methods inherited from Model
#!, #<<, #==, #assign_attribute, #expand!, #false?, #inspect, #nil?, #read_attribute, #return_undefined_method, #trigger_by_attribute!, #true?
Methods included from ObjectTracking
Methods included from ModelWrapper
Methods included from ReactiveTags
included, #reactive_method_tag
Constructor Details
#initialize(*args) ⇒ Params
Returns a new instance of Params.
11 12 13 |
# File 'lib/volt/models/params.rb', line 11 def initialize(*args) super(*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/volt/models/params.rb', line 32 def method_missing(method_name, *args, &block) result = super if method_name[0] == '_' && method_name[-1] == '=' # Trigger value updated after an assignment self.value_updated end return result end |
Instance Method Details
#deep_clone ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/volt/models/params.rb', line 15 def deep_clone new_obj = clone new_obj.attributes = new_obj.attributes.dup new_obj end |
#delete(*args) ⇒ Object
26 27 28 29 30 |
# File 'lib/volt/models/params.rb', line 26 def delete(*args) super value_updated end |
#new_model(*args) ⇒ Object
64 65 66 |
# File 'lib/volt/models/params.rb', line 64 def new_model(*args) Params.new(*args) end |
#run_update ⇒ Object
60 61 62 |
# File 'lib/volt/models/params.rb', line 60 def run_update $page.params.trigger!('child_changed') if Volt.client? end |
#value_updated ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/volt/models/params.rb', line 43 def value_updated # Once the initial url has been parsed and set into the attributes, # start triggering updates on change events. # TODO: This is a temp solution, we need to make it so value_updated # is called after the reactive_value has been updated. if RUBY_PLATFORM == 'opal' %x{ if (window.setTimeout && this.$run_update.bind) { if (window.paramsUpdateTimer) { clearTimeout(window.paramsUpdateTimer); } window.paramsUpdateTimer = setTimeout(this.$run_update.bind(this), 0); } } end end |