Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about handling an action in both components and controllers #86

Closed
cfcommando opened this issue Apr 9, 2015 · 4 comments
Closed

Comments

@cfcommando
Copy link

I want some buttons to toggle their images when tapped, and I've implemented that by updating the component's state. However, I also want to send an action upstream to a Controller which will handle the server work.

Concretely:

|LinkComponentController    <– does the heavy lifting
|LinkComponent
\___LinkVoteComponent      <– updates its own UI, holds the voting state
\___Link*Component         <– etc - other components which also get the LinkComponentController to do stuff

(where a Link is basically analogous to a Story in Facebook terms)

If I implement a LinkVoteComponentController, is it kosher for that to call [self.component updateState:...]*? Do I call CKComponentActionSend from the Component? Or am I barking up the wrong responder tree?

* currently, I just implement actions in the LinkVoteComponent directly, and update the state, with no server-side code implemented. Trying to find a way to avoid having to bake that into the Component.

Basically, the question boils down to, in Facebook terms: How do I structure a Story-like component to handle an action similar to liking a Story?

@cfcommando
Copy link
Author

Hmm, actually, I discovered that the reason I thought CKComponentActionSend was not a viable solution was because I called it immediately after updateState, not realizing that updateState was synchronously unmounting the view, causing the crash due to an assert on account of nextResponder==nil. It might be worth calling out in the docs (http://componentkit.org/docs/state.html) that updating the state can cause a synchronous unmount and therefore action sends should occur before state updates in this situation.

Sorry for the noise.

@adamjernst
Copy link
Contributor

This is really a bug with updateState that we plan to address shortly. It shouldn't synchronously unmount; instead that should be deferred to the end of the run loop. Sorry about that.

@cfcommando
Copy link
Author

Thanks!

Would it be appropriate for me to file an issue so that I can track the progress of that?

@adamjernst
Copy link
Contributor

Sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants