Replies: 5 comments 12 replies
-
@mweststrate @FredyC Have any thoughts? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I never needed it, as in all my use cases observable.ref sufficed. Not
entirely unsympathetic to the idea, but wondering if it shouldn't be more
of a global config then, doing it per declaration might be error prone as
it is easy to forget, and also requires mobx to carry context around about
the decorator that was used. Curious about real life use cases indeed if
.ref / .shallow didn't suffice?
…On Wed, Feb 17, 2021 at 8:54 AM ChenLei ***@***.***> wrote:
What's the scenario that you can't direct use observable.ref ? Can you
add a killer user case to proof your idea is meanful? Thanks
class DataStore {
@observable.ref moment;
@observable.ref reactDomNode;
constructor() {
makeObservable(this)
}}
// or
class DataStore {
reactDomNode;
moment;
constructor() {
makeObservable(this, {
moment: observable.ref,
reactDomNode: observable.ref
})
}}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2809 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBGKXBH75QI7Y5QYCJTS7N745ANCNFSM4XX32R3Q>
.
|
Beta Was this translation helpful? Give feedback.
10 replies
-
I think this idea only work on in initialization stage. const data = createMyFancyObservable(rawData);
// not
const data = createMyFancyObservable({});
data = rawData; Rerun the script function createMyFancyObservable(value) {
if (!value || typeof value !== "object") return value; // primitive
if (isValidElement(value)) return value; // no conversion
if (Array.isArray(value))
return observable.array(value.map(createMyFancyObservable), {
deep: false
});
const target = Object.fromEntries(
Object.entries(value).map([key, value] => [
key,
createMyFancyObservable(value)
])
);
return observable.object(target, { deep: false }); 👈🏻 // <- still covert object property to observable
}
createMyFancyObservable({
bb: {
cc: {
dd: <div>Hello world</div>
}
}
}) but not work, cause appendfrom const data = createMyFancyObservable({});
data = createMyFancyObservable(rawData); // reassign |
Beta Was this translation helpful? Give feedback.
1 reply
-
Pass new values through the same func before you assign them to the tree
…On Thu, 18 Feb 2021, 08:21 Janry, ***@***.***> wrote:
I hope it not only supports initial creation, but also supports dynamic
creation of observable objects. 😅
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2809 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBE2252KESUZCSIAKWLS7TEX5ANCNFSM4XX32R3Q>
.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
The recursion is exactly the same regardless whether MobX does it or you do
it yourself. But you only need to apply it to new values you are about to
store. Not to everything every time.
…On Thu, Feb 18, 2021 at 8:30 AM Janry ***@***.***> wrote:
So I have to do a deep recursion on all the data every time, the
performance will become very bad.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2809 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBB7NQWWL7ZQOH6UOLLS7TF2JANCNFSM4XX32R3Q>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For some special types(such as ReactNode,Moment,Immutable Object etc.) in deep observable, I hope the typer checker can be customized.
here is the source code location
https://github.com/mobxjs/mobx/blob/main/packages/mobx/src/api/observable.ts#L125
Usage can be like this.
Beta Was this translation helpful? Give feedback.
All reactions