module Opal::StateMachine

Constants

VERSION

Public Class Methods

extend_react_component(where, klass = nil) click to toggle source

1 we are required first, we are included first

2 we are required first, we are included second

3 we are required second, we are included first 4 we are required second, we are included second 5 we are required, but they are not

# File lib/opal/aasm.rb, line 20
def self.extend_react_component(where, klass = nil)
  return if klass and klass.respond_to? :aasm_event_fired # case 4 already handled when we were required.
  if klass and klass.respond_to? :define_state
    # case 2
    klass.define_state :protected_current_react_state_var
    klass.define_method :aasm_event_fired do |event, from, to|
      protected_current_react_state_var! to.to_s if from != to
    end
  elsif defined? React::Component
    # case 3 + 4 (second call from include will be ignored)
    # case 1 (first call from require will be ignored)
    React::Component.module_eval do
      # alias_method does not work on :included so we do it the hard way
      unless @original_included_method_for_state_machine
        @original_included_method_for_state_machine = self.method(:included) 
        def self.included(base)
          @original_included_method_for_state_machine.call(base)
          base.define_state :protected_current_react_state_var
          base.define_method :aasm_event_fired do |event, from, to|
            protected_current_react_state_var! to.to_s if from != to
          end
        end
      end 
    end
  end
end
included(base) click to toggle source
# File lib/opal/aasm.rb, line 35
def self.included(base)
  @original_included_method_for_state_machine.call(base)
  base.define_state :protected_current_react_state_var
  base.define_method :aasm_event_fired do |event, from, to|
    protected_current_react_state_var! to.to_s if from != to
  end
end

Public Instance Methods

current_state() click to toggle source
# File lib/opal/aasm.rb, line 47
def current_state
  protected_current_react_state_var if respond_to? :render
  aasm.current_state.to_s
end