Class: Lively::Resolver

Inherits:
Live::Resolver
  • Object
show all
Defined in:
lib/lively/resolver.rb

Overview

Extends Live::Resolver to pass shared application state to views on construction.

When the browser reconnects via WebSocket, the resolver creates new view instances with the shared state (e.g. a controller) so all clients stay in sync.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state = {}) ⇒ Resolver

Initialize a new resolver with shared state.



16
17
18
19
# File 'lib/lively/resolver.rb', line 16

def initialize(state = {})
	super()
	@state = state
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



22
23
24
# File 'lib/lively/resolver.rb', line 22

def state
  @state
end

Instance Method Details

#call(id, data) ⇒ Object

Resolve a client-side element to a server-side instance with shared state.



28
29
30
31
32
# File 'lib/lively/resolver.rb', line 28

def call(id, data)
	if klass = @allowed[data[:class]]
		return klass.new(id, data, **@state)
	end
end

#The shared state passed to view constructors.=(sharedstatepassedtoviewconstructors. = (value)) ⇒ Object



22
# File 'lib/lively/resolver.rb', line 22

attr :state