Class: Matestack::Ui::VueJs::Components::Async

Inherits:
Vue
  • Object
show all
Defined in:
lib/matestack/ui/vue_js/components/async.rb

Instance Method Summary collapse

Methods inherited from Vue

#base_vue_props, #component_attributes, #component_id, #component_uid, inherited, #matestack_ui_vuejs_ref, #vue_component, vue_name, #vue_name

Constructor Details

#initialize(html_tag = nil, text = nil, options = {}, &block) ⇒ Async

register itself as an async component in the context



12
13
14
15
16
# File 'lib/matestack/ui/vue_js/components/async.rb', line 12

def initialize(html_tag = nil, text = nil, options = {}, &block)
  super(html_tag, text, options, &block)
  Matestack::Ui::Core::Context.async_components = {} if Matestack::Ui::Core::Context.async_components.nil?
  Matestack::Ui::Core::Context.async_components[self.ctx.id] = self
end

Instance Method Details

#async_attributesObject



49
50
51
52
53
54
55
# File 'lib/matestack/ui/vue_js/components/async.rb', line 49

def async_attributes
  options.merge({
    id: ctx.id,
    class: 'matestack-async-component-root',
    'v-if': 'vc.showing'
  })
end

#create_children(&block) ⇒ Object



18
19
20
# File 'lib/matestack/ui/vue_js/components/async.rb', line 18

def create_children(&block)
  self.response &block
end

#is_deferred?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/matestack/ui/vue_js/components/async.rb', line 68

def is_deferred?
  ctx.defer
end

#is_not_requested?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/matestack/ui/vue_js/components/async.rb', line 72

def is_not_requested?
  params[:component_key].present? && params[:component_key] != ctx.id
end

#isolated_parentObject



76
77
78
# File 'lib/matestack/ui/vue_js/components/async.rb', line 76

def isolated_parent
  Matestack::Ui::Core::Context.isolated_parent
end

#responseObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/matestack/ui/vue_js/components/async.rb', line 22

def response
  if params[:component_key] && !is_not_requested?
    div async_attributes do
      yield
    end
  else
    vue_component do
      div class: 'matestack-async-component-container', 'v-bind:class': '{ "loading": vc.loading === true }' do
        div class: 'matestack-async-component-wrapper', 'v-if': 'vc.asyncTemplate == null', 'v-bind:class': '{ "loading": vc.loading === true }' do
          div async_attributes do
            if params[:component_key]
              # we need to yield if a request is looking for a async component, indicated through present params[:component_key]
              # the requested component could be hidden within this deferred async!
              yield
            else
              yield unless is_deferred?
            end
          end
        end
        div class: 'matestack-async-component-wrapper', 'v-if': 'vc.asyncTemplate != null', 'v-bind:class': '{ "loading": vc.loading === true }' do
          Matestack::Ui::Core::Base.new('matestack-ui-core-runtime-render', ':template': 'vc.asyncTemplate', ':vc': 'vc')
        end
      end
    end
  end
end

#vue_propsObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/matestack/ui/vue_js/components/async.rb', line 57

def vue_props
  {
    component_key: ctx.id,
    show_on: ctx.show_on,
    hide_on: ctx.hide_on,
    rerender_on: ctx.rerender_on,
    defer: ctx.defer,
    parent_class: isolated_parent ? isolated_parent.class.to_s : nil,
  }
end