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
The documentation at https://github.com/stimulus-use/stimulus-use/blob/main/docs/use-memo.md says that useMemo values are memoized on first use, but this is not the case for get properties, which is what the documentation describes. In the case of get properties, the properties are memoized immediately when useMemo is called, which can lead to unexpected results as you may not be expecting that initial before actual usage. The docs would indicate that you need to actually access the property at least once to memoize it, but that's not that the code says: https://github.com/stimulus-use/stimulus-use/blob/main/src/use-memo/use-memo.ts#L10
This is fetching the value immediately, rather than waiting for first use. This can lead to some unexpected results when you have code like this:
staticmemos=['memoizedProperty','memoizedMethod']connect(){useMemo(this)// this calls memoizedProperty(), but not memoizedMethod()this.memoizedPropety// second call, already called via useMemothis.memoizedMethod()// first call, is not memoized via useMemo}getmemoizedProperty(){return'property'}memoizedMethod(){return'method'}
The text was updated successfully, but these errors were encountered:
I'm not sure if we can also make useMemo work for getters, due to the nature how they work.
We might be able to print out a warning if we detect that you provided a getter in the static memos array and note the (unexpected) behavior in the docs.
@marcoroth if we can detect that we're using a getter, perhaps we can code around it? Like we could perhaps ignore the first call made to the getter and then start memoizing on any subsequent calls?
The documentation at https://github.com/stimulus-use/stimulus-use/blob/main/docs/use-memo.md says that
useMemo
values are memoized on first use, but this is not the case forget
properties, which is what the documentation describes. In the case ofget
properties, the properties are memoized immediately whenuseMemo
is called, which can lead to unexpected results as you may not be expecting that initial before actual usage. The docs would indicate that you need to actually access the property at least once to memoize it, but that's not that the code says: https://github.com/stimulus-use/stimulus-use/blob/main/src/use-memo/use-memo.ts#L10This is fetching the value immediately, rather than waiting for first use. This can lead to some unexpected results when you have code like this:
The text was updated successfully, but these errors were encountered: