You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useStatedBean(Model) will find the model from the provider in the context, and will report an error if it does not exist. This feels unreasonable. It should be possible to temporarily create an instance of the Model whose lifecycle is consistent with the current component.
useStatedBean(Model, Scope?)
proposed scopes:
Default: if existed in Context then Request
Request: temporarily create an instance whose lifecycle is consistent with the current component.
Context: find from the provider in the context
The text was updated successfully, but these errors were encountered:
Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.58. Please mark this comment with 👍 or 👎 to give our bot feedback!
So I think we should still resolve Model via DI, but we need find a way to register Models dynamicly.
totally agree.
Currently, StatedBeanContainer caches the instance retrieved from the BeanFactory, and then useStatedBean got the cached object from the container in the context.
Now, how to create the container in useStatedBean when with the Request scope?
temporarily store the container with useState
interfaceUseStatedBeanOptions{dependentFields?: Array<string|symbol>;scope?: Scope}exportfunctionuseStatedBean<TextendsClassType>(type: T,options?: UseStatedBeanOptions,): InstanceType<T>{useState(()=>{letcontainerif(options.scope===Scope.Request){container=newStatedBeanContainer(...);}else{// get container from context}returncontainer;});
...
}
useStatedBean(Model)
will find the model from the provider in the context, and will report an error if it does not exist. This feels unreasonable. It should be possible to temporarily create an instance of theModel
whose lifecycle is consistent with the current component.useStatedBean(Model, Scope?)
proposed scopes:
Default
: if existed inContext
thenRequest
Request
: temporarily create an instance whose lifecycle is consistent with the current component.Context
: find from the provider in the contextThe text was updated successfully, but these errors were encountered: