Class: Isomorfeus::I18n::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/i18n/init.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#init_promiseObject

Returns the value of attribute init_promise.



6
7
8
# File 'lib/isomorfeus/i18n/init.rb', line 6

def init_promise
  @init_promise
end

Instance Method Details

#initObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/isomorfeus/i18n/init.rb', line 8

def init
  return if @initializing || initialized?
  @initializing = true
  @initialized = false
  if Isomorfeus.on_browser?
    root_element = `document.querySelector('div[data-iso-root]')`
    if root_element
      Isomorfeus.current_locale = root_element.JS.getAttribute('data-iso-nloc')
    else
      Isomorfeus.current_locale = Isomorfeus.default_locale
    end
  end
  self.init_promise = init_from_server
end

#init_from_serverObject



23
24
25
26
27
28
29
30
31
# File 'lib/isomorfeus/i18n/init.rb', line 23

def init_from_server
  Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.current_locale).then do |agent|
    agent.process do
      @initializing = false
      Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
      @initialized = true
    end
  end
end

#initialized?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/isomorfeus/i18n/init.rb', line 41

def initialized?
  @initialized
end

#reload_from_serverObject



33
34
35
36
37
38
39
# File 'lib/isomorfeus/i18n/init.rb', line 33

def reload_from_server
  Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.current_locale).then do |agent|
    agent.process do
      Isomorfeus.store.dispatch(type: 'I18N_STATE', set_state: agent.response[:data])
    end
  end
end