presenter

Using rails presenters - memoizable getting deprecated in 3.1 - use ||= instead?

烈酒焚心 提交于 2019-12-03 14:34:35
Issue: To avoid creating multiple objects or multiple queries when possible. I am using Presenters with rails as a Best Practice. I am following advice that says that it would be good to use "extend ActiveSupport.Memoizable" (and then memoize :method(s) to use them) over setting up items with @the_record = record ||= @record style because of a couple of issues - false or nil not getting stored so the query gets called again and also that memoizable uses the cache better (i.e. uses it!). However I see that memoizable is getting deprecated in rails 3.1 Notes i github under carrierwave and with

How to pass argument to delegate method in Rails

倾然丶 夕夏残阳落幕 提交于 2019-11-29 06:00:58
I would like to have a Dashboard to display summary of multiple models, and I implemented it using Presenter without its own data. I use an ActiveModel class (without data table): class Dashboard attr_accessor :user_id def initialize(id) self.user_id = id end delegate :username, :password, :to => :user delegate :address, :to => :account delegate :friends, :to => :friendship end By delegate, I want to be able to call Dashboard.address and get back Account.find_by_user_id(Dashboard.user_id).address . If Dashboard was an ActiveRecord class, then I could have declared Dashboard#belongs_to :account

Show Dialog from ViewModel in Android MVVM Architecture

强颜欢笑 提交于 2019-11-28 18:45:18
About MVVM with new architecture components, I've a question, how should I implement if my app needs to display for example a Dialog with 3 options from some action that happened in my VM? Who is responsible for sending to Activity/Fragment the command to show dialog? UI-related actions like opening new activities or showing dialogs are triggered from the view (an activity or fragment), not from a ViewModel. The ViewModel doesn't have a reference to the view to prevent leaks and keep the presentation layer "reactive". You could subscribe your view (activity or fragment) to an observable in the

Ruby on Rails patterns - decorator vs presenter

ε祈祈猫儿з 提交于 2019-11-28 15:17:06
There is all sorts of talk lately in the Ruby on Rails community about decorators and presenters. What is the essential difference between the two? If there is, what are the clues that tell me which one to use over the other? Or perhaps to use the two in conjunction? A decorator is more of a "let's add some functionality to this entity". A presenter is more of a "let's build a bridge between the model/backend and view". The presenter pattern has several interpretations. Decorators are generic/general purpose. Presenters have a narrower range of responsibilities/uses. Decorators are used across

How to pass argument to delegate method in Rails

拜拜、爱过 提交于 2019-11-27 23:32:16
问题 I would like to have a Dashboard to display summary of multiple models, and I implemented it using Presenter without its own data. I use an ActiveModel class (without data table): class Dashboard attr_accessor :user_id def initialize(id) self.user_id = id end delegate :username, :password, :to => :user delegate :address, :to => :account delegate :friends, :to => :friendship end By delegate, I want to be able to call Dashboard.address and get back Account.find_by_user_id(Dashboard.user_id)

Show Dialog from ViewModel in Android MVVM Architecture

倖福魔咒の 提交于 2019-11-27 11:48:21
问题 About MVVM with new architecture components, I've a question, how should I implement if my app needs to display for example a Dialog with 3 options from some action that happened in my VM? Who is responsible for sending to Activity/Fragment the command to show dialog? 回答1: UI-related actions like opening new activities or showing dialogs are triggered from the view (an activity or fragment), not from a ViewModel. The ViewModel doesn't have a reference to the view to prevent leaks and keep the