Closed
Description
for example:
class CurrentUser < HyperStore
receives LoginOperation do |user|
Hyperstack.connect(User.find_by_email(user.email))
end
will not work, because connect needs the actual id, which will be unknown (i.e. a dummy value) until the next fetch cycle completes.
So internally connect needs to make sure that id is loaded before connecting:
module Hyperstack
def self.connect(*channels)
channels.each do |channel|
if channel.is_a? Class
IncomingBroadcast.connect_to(channel.name)
elsif channel.is_a?(String) || channel.is_a?(Array)
IncomingBroadcast.connect_to(*channel)
elsif channel.id
Hyperstack::Model.load do
channel.id
end.then do |id|
IncomingBroadcast.connect_to(channel.class.name, id)
end
else
raise "cannot connect to model before it has been saved"
end
end
end
end