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

[1.0.1] Doesn't wait for helper recomputation #469

Closed
boris-petrov opened this issue Nov 8, 2018 · 8 comments
Closed

[1.0.1] Doesn't wait for helper recomputation #469

boris-petrov opened this issue Nov 8, 2018 · 8 comments

Comments

@boris-petrov
Copy link

I have a helper in which I have something like:

  public compute(): string {
    console.log('compute');
    return 'some text';
  }

  @observes('someService.foo')
  private onFoo(): void {
    console.log('recompute');
    this.recompute();
  }

And in the test I do:

import { settled } from '@ember/test-helpers'
import wait from 'ember-test-helpers/wait'

...

    console.log 'setting 1'
    @owner.lookup('service:someService').set('foo', 'bar')
    console.log 'setting 2'

    await wait()
    await settled()
    console.log 'setting 3'

    assert.dom().hasText('some text')

When on 1.0.0 this test passes even without the await settled() line. 1.0.1 causes it to fail even with all of the above code. The output on 1.0.1 is:

setting 1
recompute
setting 2
setting 3

I'm kind of confused about all this waiting stuff but looking at recompute's implementation I don't see anything concerning runloops so I'm not sure why it ever worked... and what I should do to make it pass on 1.0.1?

@rwjblue
Copy link
Member

rwjblue commented Nov 8, 2018

Can you provide a reproduction repo? That would help me step through the code, and figure out whats going on...

@boris-petrov
Copy link
Author

Here you go

The second commit adds a test and sets test-helpers to version 1.0.0. The test passes. Checking out the third/last commit (which only updates test-helpers to 1.0.1) causes the test to fail.

@rwjblue
Copy link
Member

rwjblue commented Nov 8, 2018

Sounds basically like the issue in emberjs/ember.js#14774.

@boris-petrov
Copy link
Author

Yes, you are right, that fixes the issue. I wouldn't have thought about that, sorry. You're free to close the issue if you feel so.

@boris-petrov
Copy link
Author

OK, so putting a run around recompute fixed the FE test but it broke an integration test of ours. Debugging it yields very strange results... we have something like:

  @computed('someService.foo')
  public get a(): string {
    return this.someService.foo.split('-')[0];
  }

  @computed('someService.foo')
  public get b(): string {
    return this.someService.foo.split('-')[1];
  }

  public method(): void {
    console.log(this.a, this.b);
  }

And in some other place:

    this.someService.set('foo', 'z-x');
    something.method();

The console.log in method only causes recomputation of one of a and b and not the other... the helper from the original post does call these methods but that actually breaks in a different place - i.e. it breaks other code. If I remove the run in the helper, this code starts working fine again. If I change the run to a next - it again works... no idea what's going on...

@rwjblue
Copy link
Member

rwjblue commented Nov 9, 2018

Just to be clear, it should be run.join(this, this.recompute), that is what you are testing?

@boris-petrov
Copy link
Author

Ah, no, I was using run(() => this.recompute())... your solution works in both cases. These things are really confusing... :D Thank you!

@boris-petrov
Copy link
Author

This issue is fixed as of Ember 3.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants