Comments (2)
Sorry if this is a bit in the weeds, but I just like to have a thorough grasp of patterns and their why's and why-not's.
To provide a current example:
I have a view controller that displays a post. That view controller has a view model. One of the cells displays hash tags associated with that post. The hash tags are tappable, and ultimately should cause a new view controller to be pushed onto the stack with data about that hashtag.
So I have a custom cell, with the ability to return hot words tapped in a label. Somehow I need to surface this action of tapping a hashtag, and the respective hashtag name, up to the primary view model so that it can create a view model for that hashtag detail page and supply it to the view controller.
I've went through several incarnations of this:
- The cell having it's parent view controller's view model. This is easy as I can just call a method on that view model, but it's coupling things together that need not know of each other. Less reusable.
- The cell has no view model, and I propagate events to the view controller either via the responder chain, or signals exposed on the cell. (The one nice thing about the responder chain in this instance is not setting up new bindings every time a cell with signals was re-used, though you would have to look at the cell's .m code to determine what selectors to respond to). Instead of actually implementing the selector, I used signalForSelector.
- The cell has it's own view model, created from the parent view model and assigned in the view controller when preparing the cell. In this case the cell propagates events to it's view model via commands. The parent view model can then observe the signals on those commands and take the appropriate action. This has the downside of creating another file for a simple cell, and I'm not sure it makes sense for a view model to be more or less propagating/broadcasting ui events like that which it doesn't really care about.
from reactiveviewmodel.
I think both (2) and (3) are legitimate ways of solving the problem. If the cell is simple enough that it doesn't need its own view model, (2) seems perfectly fine.
from reactiveviewmodel.
Related Issues (20)
- didBecomeInactiveSignal should skip:1 HOT 2
- What about ViewModel based routing? HOT 1
- didBecomeInactiveSignal send value before viewDidLoad,is this right? HOT 1
- Feedback on MVVM-ification of an app HOT 3
- Why forwardSignalWhileActive:(RACSignal *)signal subscribes only on the next and error, but not completed? HOT 3
- Add Carthage compatibility badge to the README
- How to build it and use it? HOT 6
- forwardSignalWhileActive as signal operator HOT 1
- retain cycle when using didBecomeActiveSignal HOT 5
- Error Handling in ViewModel HOT 2
- code inside [self.didBecomeActiveSignal subscribeNext:^(id x) {}] not called. HOT 2
- I'd like to know how to setup a ReactiveViewModel with multiple Models? HOT 1
- Using forwardSignalWhileActive to fix KVO performance on iOS 9.
- run error HOT 1
- Old version in cocoapods HOT 5
- 你好 更新框架文件为啥老是报错了? HOT 3
- GitHub API request failed: NetworkError(Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
- new plan to use Swift rewrite this demo HOT 1
- can`t pod install 0.3.3
- compile errors using @keypath syntax
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactiveviewmodel.