Hi! I'm wondering why all stores must be included in one class / global namespace. In general, this is not good idea, but maybe I still didn't get the idea of flux architecture?
Wouldn't be something like this a better approach?
class Store
include Inesita::Store
def method_missing(m, *args, &block) # just for illustration of the idea
"#{m}_store".camelize.constantize.instance do
render!
end
end
def respond_to_missing?(m, include_private = false)
true
end
end
# all stores are singletones
class ApplicationStore
class << self
def instance(&block)
@render_block = block
@instance ||= new
end
private :new
def render_block
@render_block
end
end
def render!
self.class.render_block.call
end
end
class MediaItemsStore < ApplicationStore
def save_some_stuff
render!
end
end
# use it inside components
store.media_items.save_some_stuff
Now each store has its own namespace in store object, no need to include and initialize each store plus they are lazy-initialized
Hi! I'm wondering why all stores must be included in one class / global namespace. In general, this is not good idea, but maybe I still didn't get the idea of flux architecture?
Wouldn't be something like this a better approach?
Now each store has its own namespace in
store
object, no need to include and initialize each store plus they are lazy-initialized