Class: Params

Inherits:
Model show all
Defined in:
lib/volt/models/params.rb

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

#attributes, #parent, #path

Instance Method Summary collapse

Methods inherited from Model

#!, #<<, #==, #assign_attribute, #expand!, #false?, #inspect, #nil?, #read_attribute, #return_undefined_method, #trigger_by_attribute!, #true?

Methods included from ObjectTracking

#__setup_tracking

Methods included from ModelWrapper

#wrap_value, #wrap_values

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_cloneObject



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_updateObject



60
61
62
# File 'lib/volt/models/params.rb', line 60

def run_update
  $page.params.trigger!('child_changed') if Volt.client?
end

#value_updatedObject



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