Skip to content

Commit

Permalink
fix: avoid resetting the step manager on any attribute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmit committed Mar 15, 2019
1 parent 513c9b7 commit 569991a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
23 changes: 16 additions & 7 deletions addon/components/step-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export default class StepManagerComponent extends Component {
*/
linear!: boolean;

/**
* @property {boolean} boolean
* @private
*/
_watchCurrentStep!: boolean;

/**
* @property {BaseStateMachine} transitions state machine for transitions
* @private
Expand All @@ -85,6 +91,7 @@ export default class StepManagerComponent extends Component {
'currentStep'
);

this._watchCurrentStep = isPresent(currentStep);
const startingStep = isNone(initialStep) ? currentStep : initialStep;

if (!isPresent(this.linear)) {
Expand Down Expand Up @@ -113,13 +120,15 @@ export default class StepManagerComponent extends Component {
}

didUpdateAttrs() {
const newStep = this.currentStep;

if (typeof newStep === 'undefined') {
const firstStep = get(this.transitions, 'firstStep');
this.transitionTo(firstStep);
} else {
this.transitionTo(newStep);
if (this._watchCurrentStep) {
const newStep = this.currentStep;

if (typeof newStep === 'undefined') {
const firstStep = get(this.transitions, 'firstStep');
this.transitionTo(firstStep);
} else {
this.transitionTo(newStep);
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions tests/integration/step-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ module('step-manager', function(hooks) {

assert.equal(this.get('step'), 'first');
});

test('does not reset back to first step on any attribute change', async function(assert) {
this.set('initialStep', 'second');
this.set('randomAttribute', 'initial value');

await render(hbs`
{{#step-manager randomAttribute=randomAttribute initialStep=initialStep as |w|}}
{{#w.step name='first'}}
<div data-test-first></div>
{{/w.step}}
{{#w.step name='second'}}
<div data-test-second></div>
{{/w.step}}
{{/step-manager}}
`);

assert.dom('[data-test-second]').exists();
assert.dom('[data-test-first]').doesNotExist();

this.set('initialStep', 'second');
this.set('randomAttribute', 'a new value');

assert.dom('[data-test-second]').exists();
assert.dom('[data-test-first]').doesNotExist();
});
});
});

Expand Down

0 comments on commit 569991a

Please sign in to comment.