Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@cached() seems to cache across component instances #7

Closed
mydea opened this issue Aug 17, 2020 · 4 comments · Fixed by #9
Closed

@cached() seems to cache across component instances #7

mydea opened this issue Aug 17, 2020 · 4 comments · Fixed by #9
Labels
bug Something isn't working

Comments

@mydea
Copy link
Contributor

mydea commented Aug 17, 2020

Thanks for the work on this polyfill! I have been quite excited to try this out. However, it does not seem to work for me - the @cached value seems to be cached across all instances of a component.

A simple usage of this:

import Component from '@glimmer/component';
import Ember from 'ember';
const cached = Ember._cached;

export default class LineChart extends Component {
  @cached
  get groupedData() {
    let { data } = this.args;

   console.log('groupedData is called');

   // transform the given data, and return it
   return data.map(() => /* ... */);
  }
}

However, multiple instances of the component all seem to share the same cached value. E.g. groupedData is called is only printed to the console once, even though there are multiple instances of the component rendered. I can also see this in tests, where in following tests the value is never recomputed, even though there are completely new component instances.

Maybe I am also doing something wrong? Not sure! Also not sure if this is related to this addon or to some underlying functionality here.. Is it working for you?

For reference, I am on ember-source 3.20.4.

@buschtoens
Copy link
Contributor

Thanks for trying it out! Super glad that you have a use-case for it. 😍

Most likely you are doing everything right and I messed up. Admittedly I did not get to try this polyfill myself yet. 😅

I'll add a failing test case and fix. 👍

buschtoens added a commit that referenced this issue Aug 17, 2020
Failing test for #7.
buschtoens added a commit that referenced this issue Aug 17, 2020
@buschtoens buschtoens added the bug Something isn't working label Aug 17, 2020
@buschtoens
Copy link
Contributor

Fixed in v0.1.0-2. Thank you! 🚀

@DLiblik
Copy link

DLiblik commented Aug 18, 2020

I am still getting this issue in v0.1.0-3, but oddly, not for all properties. The difference seems to be whether the cached property depends on any other properties on the same component instance - if not (i.e. if all tracked properties are on external objects), then the cache seems to have a different 'this' than properties that do depend on other properties on the same component instance and... weirdness and alternate dimensions start to appear with tentacles reaching out of my monitor.... then John Dies at the End.

Not sure I can put this into a simple repro easily... but this is very cool... huge performance gains for a few critical use cases.

@DLiblik
Copy link

DLiblik commented Aug 18, 2020

Scratch that - I had an npm error I missed - was still running v..-0 - v..-3 does not have the problem.

Thanks for this polyfill - hugely useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants