Skip to content

Commit

Permalink
feat(uiSrefStatus): Emit all enclosed uiSref targetStates in the stat…
Browse files Browse the repository at this point in the history
…us object

Closes #142
  • Loading branch information
christopherthielen committed Sep 19, 2017
1 parent bd67d25 commit 0687e19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/directives/uiSrefStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export interface SrefStatus {
entering: boolean;
/** A transition is exiting the sref's target state */
exiting: boolean;
/** The sref's target state identifier */
identifier: StateOrName;
/** The enclosed sref(s) target state(s) */
targetStates: TargetState[];
}

/** @internalapi */
Expand All @@ -42,7 +42,7 @@ const inactiveStatus: SrefStatus = {
exact: false,
entering: false,
exiting: false,
identifier: null,
targetStates: [],
};

/**
Expand Down Expand Up @@ -120,18 +120,18 @@ function getSrefStatus(event: TransEvt, srefTarget: TargetState): SrefStatus {
exact: isExact(),
entering: isStartEvent ? isEntering() : false,
exiting: isStartEvent ? isExiting() : false,
identifier: srefTarget.identifier(),
targetStates: [srefTarget],
} as SrefStatus;
}

/** @internalapi */
function mergeSrefStatus(left: SrefStatus, right: SrefStatus) {
function mergeSrefStatus(left: SrefStatus, right: SrefStatus): SrefStatus {
return {
active: left.active || right.active,
exact: left.exact || right.exact,
entering: left.entering || right.entering,
exiting: left.exiting || right.exiting,
identifier: left.identifier || right.identifier,
targetStates: left.targetStates.concat(right.targetStates),
};
}

Expand Down
9 changes: 5 additions & 4 deletions test/uiSrefStatus/uiSrefStatus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ describe('uiSrefStatus', () => {
de.triggerEventHandler('click', {});
}));

it('should emit a event with identifier equals to `foo`', () => {
expect(component.updated).toHaveBeenCalledWith(jasmine.objectContaining({
identifier: 'foo',
}));
it('should emit a event with a TargetState pointing to `foo`', () => {
expect(component.updated).toHaveBeenCalled();
const arg: SrefStatus = (component.updated as jasmine.Spy).calls.mostRecent().args[0];
expect(arg.targetStates.length).toEqual(1);
expect(arg.targetStates[0].state()).toEqual(jasmine.objectContaining({ name: 'foo' }));
});
});
});

0 comments on commit 0687e19

Please sign in to comment.