Sha256: 97e10c82fb593ae13acc859aae4fe1dc619753c7a556bf4f8e60bf7ee0df7f78

Contents?: true

Size: 991 Bytes

Versions: 1

Compression:

Stored size: 991 Bytes

Contents

module Hyperloop
  class Router
    module Mixin
      class << self
        def included(base)
          base.include(Hyperloop::Component::Mixin)
          base.include(HyperRouter::ComponentMethods)

          base.class_eval do
            param :match, default: nil
            param :location, default: nil
            param :history, default: nil

            define_method(:match) do
              params.match
            end

            define_method(:location) do
              params.location
            end

            define_method(:history) do
              params.history
            end

            before_mount do
              @_react_router_unlisten = history.listen do |location, action|
                React::State.set_state(HyperRouter, :location, location)
              end
            end

            before_unmount do
              @_react_router_unlisten.call if @_react_router_unlisten
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hyper-router-4.2.6.lap28 lib/hyperloop/router/mixin.rb