LivelySourceLivelyResolver

class Resolver

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.

Definitions

def initialize(state = nil)

Initialize a new resolver with shared state.

Signature

parameter state Hash

Key-value pairs to pass to view constructors as keyword arguments.

Implementation

def initialize(state = nil)
	super()
	@state = state
end

attr :state

Signature

attribute Hash

The shared state passed to view constructors.

def call(id, data)

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

Signature

parameter id String

The unique element identifier.

parameter data Hash

The element data attributes.

returns Live::Element | Nil

The resolved element, or nil.

Implementation

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