-
Notifications
You must be signed in to change notification settings - Fork 200
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
SSC: Support Passing In initialValue
During Instantiation
#936
Comments
any updated here? |
Not yet 👍 |
😭, What's the main problem here, I read some ssc code just now and think It's may not a tricky. I think the main problem is the type of run function, what about change like this: run :: (?state :: IORef state, ?context :: ControllerContext, ?applicationContext :: ApplicationContext, ?modelContext :: ModelContext, ?connection :: Websocket.Connection) => state -> IO () and change initState like this: initialState :: Maybe State -> State Help wanted! |
What about something as this:
Then you may have both static and dynamic configuration data for the components (as you are able to choose the
|
I like this idea. It's very close to how react.js works as well 👍 |
With |
yep that's correct. If you set |
You may also provide a |
Hi @fidel-ml, I had tested what you have suggested. But notice that the idea does not work quite as thought. @MurakamiKennzo is right, the problem is the run method where the initialState which is executed at ComponentsController initialization. At that point I don't have the props value yet. Somehow when I call IHP.ServerSideComponent.ViewFunctions componentWithProps the value I pass must be stored in the ControllerContext or somehow? But I have too little understanding of haskell that I probably can't solve this. Who can help? Here see you what I have: Edit: |
I think this might actually be a good option here. The ControllerContext cannot be used as we're having two requests here. The first that renders the SSC We've had a similiar problem with IHP AutoRefresh (keeping state across multiple requests). AutoRefresh solves this by having a server-global session store. On the first request it creates a new |
Hello Marc @mpscholten , I have played around a bit today. I now pass the props in the websocket URL on the first request and then set the state in the ComponentsController over it. My example runs with it. But I really only have rudimentary Haskell knowledge, so the code is probably really bad. I've somehow managed to get there with a lot of trial and error. Here is the branch with my changes. I also wrote a test counter component. but somehow I didn't manage to link to my feature branch in default.nix. I have included my feature branch for testing simply over an IHP subdirectory. Both projects compile. I have only strangely in Visual Code (Haskell plugin) with the language server problems. Get then e.g. Web.Component.Counter File the following error displayed:
do you know where the problem is? Edit: |
componentFromState @Counter (Counter { value = 100 })
should use the provided initial state instead of relying on theinitialValue
defined in the Counter component module.https://ihpframework.slack.com/archives/C01DQE0F4F8/p1624537056154200
The text was updated successfully, but these errors were encountered: