Open rrousselGit opened 5 years ago
I like the @store
attribute with optional parameters to enable inference. Comments:
@computed
' seems to conflict with 'public immutable properties aren't @observable
'. Also IMO there is a case for observable readonly properties, see #220, although maybe this isn't an inference use case. Would inference be all-or-nothing or could you still use annotations to override inference rules?
Great idea @rrousselGit. Overall I like the direction. Few other things to consider:
@noAction
, @noComputed
, @noObservable
). Essentially a per-member toggle that can be used to opt out of the auto generation.@pavanpodila you often see ignore: true . so for computed it would be @computed(ignore: true)
Agreed with ignore: true, IMO this is preferable to doubling the number of annotations.
Ya like the ignore
approach.
It should be @Computed()
in that case.
Anyway I agree with ignore
. If peoples wants a shorthand to make it easier to use, they can do the following:
const noComputed = Computed(ignore: true);
@shyndman I was thinking we can pick this up as a good enhancement for simplifying the use of MobX for most users. The current @store
directive can get a nitro-boost with this auto-inference feature? What do you think ?
Yeah, I'm into it, along with the opt-out annotation.
Maybe we could generalize the opt-outs into a single annotation? Something like @ignore()?
I prefer the @ignore approach On 27 Dec 2019, 1:21 AM +0530, Scott Hyndman notifications@github.com, wrote:
Yeah, I'm into it, along with the opt-out annotations. Maybe we could generalize the opt-outs into a single annotation? Something like @ignore()? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
This proposal is for automatically inferring
@action/@computed/@observable
based on the type of the variable.The idea is, by letting the inference do its job, silly mistakes where we forgot to decorate a member can be stopped.
The inference would work using the following rules:
@computed
@obvervable
@observable
@action
This inference can be configured using two different ways:
@Store
decorator, for store specific overridebuild.yaml
file, for global configuration change:I've looked through the entire
mobx_examples
folder and all of the examples follows these rules.There are some exceptions, like in form_store.dart where
setupValidations
is not decorated. ButsetupValidations
should probably be performed inside the constructor ofFormStore
and thereforesetupValidations
can be made private.Another exception is in github_store.dart, where
repositories
is not@obvervable
. But that seems dangerous consideringrepositories
is mutated on multiple occasions and is used inside thebuild
method ofRepositoryListView
.