-
-
Notifications
You must be signed in to change notification settings - Fork 91
[Experimental][WIP] Refactor api #306
Conversation
... although a simpler migration would probably be to still expose
|
Imo if we keep |
06a130e
to
5f83857
Compare
I think the hook has a few benefits over the useState hook: move people away from using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still not convinced about removing useObserver
. For fun, I tried searching that name over the GitHub, and 5000 results is not exactly a small number. And that's not considering private repos, etc... We might break a lot of codebases here without a clean way out of such breakage.
I even looked at some of my old codebases I no longer maintain and that hook is used fairly heavily too. It will be a real pain to refactor that.
Is it really worth just to "protect" people who don't know what they are doing?
Doh, intended to rewrap |
Please consider again deprecating |
5K isn't really a big number, e.g. in comparison "observer mobx" gives 300K results. For old project it is no problem, as they use old versions of deps as well, and even with a new version it is just a single deprecated message that will only show up in DEV. I think if people use an unrecommended, soon to be undocumented api, it is no more than fair to point to them it is deprecated and how to fix it. Note that moving to MobX 6 will already introduce much larger changes than replacing Let's deprecate first, and we can always see if the fallout is too big to revert that message. But for now the balance between the support load / confusing it generates versus the unique benefits it yields don't justify its existence to me. |
Ok, sounds fair enough. But let's definitely keep |
useLocalObservable sounds great!
…On Fri, Aug 28, 2020 at 2:38 PM Daniel K. ***@***.***> wrote:
Let's deprecate first, and we can always see if the fallout is too big to
revert that message. But for now the balance between the support load /
confusing it generates versus the unique benefits it yields don't justify
its existence to me.
Ok, sounds fair enough.
But let's definitely keep useLocalStore or even a different name
(useLocalObservable?). Just in case the useObserver stays so it doesn't
clutter with useObservable as it was in the past.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#306 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBC3HCFSAVPQXWEE5T3SC6XNJANCNFSM4QMKTCKA>
.
|
README.md
Outdated
|
||
The library does not include any Provider/inject utilities as they can be fully replaced with [React Context](https://mobx-react.js.org/recipes-context). Check out [the migration guide](https://mobx-react.js.org/recipes-migration). | ||
| mobx | mobx-react-lite | mobx-react<br/>(for class components) | Browser | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this is cool, but isn't it too confusing? I mean why to bother with mobx-react
in here? If people want to use mobx-react-lite
only they need to care about MobX version only, right? Some might get an impression from this table they also need to install mobx-react
of a specific version 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah your right, this should probably be somewhere else :)
README.md
Outdated
|
||
`useLocalObservable` is a short-hand for: | ||
|
||
`const state = useState(() => observable(initializer(), annotations, { autoBind: true }))[0]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That [0]
is hard to spot, people are more used to tuple syntax imo.
`const state = useState(() => observable(initializer(), annotations, { autoBind: true }))[0]` | |
`const [state] = useState(() => observable(initializer(), annotations, { autoBind: true }))` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
|
||
`const state = useState(() => observable(initializer(), annotations, { autoBind: true }))[0]` | ||
|
||
### **`useStaticRendering(enable: true)`** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should deprecate this name and find something that doesn't look like a hook :) Something like enableStaticRendering
or even enableSSR
.
|
||
--- | ||
|
||
## Deprecated APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I wouldn't keep this whole section here at all. Or do you actually want to keep these around in V3 and remove it in a future V4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah wanted to keep them around in v3, to not make migration too hard, and remove them in v4 only. Also nice to have the docs somewhere available in case people are looking at old code. So I think it is probably not too much in the way here.
Note that, at your own risk, it is also possible to not use `useEffect`, but do `state.unit = unit` instead in the rendering. | ||
This is closer to the old behavior, but React will warn correctly about this if this would affect the rendering of other components. | ||
|
||
## Observer batching (deprecated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a short explanation that this is done automatically now and they don't need to worry about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See next line :)
To be honest, I don't understand what is the point of class Counter {
value = 0;
constructor() {
makeAutoObservable(this);
}
increase = () => this.value++;
decrease = () => this.value--;
}
const Component = observer(() => {
const [counter] = useState(() => new Counter());
...
}) In this scenario, it is clear how to cover such store with unit tests. How to do it with |
This will work correctly with MobX 6 If you follow through comments here, we are going to rename |
Merging into mobx6 branch for a more holistic diff |
This reverts commit 916fd55.
Follow-up experiment based on discussion in the MobX 6 branch, removing a lot of api's to keep things OSS and undo some pollution preventing this to becoming a second mobx-react:
useAsObservableSource
, and all complexity that is introduced with it. Instead, but the props (or whatever) directly into the observable and2. use
useEffect
to update the observable after receiving new props3. or, to optimize away the possible double render, directly assign the observable update for render. This works fine for observables that are only used locally, but will, of course, trigger warnings when sending the observable to children, so 1) is recommended
useLocalStore
(the source)annotations
, renamed it touseLocalObservable
. But maybe we should keep it as is to simplify migration, I think that second arg is rarely used?forceUpdate
customisation option. Features should be useful for basically everyone or nobody, not a single libuseObserver
to encourage people to useObserver
/observer
. This might be a bit too aggressive and probably better to export it as_useObserver
or with a deprecation warningI think this is such a big change, that we should release it as separate major after releasing mobx 6 compatibility, so that people don't have to migrate immediately?